~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to helpers/ntlm_auth/mswin_sspi/libntlmssp.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
10
 * GNU General Public License for more details.
11
 
 
 
11
 
12
12
 * You should have received a copy of the GNU General Public License
13
13
 * along with this program; if not, write to the Free Software
14
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
43
43
    DWORD i;
44
44
    DWORD dwTotalCount = 0;
45
45
 
46
 
/* Convert ANSI User Name and Group to Unicode */
 
46
    /* Convert ANSI User Name and Group to Unicode */
47
47
 
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]));
53
53
 
54
54
    /*
55
 
     * Call the NetUserGetLocalGroups function 
56
 
         * specifying information level 0.
57
 
         * 
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.
61
 
         */
62
 
        nStatus = NetUserGetLocalGroups(NULL,
63
 
            wszUserName,
64
 
            dwLevel,
65
 
            dwFlags,
66
 
            (LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
67
 
        /*
68
 
         * If the call succeeds,
69
 
         */
 
55
     * Call the NetUserGetLocalGroups function
 
56
     * specifying information level 0.
 
57
     *
 
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.
 
61
     */
 
62
    nStatus = NetUserGetLocalGroups(NULL,
 
63
                                    wszUserName,
 
64
                                    dwLevel,
 
65
                                    dwFlags,
 
66
                                    (LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
 
67
    /*
 
68
     * If the call succeeds,
 
69
     */
70
70
    if (nStatus == NERR_Success) {
71
 
        if ((pTmpBuf = pBuf) != NULL) {
72
 
            for (i = 0; i < dwEntriesRead; i++) {
73
 
                if (pTmpBuf == NULL) {
74
 
                    result = FALSE;
75
 
                    break;
76
 
                }
77
 
                if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) {
78
 
                    result = TRUE;
79
 
                    break;
80
 
                }
81
 
                pTmpBuf++;
82
 
                dwTotalCount++;
83
 
            }
84
 
        }
 
71
        if ((pTmpBuf = pBuf) != NULL) {
 
72
            for (i = 0; i < dwEntriesRead; i++) {
 
73
                if (pTmpBuf == NULL) {
 
74
                    result = FALSE;
 
75
                    break;
 
76
                }
 
77
                if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) {
 
78
                    result = TRUE;
 
79
                    break;
 
80
                }
 
81
                pTmpBuf++;
 
82
                dwTotalCount++;
 
83
            }
 
84
        }
85
85
    } else
86
 
            result = FALSE;
87
 
/*
88
 
 * Free the allocated memory.
89
 
 */
 
86
        result = FALSE;
 
87
    /*
 
88
     * Free the allocated memory.
 
89
     */
90
90
    if (pBuf != NULL)
91
 
        NetApiBufferFree(pBuf);
 
91
        NetApiBufferFree(pBuf);
92
92
    return result;
93
93
}
94
94
 
104
104
    safe_free(target);
105
105
    target = (char *)xmalloc(len);
106
106
    if (target == NULL)
107
 
        return NULL;
 
107
        return NULL;
108
108
 
109
109
    /* copy unicode buffer */
110
110
    WideCharToMultiByte(CP_ACP, 0, LsaStr.Buffer, LsaStr.Length, target, len, NULL, NULL );
126
126
    DWORD netret;
127
127
    char * DomainName = NULL;
128
128
 
129
 
    /* 
 
129
    /*
130
130
     * Always initialize the object attributes to all zeroes.
131
 
     */ 
 
131
     */
132
132
    memset(&ObjectAttributes, '\0', sizeof(ObjectAttributes));
133
133
 
134
 
    /* 
 
134
    /*
135
135
     * You need the local workstation name. Use NetWkstaGetInfo at level
136
136
     * 100 to retrieve a WKSTA_INFO_100 structure.
137
 
     * 
 
137
     *
138
138
     * The wki100_computername field contains a pointer to a UNICODE
139
139
     * string containing the local computer name.
140
 
     */ 
 
140
     */
141
141
    netret = NetWkstaGetInfo(NULL, 100, (LPBYTE *)&pwkiWorkstationInfo);
142
142
    if (netret == NERR_Success) {
143
 
        /* 
144
 
         * We have the workstation name in:
145
 
         * pwkiWorkstationInfo->wki100_computername
146
 
         * 
147
 
         * Next, open the policy object for the local system using
148
 
         * the LsaOpenPolicy function.
149
 
         */ 
150
 
        status = LsaOpenPolicy(
151
 
                 NULL,
152
 
                 &ObjectAttributes,
153
 
                 GENERIC_READ | POLICY_VIEW_LOCAL_INFORMATION,
154
 
                 &PolicyHandle
155
 
                );
156
 
        
157
 
        /* 
158
 
         * Error checking.
159
 
         */ 
160
 
        if (status) {
161
 
            debug("OpenPolicy Error: %ld\n", status);
162
 
        } else {
163
 
 
164
 
            /* 
165
 
             * You have a handle to the policy object. Now, get the
166
 
             * domain information using LsaQueryInformationPolicy.
167
 
             */ 
168
 
            status = LsaQueryInformationPolicy(PolicyHandle,
169
 
                PolicyPrimaryDomainInformation,
170
 
                (void **)&ppdiDomainInfo);
171
 
            if (status) {
172
 
                debug("LsaQueryInformationPolicy Error: %ld\n", status);
173
 
            } else  {
174
 
 
175
 
                /* Get name in useable format */
176
 
                DomainName = AllocStrFromLSAStr(ppdiDomainInfo->Name);
177
 
 
178
 
                /* 
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.
182
 
                 */ 
183
 
                if (ppdiDomainInfo->Sid) {
184
 
 
185
 
                    /* 
186
 
                     * Member of a domain. Display it in debug mode.
187
 
                     */ 
188
 
                    debug("Member of Domain %s\n",DomainName);
189
 
                } else {
190
 
                    DomainName = NULL;
 
143
        /*
 
144
         * We have the workstation name in:
 
145
         * pwkiWorkstationInfo->wki100_computername
 
146
         *
 
147
         * Next, open the policy object for the local system using
 
148
         * the LsaOpenPolicy function.
 
149
         */
 
150
        status = LsaOpenPolicy(
 
151
                     NULL,
 
152
                     &ObjectAttributes,
 
153
                     GENERIC_READ | POLICY_VIEW_LOCAL_INFORMATION,
 
154
                     &PolicyHandle
 
155
                 );
 
156
 
 
157
        /*
 
158
         * Error checking.
 
159
         */
 
160
        if (status) {
 
161
            debug("OpenPolicy Error: %ld\n", status);
 
162
        } else {
 
163
 
 
164
            /*
 
165
             * You have a handle to the policy object. Now, get the
 
166
             * domain information using LsaQueryInformationPolicy.
 
167
             */
 
168
            status = LsaQueryInformationPolicy(PolicyHandle,
 
169
                                               PolicyPrimaryDomainInformation,
 
170
                                               (void **)&ppdiDomainInfo);
 
171
            if (status) {
 
172
                debug("LsaQueryInformationPolicy Error: %ld\n", status);
 
173
            } else  {
 
174
 
 
175
                /* Get name in useable format */
 
176
                DomainName = AllocStrFromLSAStr(ppdiDomainInfo->Name);
 
177
 
 
178
                /*
 
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.
 
182
                 */
 
183
                if (ppdiDomainInfo->Sid) {
 
184
 
 
185
                    /*
 
186
                     * Member of a domain. Display it in debug mode.
 
187
                     */
 
188
                    debug("Member of Domain %s\n",DomainName);
 
189
                } else {
 
190
                    DomainName = NULL;
191
191
                }
192
 
            }
193
 
        }
 
192
            }
 
193
        }
194
194
 
195
 
        /* 
196
 
         * Clean up all the memory buffers created by the LSA and
197
 
         * Net* APIs.
198
 
         */ 
199
 
        NetApiBufferFree(pwkiWorkstationInfo);
200
 
        LsaFreeMemory((LPVOID)ppdiDomainInfo);
201
 
    } else 
202
 
        debug("NetWkstaGetInfo Error: %ld\n", netret);
 
195
        /*
 
196
         * Clean up all the memory buffers created by the LSA and
 
197
         * Net* APIs.
 
198
         */
 
199
        NetApiBufferFree(pwkiWorkstationInfo);
 
200
        LsaFreeMemory((LPVOID)ppdiDomainInfo);
 
201
    } else
 
202
        debug("NetWkstaGetInfo Error: %ld\n", netret);
203
203
    return DomainName;
204
204
}
205
205
 
228
228
        tmp = ntlm_fetch_string((char *) auth, auth_length, &auth->domain);
229
229
 
230
230
        if (tmp.str == NULL || tmp.l == 0) {
231
 
            debug("No domain supplied. Returning no-auth\n");
232
 
            ntlm_errno = NTLM_BAD_REQUEST;
233
 
            return NULL;
 
231
            debug("No domain supplied. Returning no-auth\n");
 
232
            ntlm_errno = NTLM_BAD_REQUEST;
 
233
            return NULL;
234
234
        }
235
235
        if (Use_Unicode) {
236
236
            /* copy unicode buffer */
239
239
            domain[tmp.l / sizeof(WCHAR)] = '\0';
240
240
        } else {
241
241
            if (tmp.l > DNLEN) {
242
 
                debug("Domain string exceeds %d bytes, rejecting\n", DNLEN);
243
 
                ntlm_errno = NTLM_BAD_REQUEST;
244
 
                return NULL;
 
242
                debug("Domain string exceeds %d bytes, rejecting\n", DNLEN);
 
243
                ntlm_errno = NTLM_BAD_REQUEST;
 
244
                return NULL;
245
245
            }
246
246
            memcpy(domain, tmp.str, tmp.l);
247
247
            domain[tmp.l] = '\0';
248
248
        }
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;
253
 
            return NULL;
 
251
            debug("No username supplied. Returning no-auth\n");
 
252
            ntlm_errno = NTLM_BAD_REQUEST;
 
253
            return NULL;
254
254
        }
255
255
        if (Use_Unicode) {
256
256
            /* copy unicode buffer */
259
259
            user[tmp.l / sizeof(WCHAR)] = '\0';
260
260
        } else {
261
261
            if (tmp.l > UNLEN) {
262
 
                debug("Username string exceeds %d bytes, rejecting\n", UNLEN);
263
 
                ntlm_errno = NTLM_BAD_REQUEST;
264
 
                return NULL;
 
262
                debug("Username string exceeds %d bytes, rejecting\n", UNLEN);
 
263
                ntlm_errno = NTLM_BAD_REQUEST;
 
264
                return NULL;
265
265
            }
266
266
            memcpy(user, tmp.str, tmp.l);
267
267
            user[tmp.l] = '\0';
276
276
    debug("Login attempt had result %d\n", rv);
277
277
 
278
278
    if (!rv) {                  /* failed */
279
 
        ntlm_errno = NTLM_SSPI_ERROR;
280
 
        return NULL;
 
279
        ntlm_errno = NTLM_SSPI_ERROR;
 
280
        return NULL;
281
281
    }
282
 
    
 
282
 
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);
287
 
            return NULL;
288
 
        }
 
284
        if (!Valid_Group(credentials, NTAllowedGroup)) {
 
285
            ntlm_errno = NTLM_BAD_NTGROUP;
 
286
            debug("User %s not in allowed Group %s\n", credentials, NTAllowedGroup);
 
287
            return NULL;
 
288
        }
289
289
    }
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);
294
 
            return NULL;
295
 
        }
 
291
        if (Valid_Group(credentials, NTDisAllowedGroup)) {
 
292
            ntlm_errno = NTLM_BAD_NTGROUP;
 
293
            debug("User %s is in denied Group %s\n", credentials, NTDisAllowedGroup);
 
294
            return NULL;
 
295
        }
296
296
    }
297
297
 
298
298
    debug("credentials: %s\n", credentials);
309
309
    memcpy(ne.signature, "NTLMSSP", 8);         /* set the signature */
310
310
    ne.type = le32toh(NTLM_NEGOTIATE);  /* this is a challenge */
311
311
    ne.flags = le32toh(
312
 
        NEGOTIATE_ALWAYS_SIGN |
313
 
        NEGOTIATE_USE_NTLM |
314
 
        NEGOTIATE_USE_LM |
315
 
        NEGOTIATE_ASCII |
316
 
        0
317
 
        );
 
312
                   NEGOTIATE_ALWAYS_SIGN |
 
313
                   NEGOTIATE_USE_NTLM |
 
314
                   NEGOTIATE_USE_LM |
 
315
                   NEGOTIATE_ASCII |
 
316
                   0
 
317
               );
318
318
    encoded = base64_encode_bin((char *) &ne, NEGOTIATE_LENGTH);
319
319
    debug("Negotiate packet not supplied - self generated\n");
320
320
    return encoded;
340
340
        char addrstr[10] = {0};
341
341
        char hexstr[ 16*3 + 5] = {0};
342
342
        char charstr[16*1 + 5] = {0};
343
 
        for(n=1;n<=size;n++) {
 
343
        for (n=1;n<=size;n++) {
344
344
            if (n%16 == 1) {
345
345
                /* store address for this line */
346
346
                snprintf(addrstr, sizeof(addrstr), "%.4x",
347
 
                   ((unsigned int)p-(unsigned int)data) );
 
347
                         ((unsigned int)p-(unsigned int)data) );
348
348
            }
349
 
            
 
349
 
350
350
            c = *p;
351
351
            if (xisalnum(c) == 0) {
352
352
                c = '.';
360
360
            snprintf(bytestr, sizeof(bytestr), "%c", c);
361
361
            strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1);
362
362
 
363
 
            if(n%16 == 0) { 
 
363
            if (n%16 == 0) {
364
364
                /* line completed */
365
365
                fprintf(stderr, "[%4.4s]   %-50.50s  %s\n", addrstr, hexstr, charstr);
366
366
                hexstr[0] = 0;
367
367
                charstr[0] = 0;
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);