WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, LPWSTR Domain, UINT32 DomainLength) { int length; BOOL found = 0; LPWSTR EntryUser; UINT32 EntryUserLength; WINPR_SAM_ENTRY* entry; entry = (WINPR_SAM_ENTRY*) malloc(sizeof(WINPR_SAM_ENTRY)); SamLookupStart(sam); while (sam->line != NULL) { length = strlen(sam->line); if (length > 1) { if (sam->line[0] != '#') { entry = SamReadEntry(sam, entry); EntryUserLength = strlen(entry->User) * 2; EntryUser = (LPWSTR) malloc(EntryUserLength + 2); MultiByteToWideChar(CP_ACP, 0, entry->User, EntryUserLength / 2, (LPWSTR) EntryUser, EntryUserLength / 2); if (UserLength == EntryUserLength) { if (memcmp(User, EntryUser, UserLength) == 0) { found = 1; break; } } } } sam->line = strtok(NULL, "\n"); } SamLookupFinish(sam); if (!found) { free(entry); return NULL; } return entry; }
WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, LPSTR Domain, UINT32 DomainLength) { int length; BOOL found = FALSE; WINPR_SAM_ENTRY* entry; entry = (WINPR_SAM_ENTRY*) calloc(1, sizeof(WINPR_SAM_ENTRY)); if (!entry) return NULL; if (!SamLookupStart(sam)) { free(entry); return NULL; } while (sam->line != NULL) { length = (int) strlen(sam->line); if (length > 1) { if (sam->line[0] != '#') { if (!SamReadEntry(sam, entry)) { goto out_fail; } if (strcmp(User, entry->User) == 0) { found = 1; break; } } } SamResetEntry(entry); sam->line = strtok(NULL, "\n"); } out_fail: SamLookupFinish(sam); if (!found) { free(entry); return NULL; } return entry; }
WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, LPSTR Domain, UINT32 DomainLength) { int length; BOOL found = 0; WINPR_SAM_ENTRY* entry; entry = (WINPR_SAM_ENTRY*) malloc(sizeof(WINPR_SAM_ENTRY)); SamLookupStart(sam); while (sam->line != NULL) { length = strlen(sam->line); if (length > 1) { if (sam->line[0] != '#') { SamReadEntry(sam, entry); if (strcmp(User, entry->User) == 0) { found = 1; break; } } } sam->line = strtok(NULL, "\n"); } SamLookupFinish(sam); if (!found) { free(entry); return NULL; } return entry; }
WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, LPWSTR Domain, UINT32 DomainLength) { int length; BOOL Found = FALSE; BOOL UserMatch; BOOL DomainMatch; LPWSTR EntryUser = NULL; UINT32 EntryUserLength; LPWSTR EntryDomain = NULL; UINT32 EntryDomainLength; WINPR_SAM_ENTRY* entry; if (!(entry = (WINPR_SAM_ENTRY*) calloc(1, sizeof(WINPR_SAM_ENTRY)))) return NULL; if (!SamLookupStart(sam)) return NULL; while (sam->line != NULL) { length = (int) strlen(sam->line); if (length > 1) { if (sam->line[0] != '#') { DomainMatch = 0; UserMatch = 0; if (!SamReadEntry(sam, entry)) goto out_fail; if (DomainLength > 0) { if (entry->DomainLength > 0) { EntryDomainLength = (UINT32) strlen(entry->Domain) * 2; EntryDomain = (LPWSTR) malloc(EntryDomainLength + 2); if (!EntryDomain) goto out_fail; MultiByteToWideChar(CP_ACP, 0, entry->Domain, EntryDomainLength / 2, (LPWSTR) EntryDomain, EntryDomainLength / 2); if (DomainLength == EntryDomainLength) { if (memcmp(Domain, EntryDomain, DomainLength) == 0) { DomainMatch = 1; } } free(EntryDomain); } else { DomainMatch = 0; } } else { DomainMatch = 1; } if (DomainMatch) { EntryUserLength = (UINT32) strlen(entry->User) * 2; EntryUser = (LPWSTR) malloc(EntryUserLength + 2); if (!EntryUser) goto out_fail; MultiByteToWideChar(CP_ACP, 0, entry->User, EntryUserLength / 2, (LPWSTR) EntryUser, EntryUserLength / 2); if (UserLength == EntryUserLength) { if (memcmp(User, EntryUser, UserLength) == 0) { UserMatch = 1; } } free(EntryUser); if (UserMatch && DomainMatch) { Found = TRUE; break; } } } } SamResetEntry(entry); sam->line = strtok(NULL, "\n"); } out_fail: SamLookupFinish(sam); if (!Found) { free(entry); return NULL; } return entry; }