ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

secext.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Juan Lang
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include <precomp.h>
00020 
00021 #define NDEBUG
00022 #include <debug.h>
00023 
00024 #define UNLEN 256
00025 
00026 
00027 /***********************************************************************
00028  *      GetComputerObjectNameA (SECUR32.@) Wine 1.1.14
00029  *
00030  * Get the local computer's name using the format specified.
00031  *
00032  * PARAMS
00033  *  NameFormat   [I] The format for the name.
00034  *  lpNameBuffer [O] Pointer to buffer to receive the name.
00035  *  nSize        [I/O] Size in characters of buffer.
00036  *
00037  * RETURNS
00038  *  TRUE  If the name was written to lpNameBuffer.
00039  *  FALSE If the name couldn't be written.
00040  *
00041  * NOTES
00042  *  If lpNameBuffer is NULL, then the size of the buffer needed to hold the
00043  *  name will be returned in *nSize.
00044  *
00045  *  nSize returns the number of characters written when lpNameBuffer is not
00046  *  NULL or the size of the buffer needed to hold the name when the buffer
00047  *  is too short or lpNameBuffer is NULL.
00048  * 
00049  *  It the buffer is too short, ERROR_INSUFFICIENT_BUFFER error will be set.
00050  */
00051 BOOLEAN WINAPI GetComputerObjectNameA(
00052   EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG nSize)
00053 {
00054     BOOLEAN rc;
00055     LPWSTR bufferW = NULL;
00056     ULONG sizeW = *nSize;
00057     DPRINT("(%d %p %p)\n", NameFormat, lpNameBuffer, nSize);
00058     if (lpNameBuffer) {
00059         bufferW = HeapAlloc(GetProcessHeap(), 0, sizeW * sizeof(WCHAR));
00060         if (bufferW == NULL) {
00061             SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00062             return FALSE;
00063         }
00064     }
00065     rc = GetComputerObjectNameW(NameFormat, bufferW, &sizeW);
00066     if (rc && bufferW) {
00067         ULONG len = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL);
00068         WideCharToMultiByte(CP_ACP, 0, bufferW, -1, lpNameBuffer, *nSize, NULL, NULL);
00069         *nSize = len;
00070     }
00071     else
00072         *nSize = sizeW;
00073     HeapFree(GetProcessHeap(), 0, bufferW);
00074     return rc;
00075 }
00076 
00077 /***********************************************************************
00078  *      GetComputerObjectNameW (SECUR32.@) Wine 1.1.14
00079  */
00080 BOOLEAN WINAPI GetComputerObjectNameW(
00081   EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize)
00082 {
00083     LSA_HANDLE policyHandle;
00084     LSA_OBJECT_ATTRIBUTES objectAttributes;
00085     PPOLICY_DNS_DOMAIN_INFO domainInfo;
00086     NTSTATUS ntStatus;
00087     BOOLEAN status;
00088     DPRINT("(%d %p %p)\n", NameFormat, lpNameBuffer, nSize);
00089 
00090     if (NameFormat == NameUnknown)
00091     {
00092         SetLastError(ERROR_INVALID_PARAMETER);
00093         return FALSE;
00094     }
00095 
00096     ZeroMemory(&objectAttributes, sizeof(objectAttributes));
00097     objectAttributes.Length = sizeof(objectAttributes);
00098 
00099     ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
00100                              POLICY_VIEW_LOCAL_INFORMATION,
00101                              &policyHandle);
00102     if (ntStatus != STATUS_SUCCESS)
00103     {
00104         SetLastError(LsaNtStatusToWinError(ntStatus));
00105         DPRINT1("LsaOpenPolicy failed with NT status %u\n", GetLastError());
00106         return FALSE;
00107     }
00108 
00109     ntStatus = LsaQueryInformationPolicy(policyHandle,
00110                                          PolicyDnsDomainInformation,
00111                                          (PVOID *)&domainInfo);
00112     if (ntStatus != STATUS_SUCCESS)
00113     {
00114         SetLastError(LsaNtStatusToWinError(ntStatus));
00115         DPRINT1("LsaQueryInformationPolicy failed with NT status %u\n",
00116              GetLastError());
00117         LsaClose(policyHandle);
00118         return FALSE;
00119     }
00120 
00121     if (domainInfo->Sid)
00122     {
00123         switch (NameFormat)
00124         {
00125         case NameSamCompatible:
00126             {
00127                 WCHAR name[MAX_COMPUTERNAME_LENGTH + 1];
00128                 DWORD size = sizeof(name)/sizeof(name[0]);
00129                 if (GetComputerNameW(name, &size))
00130                 {
00131                     DWORD len = domainInfo->Name.Length + size + 3;
00132                     if (lpNameBuffer)
00133                     {
00134                         if (*nSize < len)
00135                         {
00136                             *nSize = len;
00137                             SetLastError(ERROR_INSUFFICIENT_BUFFER);
00138                             status = FALSE;
00139                         }
00140                         else
00141                         {
00142                             WCHAR bs[] = { '\\', 0 };
00143                             WCHAR ds[] = { '$', 0 };
00144                             lstrcpyW(lpNameBuffer, domainInfo->Name.Buffer);
00145                             lstrcatW(lpNameBuffer, bs);
00146                             lstrcatW(lpNameBuffer, name);
00147                             lstrcatW(lpNameBuffer, ds);
00148                             status = TRUE;
00149                         }
00150                     }
00151                     else    /* just requesting length required */
00152                     {
00153                         *nSize = len;
00154                         status = TRUE;
00155                     }
00156                 }
00157                 else
00158                 {
00159                     SetLastError(ERROR_INTERNAL_ERROR);
00160                     status = FALSE;
00161                 }
00162             }
00163             break;
00164         case NameFullyQualifiedDN:
00165         case NameDisplay:
00166         case NameUniqueId:
00167         case NameCanonical:
00168         case NameUserPrincipal:
00169         case NameCanonicalEx:
00170         case NameServicePrincipal:
00171         case NameDnsDomain:
00172             DPRINT1("NameFormat %d not implemented\n", NameFormat);
00173             SetLastError(ERROR_CANT_ACCESS_DOMAIN_INFO);
00174             status = FALSE;
00175             break;
00176         default:
00177             SetLastError(ERROR_INVALID_PARAMETER);
00178             status = FALSE;
00179         }
00180     }
00181     else
00182     {
00183         SetLastError(ERROR_CANT_ACCESS_DOMAIN_INFO);
00184         status = FALSE;
00185     }
00186 
00187     LsaFreeMemory(domainInfo);
00188     LsaClose(policyHandle);
00189 
00190     return status;
00191 }
00192 
00193 
00194 BOOLEAN WINAPI GetUserNameExA(
00195   EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG nSize)
00196 {
00197     BOOLEAN rc;
00198     LPWSTR bufferW = NULL;
00199     ULONG sizeW = *nSize;
00200     DPRINT("(%d %p %p)\n", NameFormat, lpNameBuffer, nSize);
00201     if (lpNameBuffer) {
00202         bufferW = HeapAlloc(GetProcessHeap(), 0, sizeW * sizeof(WCHAR));
00203         if (bufferW == NULL) {
00204             SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00205             return FALSE;
00206         }
00207     }
00208     rc = GetUserNameExW(NameFormat, bufferW, &sizeW);
00209     if (rc) {
00210         ULONG len = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL);
00211         if (len <= *nSize)
00212         {
00213             WideCharToMultiByte(CP_ACP, 0, bufferW, -1, lpNameBuffer, *nSize, NULL, NULL);
00214             *nSize = len - 1;
00215         }
00216         else
00217         {
00218             *nSize = len;
00219             rc = FALSE;
00220             SetLastError(ERROR_MORE_DATA);
00221         }
00222     }
00223     else
00224         *nSize = sizeW;
00225     HeapFree(GetProcessHeap(), 0, bufferW);
00226     return rc;
00227 }
00228 
00229 
00230 BOOLEAN WINAPI GetUserNameExW(
00231   EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize)
00232 {
00233     BOOLEAN status;
00234     WCHAR samname[UNLEN + 1 + MAX_COMPUTERNAME_LENGTH + 1];
00235     LPWSTR out;
00236     DWORD len;
00237     DPRINT("(%d %p %p)\n", NameFormat, lpNameBuffer, nSize);
00238 
00239     switch (NameFormat)
00240     {
00241     case NameSamCompatible:
00242         {
00243             /* This assumes the current user is always a local account */
00244             len = MAX_COMPUTERNAME_LENGTH + 1;
00245             if (GetComputerNameW(samname, &len))
00246             {
00247                 out = samname + lstrlenW(samname);
00248                 *out++ = '\\';
00249                 len = UNLEN + 1;
00250                 if (GetUserNameW(out, &len))
00251                 {
00252                     status = (lstrlenW(samname) < *nSize);
00253                     if (status)
00254                     {
00255                         lstrcpyW(lpNameBuffer, samname);
00256                         *nSize = lstrlenW(samname);
00257                     }
00258                     else
00259                     {
00260                         SetLastError(ERROR_MORE_DATA);
00261                         *nSize = lstrlenW(samname) + 1;
00262                     }
00263                 }
00264                 else
00265                     status = FALSE;
00266             }
00267             else
00268                 status = FALSE;
00269         }
00270         break;
00271     case NameUnknown:
00272     case NameFullyQualifiedDN:
00273     case NameDisplay:
00274     case NameUniqueId:
00275     case NameCanonical:
00276     case NameUserPrincipal:
00277     case NameCanonicalEx:
00278     case NameServicePrincipal:
00279     case NameDnsDomain:
00280         SetLastError(ERROR_NONE_MAPPED);
00281         status = FALSE;
00282         break;
00283     default:
00284         SetLastError(ERROR_INVALID_PARAMETER);
00285         status = FALSE;
00286     }
00287 
00288     return status;
00289 }

Generated on Fri May 25 2012 04:24:19 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.