Help and Support

Artigo: 157234 - Última revisão: terça-feira, 21 de Novembro de 2006 - Revisão: 5.1

Como lidar com localizada e mudar o nome nomes de utilizadores e grupos

Nesta página

Expandir tudo | Reduzir tudo

Sumário

Este artigo mostra como obter localizada e cujo nome foi mudada conta nomes associadas às contas em computadores arbitrários.

A abordagem ilustrada abaixo é necessária devido à localização de utilizador do Windows NT e nomes de grupo e também para permitir a conta arbitrário mudar o nome por administradores de sistema. Esta abordagem funciona criando um SID valor de (identificador de segurança) que contém um valor de ID relativo Especifica o utilizador ou grupo de interesse. O SID resultante, em seguida, é procurado no computador do interesse e resulta numa cadeia de nome que é relevante no computador onde a pesquisa teve lugar. Isto é feito porque o mesmo valor de SID pode têm diferente texto associado em computadores diferentes, tal como foi mencionado acima.

Mais Informação

Exemplo de código

   /*++

   Copyright (c) 1996  Microsoft Corporation

   Module Name:

       acctname.c

   Abstract:

       This module illustrates how to obtain user and group names
       Associated with accounts that have been renamed or localized. This
       sample works by building a Sid value and then looking up the name
       associated with that Sid value.

       For example, in a default English install of Windows NT, the local
       administrators group is called "Administrators." In a default German
       install of Windows NT, the local administrators group is called
       "Administratoren." This can lead to problems when managing users
       and groups if the proper steps are not taken.

       The following relative ID values are an index into an account
       database that represents a specific user or group. In DOMAIN_USER_
       and DOMAIN_GROUP_ cases, the relative ID is appended to the account
       domain Sid from the machine of interest. In the DOMAIN_ALIAS_ case,
       the relative ID is appended to a well-known Sid representing the
       BUILTIN domain that is consistent across machines.

       // Well-known users and groups...

       #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
       #define DOMAIN_USER_RID_GUEST          (0x000001F5L)

       #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
       #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
       #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)

       // well-known aliases ...

       #define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
       #define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
       #define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
       #define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
       #define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
       #define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
       #define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
       #define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
       #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)

       The following section is for informational purposes and is useful
       for visualizing Sid values:

       // Universal well-known SIDs:
       // 
       //     Null SID                     S-1-0-0
       //     World                        S-1-1-0
       //     Local                        S-1-2-0
       //     Creator Owner ID             S-1-3-0
       //     Creator Group ID             S-1-3-1
       //     Creator Owner Server ID      S-1-3-2
       //     Creator Group Server ID      S-1-3-3
       // 
       //     (Non-unique IDs)             S-1-4

       #define SECURITY_NULL_SID_AUTHORITY       {0,0,0,0,0,0}
       #define SECURITY_WORLD_SID_AUTHORITY      {0,0,0,0,0,1}
       #define SECURITY_LOCAL_SID_AUTHORITY      {0,0,0,0,0,2}
       #define SECURITY_CREATOR_SID_AUTHORITY    {0,0,0,0,0,3}
       #define SECURITY_NON_UNIQUE_AUTHORITY     {0,0,0,0,0,4}

       #define SECURITY_NULL_RID                 (0x00000000L)
       #define SECURITY_WORLD_RID                (0x00000000L)
       #define SECURITY_LOCAL_RID                (0X00000000L)

       #define SECURITY_CREATOR_OWNER_RID        (0x00000000L)
       #define SECURITY_CREATOR_GROUP_RID        (0x00000001L)

       #define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L)
       #define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L)

       // NT well-known SIDs:
       // 
       //     NT Authority          S-1-5
       //     Dialup                S-1-5-1
       // 
       //     Network               S-1-5-2
       //     Batch                 S-1-5-3
       //     Interactive           S-1-5-4
       //     Service               S-1-5-6
       //     AnonymousLogon        S-1-5-7       (aka null logon session)
       //     Proxy                 S-1-5-8
       //     ServerLogon           S-1-5-8       (aka domain controller
       //                                            account)
       // 
       //     (Logon IDs)           S-1-5-5-X-Y
       // 
       //     (NT non-unique IDs)   S-1-5-0x15-...
       // 
       //     (Built-in domain)     S-1-5-0x20

       #define SECURITY_NT_AUTHORITY           {0,0,0,0,0,5}   // ntifs

       #define SECURITY_DIALUP_RID             (0x00000001L)
       #define SECURITY_NETWORK_RID            (0x00000002L)
       #define SECURITY_BATCH_RID              (0x00000003L)
       #define SECURITY_INTERACTIVE_RID        (0x00000004L)
       #define SECURITY_SERVICE_RID            (0x00000006L)
       #define SECURITY_ANONYMOUS_LOGON_RID    (0x00000007L)
       #define SECURITY_PROXY_RID              (0x00000008L)
       #define SECURITY_SERVER_LOGON_RID       (0x00000009L)

       #define SECURITY_LOGON_IDS_RID          (0x00000005L)
       #define SECURITY_LOGON_IDS_RID_COUNT    (3L)

       #define SECURITY_LOCAL_SYSTEM_RID       (0x00000012L)

       #define SECURITY_NT_NON_UNIQUE          (0x00000015L)

       #define SECURITY_BUILTIN_DOMAIN_RID     (0x00000020L)

       If no Command line arguments are specified, names are looked up
       on the local machine. If argv[1] is present, the lookup occurs
       on the specified machine.

       For example, acctname.exe \\winbase will look up names from the
       machine named \\winbase. If \\winbase is a default German install
       of Windows NT, names will appear in German locale.

   Author:

       Scott Field (sfield)    02-Oct-96

   --*/ 

   #define WIN32_LEAN_AND_MEAN
   #include <windows.h>
   #include <lm.h>

   BOOL
   LookupAliasFromRid(
       LPWSTR TargetComputer,
       DWORD Rid,
       LPWSTR Name,
       PDWORD cchName
       );

   BOOL
   LookupUserGroupFromRid(
       LPWSTR TargetComputer,
       DWORD Rid,
       LPWSTR Name,
       PDWORD cchName
       );

   #define RTN_OK 0
   #define RTN_USAGE 1
   #define RTN_ERROR 13

   int
   __cdecl
   wmain(
       int argc,
       wchar_t *argv[]
       )
   {
       LPWSTR TargetComputer;
       WCHAR Name[UNLEN+1];
       DWORD cchName = UNLEN+1;

       if(argc == 2)
           TargetComputer = argv[1];   // target specified machine
       else
           TargetComputer = NULL;      // target local machine

       if(!LookupUserGroupFromRid(
               TargetComputer,
               DOMAIN_USER_RID_ADMIN,
               Name,
               &cchName
               )) {

           printf("LookupUserFromRid error! (rc=%lu)\n", GetLastError());
           return RTN_ERROR;
       }

       printf("'Administrator' user name = %ls\n", Name);

       cchName = UNLEN; // reset buffer size

       if(!LookupAliasFromRid(
               TargetComputer,
               DOMAIN_ALIAS_RID_ADMINS,
               Name,
               &cchName
               )) {

           printf("LookupAliasFromRid error! (rc=%lu)\n", GetLastError());
           return RTN_ERROR;
       }

       printf("'Administrators' local group/alias name = %ls\n", Name);

       return RTN_OK;
   }

   BOOL
   LookupAliasFromRid(
       LPWSTR TargetComputer,
       DWORD Rid,
       LPWSTR Name,
       PDWORD cchName
       )
   {
       SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
       SID_NAME_USE snu;
       PSID pSid;
       WCHAR DomainName[DNLEN+1];
       DWORD cchDomainName = DNLEN+1;
       BOOL bSuccess = FALSE;

       // 
       // Sid is the same regardless of machine, since the well-known
       // BUILTIN domain is referenced.
       // 

       if(AllocateAndInitializeSid(
               &sia,
               2,
               SECURITY_BUILTIN_DOMAIN_RID,
               Rid,
               0, 0, 0, 0, 0, 0,
               &pSid
               )) {

           bSuccess = LookupAccountSidW(
                   TargetComputer,
                   pSid,
                   Name,
                   cchName,
                   DomainName,
                   &cchDomainName,
                   &snu
                   );

           FreeSid(pSid);
       }

       return bSuccess;
   }

   BOOL
   LookupUserGroupFromRid(
       LPWSTR TargetComputer,
       DWORD Rid,
       LPWSTR Name,
       PDWORD cchName
       )
   {
       PUSER_MODALS_INFO_2 umi2;
       NET_API_STATUS nas;

       UCHAR SubAuthorityCount;
       PSID pSid;
       SID_NAME_USE snu;

       WCHAR DomainName[DNLEN+1];
       DWORD cchDomainName = DNLEN+1;
       BOOL bSuccess = FALSE; // assume failure

       // 
       // get the account domain Sid on the target machine
       // note: if you were looking up multiple sids based on the same
       // account domain, only need to call this once.
       // 

       nas = NetUserModalsGet(TargetComputer, 2, (LPBYTE *)&umi2);

       if(nas != NERR_Success) {
           SetLastError(nas);
           return FALSE;
       }

       SubAuthorityCount = *GetSidSubAuthorityCount
                            (umi2->usrmod2_domain_id);

       // 
       // allocate storage for new Sid. account domain Sid + account Rid
       // 

       pSid = (PSID)HeapAlloc(GetProcessHeap(), 0,
               GetSidLengthRequired((UCHAR)(SubAuthorityCount + 1)));

       if(pSid != NULL) {

           if(InitializeSid(
                   pSid,
                   GetSidIdentifierAuthority(umi2->usrmod2_domain_id),
                   (BYTE)(SubAuthorityCount+1)
                   )) {

               DWORD SubAuthIndex = 0;

               // 
               // copy existing subauthorities from account domain Sid into
               // new Sid
               // 

               for( ; SubAuthIndex < SubAuthorityCount ; SubAuthIndex++) {
                   *GetSidSubAuthority(pSid, SubAuthIndex) =
                   *GetSidSubAuthority(umi2->usrmod2_domain_id,
                                       SubAuthIndex);
               }

               // 
               // append Rid to new Sid
               // 

               *GetSidSubAuthority(pSid, SubAuthorityCount) = Rid;

               bSuccess = LookupAccountSidW(
                       TargetComputer,
                       pSid,
                       Name,
                       cchName,
                       DomainName,
                       &cchDomainName,
                       &snu
                       );
           }

           HeapFree(GetProcessHeap(), 0, pSid);
       }

       NetApiBufferFree(umi2);

       return bSuccess;
   }
				

A informação contida neste artigo aplica-se a:
  • Microsoft Win32 Application Programming Interface nas seguintes plataformas
    • Microsoft Windows NT 3.51 Service Pack 5
    • Microsoft Windows NT 4.0
    • the operating system: Microsoft Windows 2000
    • the operating system: Microsoft Windows XP
Palavras-chave: 
kbmt kbcode kbhowto kbkernbase kbnetwork kbsecurity KB157234 KbMtpt
Tradução automáticaTradução automática
IMPORTANTE: Este artigo foi traduzido por um sistema de tradução automática (também designado por Machine translation ou MT), não tendo sido portanto revisto ou traduzido por humanos. A Microsoft tem artigos traduzidos por aplicações (MT) e artigos traduzidos por tradutores profissionais. O objectivo é simples: oferecer em Português a totalidade dos artigos existentes na base de dados do suporte. Sabemos no entanto que a tradução automática não é sempre perfeita. Esta pode conter erros de vocabulário, sintaxe ou gramática? erros semelhantes aos que um estrangeiro realiza ao falar em Português. A Microsoft não é responsável por incoerências, erros ou estragos realizados na sequência da utilização dos artigos MT por parte dos nossos clientes. A Microsoft realiza actualizações frequentes ao software de tradução automática (MT). Pedíamos-lhe o favor de preencher o formulário existente no fundo desta página caso venha a encontrar erros neste artigo e tenha possibilidade de colaborar no processo de aperfeiçoamento desta ferramenta. Obrigado.
Clique aqui para ver a versão em Inglês deste artigo: 157234  (http://support.microsoft.com/kb/157234/en-us/ )

Traduções de Artigos