44
44
DWORD dwTotalCount = 0;
46
/* Convert ANSI User Name and Group to Unicode */
46
/* Convert ANSI User Name and Group to Unicode */
48
48
MultiByteToWideChar(CP_ACP, 0, UserName,
49
strlen(UserName) + 1, wszUserName,
50
sizeof(wszUserName) / sizeof(wszUserName[0]));
49
strlen(UserName) + 1, wszUserName,
50
sizeof(wszUserName) / sizeof(wszUserName[0]));
51
51
MultiByteToWideChar(CP_ACP, 0, Group,
52
strlen(Group) + 1, wszGroup, sizeof(wszGroup) / sizeof(wszGroup[0]));
52
strlen(Group) + 1, wszGroup, sizeof(wszGroup) / sizeof(wszGroup[0]));
55
* Call the NetUserGetLocalGroups function
56
* specifying information level 0.
58
* The LG_INCLUDE_INDIRECT flag specifies that the
59
* function should also return the names of the local
60
* groups in which the user is indirectly a member.
62
nStatus = NetUserGetLocalGroups(NULL,
66
(LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
68
* If the call succeeds,
55
* Call the NetUserGetLocalGroups function
56
* specifying information level 0.
58
* The LG_INCLUDE_INDIRECT flag specifies that the
59
* function should also return the names of the local
60
* groups in which the user is indirectly a member.
62
nStatus = NetUserGetLocalGroups(NULL,
66
(LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
68
* If the call succeeds,
70
70
if (nStatus == NERR_Success) {
71
if ((pTmpBuf = pBuf) != NULL) {
72
for (i = 0; i < dwEntriesRead; i++) {
73
if (pTmpBuf == NULL) {
77
if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) {
71
if ((pTmpBuf = pBuf) != NULL) {
72
for (i = 0; i < dwEntriesRead; i++) {
73
if (pTmpBuf == NULL) {
77
if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) {
88
* Free the allocated memory.
88
* Free the allocated memory.
91
NetApiBufferFree(pBuf);
91
NetApiBufferFree(pBuf);
127
127
char * DomainName = NULL;
130
130
* Always initialize the object attributes to all zeroes.
132
132
memset(&ObjectAttributes, '\0', sizeof(ObjectAttributes));
135
135
* You need the local workstation name. Use NetWkstaGetInfo at level
136
136
* 100 to retrieve a WKSTA_INFO_100 structure.
138
138
* The wki100_computername field contains a pointer to a UNICODE
139
139
* string containing the local computer name.
141
141
netret = NetWkstaGetInfo(NULL, 100, (LPBYTE *)&pwkiWorkstationInfo);
142
142
if (netret == NERR_Success) {
144
* We have the workstation name in:
145
* pwkiWorkstationInfo->wki100_computername
147
* Next, open the policy object for the local system using
148
* the LsaOpenPolicy function.
150
status = LsaOpenPolicy(
153
GENERIC_READ | POLICY_VIEW_LOCAL_INFORMATION,
161
debug("OpenPolicy Error: %ld\n", status);
165
* You have a handle to the policy object. Now, get the
166
* domain information using LsaQueryInformationPolicy.
168
status = LsaQueryInformationPolicy(PolicyHandle,
169
PolicyPrimaryDomainInformation,
170
(void **)&ppdiDomainInfo);
172
debug("LsaQueryInformationPolicy Error: %ld\n", status);
175
/* Get name in useable format */
176
DomainName = AllocStrFromLSAStr(ppdiDomainInfo->Name);
179
* Check the Sid pointer, if it is null, the
180
* workstation is either a stand-alone computer
181
* or a member of a workgroup.
183
if (ppdiDomainInfo->Sid) {
186
* Member of a domain. Display it in debug mode.
188
debug("Member of Domain %s\n",DomainName);
144
* We have the workstation name in:
145
* pwkiWorkstationInfo->wki100_computername
147
* Next, open the policy object for the local system using
148
* the LsaOpenPolicy function.
150
status = LsaOpenPolicy(
153
GENERIC_READ | POLICY_VIEW_LOCAL_INFORMATION,
161
debug("OpenPolicy Error: %ld\n", status);
165
* You have a handle to the policy object. Now, get the
166
* domain information using LsaQueryInformationPolicy.
168
status = LsaQueryInformationPolicy(PolicyHandle,
169
PolicyPrimaryDomainInformation,
170
(void **)&ppdiDomainInfo);
172
debug("LsaQueryInformationPolicy Error: %ld\n", status);
175
/* Get name in useable format */
176
DomainName = AllocStrFromLSAStr(ppdiDomainInfo->Name);
179
* Check the Sid pointer, if it is null, the
180
* workstation is either a stand-alone computer
181
* or a member of a workgroup.
183
if (ppdiDomainInfo->Sid) {
186
* Member of a domain. Display it in debug mode.
188
debug("Member of Domain %s\n",DomainName);
196
* Clean up all the memory buffers created by the LSA and
199
NetApiBufferFree(pwkiWorkstationInfo);
200
LsaFreeMemory((LPVOID)ppdiDomainInfo);
202
debug("NetWkstaGetInfo Error: %ld\n", netret);
196
* Clean up all the memory buffers created by the LSA and
199
NetApiBufferFree(pwkiWorkstationInfo);
200
LsaFreeMemory((LPVOID)ppdiDomainInfo);
202
debug("NetWkstaGetInfo Error: %ld\n", netret);
203
203
return DomainName;
239
239
domain[tmp.l / sizeof(WCHAR)] = '\0';
241
241
if (tmp.l > DNLEN) {
242
debug("Domain string exceeds %d bytes, rejecting\n", DNLEN);
243
ntlm_errno = NTLM_BAD_REQUEST;
242
debug("Domain string exceeds %d bytes, rejecting\n", DNLEN);
243
ntlm_errno = NTLM_BAD_REQUEST;
246
246
memcpy(domain, tmp.str, tmp.l);
247
247
domain[tmp.l] = '\0';
249
249
tmp = ntlm_fetch_string((char *) auth, auth_length, &auth->user);
250
250
if (tmp.str == NULL || tmp.l == 0) {
251
debug("No username supplied. Returning no-auth\n");
252
ntlm_errno = NTLM_BAD_REQUEST;
251
debug("No username supplied. Returning no-auth\n");
252
ntlm_errno = NTLM_BAD_REQUEST;
255
255
if (Use_Unicode) {
256
256
/* copy unicode buffer */
276
276
debug("Login attempt had result %d\n", rv);
278
278
if (!rv) { /* failed */
279
ntlm_errno = NTLM_SSPI_ERROR;
279
ntlm_errno = NTLM_SSPI_ERROR;
283
283
if (UseAllowedGroup) {
284
if (!Valid_Group(credentials, NTAllowedGroup)) {
285
ntlm_errno = NTLM_BAD_NTGROUP;
286
debug("User %s not in allowed Group %s\n", credentials, NTAllowedGroup);
284
if (!Valid_Group(credentials, NTAllowedGroup)) {
285
ntlm_errno = NTLM_BAD_NTGROUP;
286
debug("User %s not in allowed Group %s\n", credentials, NTAllowedGroup);
290
290
if (UseDisallowedGroup) {
291
if (Valid_Group(credentials, NTDisAllowedGroup)) {
292
ntlm_errno = NTLM_BAD_NTGROUP;
293
debug("User %s is in denied Group %s\n", credentials, NTDisAllowedGroup);
291
if (Valid_Group(credentials, NTDisAllowedGroup)) {
292
ntlm_errno = NTLM_BAD_NTGROUP;
293
debug("User %s is in denied Group %s\n", credentials, NTDisAllowedGroup);
298
298
debug("credentials: %s\n", credentials);
360
360
snprintf(bytestr, sizeof(bytestr), "%c", c);
361
361
strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1);
364
364
/* line completed */
365
365
fprintf(stderr, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr);
368
} else if(n%8 == 0) {
368
} else if (n%8 == 0) {
369
369
/* half line: add whitespaces */
370
370
strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1);
371
371
strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1);