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

« back to all changes in this revision

Viewing changes to helpers/ntlm_auth/smb_lm/smbval/smblib.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* UNIX SMBlib NetBIOS implementation
 
3
 *
 
4
 * Version 1.0
 
5
 * SMBlib Routines
 
6
 *
 
7
 * Copyright (C) Richard Sharpe 1996
 
8
 *
 
9
 */
 
10
 
 
11
/*
 
12
 * This program is free software; you can redistribute it and/or modify
 
13
 * it under the terms of the GNU General Public License as published by
 
14
 * the Free Software Foundation; either version 2 of the License, or
 
15
 * (at your option) any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
25
 */
 
26
 
 
27
#include "config.h"
 
28
#include <stdlib.h>
 
29
#include <ctype.h>
 
30
#include <string.h>
 
31
 
 
32
int SMBlib_errno;
 
33
int SMBlib_SMB_Error;
 
34
#define SMBLIB_ERRNO
 
35
#define uchar unsigned char
 
36
#include "smblib-priv.h"
 
37
 
 
38
#include "rfcnb.h"
 
39
#include "smbencrypt.h"
 
40
 
 
41
#include <signal.h>
 
42
 
 
43
/* local functions */
 
44
int SMB_Term(void);
 
45
SMB_Handle_Type SMB_Create_Con_Handle(void);
 
46
int SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn);
 
47
SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, char *server, char *NTdomain);
 
48
SMB_Handle_Type SMB_Connect(SMB_Handle_Type Con_Handle, SMB_Tree_Handle * tree, char *service, char *username, char *password);
 
49
 
 
50
 
 
51
/* #define DEBUG */
 
52
 
 
53
SMB_State_Types SMBlib_State;
 
54
 
 
55
/* Initialize the SMBlib package     */
 
56
 
 
57
int
 
58
SMB_Init()
 
59
{
 
60
 
 
61
    SMBlib_State = SMB_State_Started;
 
62
 
 
63
    signal(SIGPIPE, SIG_IGN);   /* Ignore these ... */
 
64
 
 
65
    /* If SMBLIB_Instrument is defines, turn on the instrumentation stuff */
 
66
#ifdef SMBLIB_INSTRUMENT
 
67
 
 
68
    SMBlib_Instrument_Init();
 
69
 
 
70
#endif
 
71
 
 
72
    return 0;
 
73
 
 
74
}
 
75
 
 
76
int
 
77
SMB_Term()
 
78
{
 
79
 
 
80
#ifdef SMBLIB_INSTRUMENT
 
81
 
 
82
    SMBlib_Instrument_Term();   /* Clean up and print results */
 
83
 
 
84
#endif
 
85
 
 
86
    return 0;
 
87
 
 
88
}
 
89
 
 
90
/**
 
91
 * SMB_Create: Create a connection structure and return for later use
 
92
 * We have other helper routines to set variables
 
93
 */
 
94
SMB_Handle_Type
 
95
SMB_Create_Con_Handle()
 
96
{
 
97
    SMBlib_errno = SMBlibE_NotImpl;
 
98
    return (NULL);
 
99
}
 
100
 
 
101
int
 
102
SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn)
 
103
{
 
104
    if (RFCNB_Set_Sock_NoDelay(Con_Handle->Trans_Connect, yn) < 0) {
 
105
        fprintf(stderr, "Setting no-delay on TCP socket failed ...\n");
 
106
    }
 
107
    return (0);
 
108
}
 
109
 
 
110
/* SMB_Connect_Server: Connect to a server, but don't negotiate protocol */
 
111
/* or anything else ...                                                  */
 
112
SMB_Handle_Type
 
113
SMB_Connect_Server(SMB_Handle_Type Con_Handle,
 
114
                   char *server, char *NTdomain)
 
115
{
 
116
    SMB_Handle_Type con;
 
117
    char called[80], calling[80], *address;
 
118
    int i;
 
119
 
 
120
    /* Get a connection structure if one does not exist */
 
121
 
 
122
    con = Con_Handle;
 
123
 
 
124
    if (Con_Handle == NULL) {
 
125
 
 
126
        if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) {
 
127
 
 
128
 
 
129
            SMBlib_errno = SMBlibE_NoSpace;
 
130
            return NULL;
 
131
        }
 
132
    }
 
133
    /* Init some things ... */
 
134
 
 
135
    strcpy(con->service, "");
 
136
    strcpy(con->username, "");
 
137
    strcpy(con->password, "");
 
138
    strcpy(con->sock_options, "");
 
139
    strcpy(con->address, "");
 
140
    strcpy(con->desthost, server);
 
141
    strcpy(con->PDomain, NTdomain);
 
142
    strcpy(con->OSName, SMBLIB_DEFAULT_OSNAME);
 
143
    strcpy(con->LMType, SMBLIB_DEFAULT_LMTYPE);
 
144
    con->first_tree = con->last_tree = NULL;
 
145
 
 
146
    /* ugh. This is horribly broken. */
 
147
    /*   SMB_Get_My_Name(con -> myname, sizeof(con -> myname)); */
 
148
    /* hacked by Kinkie */
 
149
    i = gethostname(con->myname, sizeof(con->myname));
 
150
    if (i == -1) {
 
151
        strcpy(con->myname, "unknown");
 
152
    } else {
 
153
        if (NULL != (address = strchr(con->myname, '.'))) {
 
154
            *address = '\0';    /* truncate at first '.' */
 
155
        }
 
156
    }
 
157
 
 
158
 
 
159
    con->port = 0;              /* No port selected */
 
160
 
 
161
    /* Get some things we need for the SMB Header */
 
162
 
 
163
    con->pid = getpid();
 
164
    con->mid = con->pid;        /* This will do for now ... */
 
165
    con->uid = 0;               /* Until we have done a logon, no uid ... */
 
166
    con->gid = getgid();
 
167
 
 
168
    /* Now connect to the remote end, but first upper case the name of the
 
169
     * service we are going to call, sine some servers want it in uppercase */
 
170
 
 
171
    for (i = 0; i < strlen(server); i++)
 
172
        called[i] = xtoupper(server[i]);
 
173
 
 
174
    called[strlen(server)] = 0; /* Make it a string */
 
175
 
 
176
    for (i = 0; i < strlen(con->myname); i++)
 
177
        calling[i] = xtoupper(con->myname[i]);
 
178
 
 
179
    calling[strlen(con->myname)] = 0;   /* Make it a string */
 
180
 
 
181
    if (strcmp(con->address, "") == 0)
 
182
        address = con->desthost;
 
183
    else
 
184
        address = con->address;
 
185
 
 
186
    con->Trans_Connect = RFCNB_Call(called,
 
187
                                    calling,
 
188
                                    address,            /* Protocol specific */
 
189
                                    con->port);
 
190
 
 
191
    /* Did we get one? */
 
192
 
 
193
    if (con->Trans_Connect == NULL) {
 
194
 
 
195
        if (Con_Handle == NULL) {
 
196
            Con_Handle = NULL;
 
197
            free(con);
 
198
        }
 
199
        SMBlib_errno = -SMBlibE_CallFailed;
 
200
        return NULL;
 
201
 
 
202
    }
 
203
    return (con);
 
204
 
 
205
}
 
206
 
 
207
/* SMB_Connect: Connect to the indicated server                       */
 
208
/* If Con_Handle == NULL then create a handle and connect, otherwise  */
 
209
/* use the handle passed                                              */
 
210
 
 
211
char const *SMB_Prots_Restrict[] = {"PC NETWORK PROGRAM 1.0",
 
212
                                    NULL
 
213
                                   };
 
214
 
 
215
 
 
216
SMB_Handle_Type
 
217
SMB_Connect(SMB_Handle_Type Con_Handle,
 
218
            SMB_Tree_Handle * tree,
 
219
            char *service,
 
220
            char *username,
 
221
            char *password)
 
222
{
 
223
    SMB_Handle_Type con;
 
224
    char *host, *address;
 
225
    char temp[80], called[80], calling[80];
 
226
    int i;
 
227
 
 
228
    /* Get a connection structure if one does not exist */
 
229
 
 
230
    con = Con_Handle;
 
231
 
 
232
    if (Con_Handle == NULL) {
 
233
 
 
234
        if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) {
 
235
 
 
236
            SMBlib_errno = SMBlibE_NoSpace;
 
237
            return NULL;
 
238
        }
 
239
    }
 
240
    /* Init some things ... */
 
241
 
 
242
    strcpy(con->service, service);
 
243
    strcpy(con->username, username);
 
244
    strcpy(con->password, password);
 
245
    strcpy(con->sock_options, "");
 
246
    strcpy(con->address, "");
 
247
    strcpy(con->PDomain, SMBLIB_DEFAULT_DOMAIN);
 
248
    strcpy(con->OSName, SMBLIB_DEFAULT_OSNAME);
 
249
    strcpy(con->LMType, SMBLIB_DEFAULT_LMTYPE);
 
250
    con->first_tree = con->last_tree = NULL;
 
251
 
 
252
    SMB_Get_My_Name(con->myname, sizeof(con->myname));
 
253
 
 
254
    con->port = 0;              /* No port selected */
 
255
 
 
256
    /* Get some things we need for the SMB Header */
 
257
 
 
258
    con->pid = getpid();
 
259
    con->mid = con->pid;        /* This will do for now ... */
 
260
    con->uid = 0;               /* Until we have done a logon, no uid */
 
261
    con->gid = getgid();
 
262
 
 
263
    /* Now figure out the host portion of the service */
 
264
 
 
265
    strcpy(temp, service);
 
266
    host = (char *) strtok(temp, "/\\");        /* Separate host name portion */
 
267
    strcpy(con->desthost, host);
 
268
 
 
269
    /* Now connect to the remote end, but first upper case the name of the
 
270
     * service we are going to call, sine some servers want it in uppercase */
 
271
 
 
272
    for (i = 0; i < strlen(host); i++)
 
273
        called[i] = xtoupper(host[i]);
 
274
 
 
275
    called[strlen(host)] = 0;   /* Make it a string */
 
276
 
 
277
    for (i = 0; i < strlen(con->myname); i++)
 
278
        calling[i] = xtoupper(con->myname[i]);
 
279
 
 
280
    calling[strlen(con->myname)] = 0;   /* Make it a string */
 
281
 
 
282
    if (strcmp(con->address, "") == 0)
 
283
        address = con->desthost;
 
284
    else
 
285
        address = con->address;
 
286
 
 
287
    con->Trans_Connect = RFCNB_Call(called,
 
288
                                    calling,
 
289
                                    address,            /* Protocol specific */
 
290
                                    con->port);
 
291
 
 
292
    /* Did we get one? */
 
293
 
 
294
    if (con->Trans_Connect == NULL) {
 
295
 
 
296
        if (Con_Handle == NULL) {
 
297
            free(con);
 
298
            Con_Handle = NULL;
 
299
        }
 
300
        SMBlib_errno = -SMBlibE_CallFailed;
 
301
        return NULL;
 
302
 
 
303
    }
 
304
 
 
305
    /* Now, negotiate the protocol */
 
306
    if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) {
 
307
 
 
308
        /* Hmmm what should we do here ... We have a connection, but could not
 
309
         * negotiate ...                                                      */
 
310
        return NULL;
 
311
    }
 
312
 
 
313
    /* Now connect to the service ... */
 
314
    if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) {
 
315
        return NULL;
 
316
    }
 
317
    return (con);
 
318
 
 
319
}
 
320
 
 
321
/* Logon to the server. That is, do a session setup if we can. We do not do */
 
322
/* Unicode yet!                                                             */
 
323
 
 
324
int
 
325
SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName,
 
326
                 char *PassWord, char *UserDomain, int precrypted)
 
327
{
 
328
    struct RFCNB_Pkt *pkt;
 
329
    int param_len, pkt_len, pass_len;
 
330
    char *p, pword[128];
 
331
 
 
332
    /* First we need a packet etc ... but we need to know what protocol has  */
 
333
    /* been negotiated to figure out if we can do it and what SMB format to  */
 
334
    /* use ...                                                               */
 
335
 
 
336
    if (Con_Handle->protocol < SMB_P_LanMan1) {
 
337
 
 
338
        SMBlib_errno = SMBlibE_ProtLow;
 
339
        return (SMBlibE_BAD);
 
340
 
 
341
    }
 
342
    if (precrypted) {
 
343
        pass_len = 24;
 
344
        memcpy(pword, PassWord, 24);
 
345
    } else {
 
346
        strcpy(pword, PassWord);
 
347
        if (Con_Handle->encrypt_passwords) {
 
348
            pass_len = 24;
 
349
            SMBencrypt((uchar *) PassWord, (uchar *) Con_Handle->Encrypt_Key, (uchar *) pword);
 
350
        } else
 
351
            pass_len = strlen(pword);
 
352
    }
 
353
 
 
354
    /* Now build the correct structure */
 
355
 
 
356
    if (Con_Handle->protocol < SMB_P_NT1) {
 
357
 
 
358
        param_len = strlen(UserName) + 1 + pass_len + 1 +
 
359
                    strlen(UserDomain) + 1 +
 
360
                    strlen(Con_Handle->OSName) + 1;
 
361
 
 
362
        pkt_len = SMB_ssetpLM_len + param_len;
 
363
 
 
364
        pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len);
 
365
 
 
366
        if (pkt == NULL) {
 
367
 
 
368
            SMBlib_errno = SMBlibE_NoSpace;
 
369
            fprintf(stderr, "SMB_Logon_server: Couldn't allocate packet\n");
 
370
            return (SMBlibE_BAD);       /* Should handle the error */
 
371
        }
 
372
        memset(SMB_Hdr(pkt), 0, SMB_ssetpLM_len);
 
373
        SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF);   /* Plunk in IDF */
 
374
        *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX;
 
375
        SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle->pid);
 
376
        SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
 
377
        SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid);
 
378
        SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid);
 
379
        *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 10;
 
380
        *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF;    /* No extra command */
 
381
        SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0);
 
382
 
 
383
        SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_mbs_offset, SMBLIB_MAX_XMIT);
 
384
        SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_mmc_offset, 2);
 
385
        SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_vcn_offset, Con_Handle->pid);
 
386
        SIVAL(SMB_Hdr(pkt), SMB_ssetpLM_snk_offset, 0);
 
387
        SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_pwl_offset, pass_len + 1);
 
388
        SIVAL(SMB_Hdr(pkt), SMB_ssetpLM_res_offset, 0);
 
389
        SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_bcc_offset, param_len);
 
390
 
 
391
        /* Now copy the param strings in with the right stuff */
 
392
 
 
393
        p = (char *) (SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset);
 
394
 
 
395
        /* Copy  in password, then the rest. Password has a null at end */
 
396
 
 
397
        memcpy(p, pword, pass_len);
 
398
 
 
399
        p = p + pass_len + 1;
 
400
 
 
401
        strcpy(p, UserName);
 
402
        p = p + strlen(UserName);
 
403
        *p = 0;
 
404
 
 
405
        p = p + 1;
 
406
 
 
407
        strcpy(p, UserDomain);
 
408
        p = p + strlen(UserDomain);
 
409
        *p = 0;
 
410
        p = p + 1;
 
411
 
 
412
        strcpy(p, Con_Handle->OSName);
 
413
        p = p + strlen(Con_Handle->OSName);
 
414
        *p = 0;
 
415
 
 
416
    } else {
 
417
 
 
418
        /* We don't admit to UNICODE support ... */
 
419
 
 
420
        param_len = strlen(UserName) + 1 + pass_len +
 
421
                    strlen(UserDomain) + 1 +
 
422
                    strlen(Con_Handle->OSName) + 1 +
 
423
                    strlen(Con_Handle->LMType) + 1;
 
424
 
 
425
        pkt_len = SMB_ssetpNTLM_len + param_len;
 
426
 
 
427
        pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len);
 
428
 
 
429
        if (pkt == NULL) {
 
430
 
 
431
            SMBlib_errno = SMBlibE_NoSpace;
 
432
            fprintf(stderr, "SMB_Logon_server: Couldn't allocate packet\n");
 
433
            return (-1);        /* Should handle the error */
 
434
        }
 
435
        memset(SMB_Hdr(pkt), 0, SMB_ssetpNTLM_len);
 
436
        SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF);   /* Plunk in IDF */
 
437
        *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX;
 
438
        SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle->pid);
 
439
        SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
 
440
        SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid);
 
441
        SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid);
 
442
        *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13;
 
443
        *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF;    /* No extra command */
 
444
        SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0);
 
445
 
 
446
        SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mbs_offset, SMBLIB_MAX_XMIT);
 
447
        SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mmc_offset, 0);
 
448
        SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_vcn_offset, 1); /* Thanks Tridge! */
 
449
        SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_snk_offset, 0);
 
450
        SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cipl_offset, pass_len);
 
451
        SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cspl_offset, 0);
 
452
        SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_res_offset, 0);
 
453
        SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cap_offset, 0);
 
454
        SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_bcc_offset, param_len);
 
455
 
 
456
        /* Now copy the param strings in with the right stuff */
 
457
 
 
458
        p = (char *) (SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset);
 
459
 
 
460
        /* Copy  in password, then the rest. Password has no null at end */
 
461
 
 
462
        memcpy(p, pword, pass_len);
 
463
 
 
464
        p = p + pass_len;
 
465
 
 
466
        strcpy(p, UserName);
 
467
        p = p + strlen(UserName);
 
468
        *p = 0;
 
469
 
 
470
        p = p + 1;
 
471
 
 
472
        strcpy(p, UserDomain);
 
473
        p = p + strlen(UserDomain);
 
474
        *p = 0;
 
475
        p = p + 1;
 
476
 
 
477
        strcpy(p, Con_Handle->OSName);
 
478
        p = p + strlen(Con_Handle->OSName);
 
479
        *p = 0;
 
480
        p = p + 1;
 
481
 
 
482
        strcpy(p, Con_Handle->LMType);
 
483
        p = p + strlen(Con_Handle->LMType);
 
484
        *p = 0;
 
485
 
 
486
    }
 
487
 
 
488
    /* Now send it and get a response */
 
489
 
 
490
    if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) {
 
491
 
 
492
#ifdef DEBUG
 
493
        fprintf(stderr, "Error sending SessSetupX request\n");
 
494
#endif
 
495
 
 
496
        RFCNB_Free_Pkt(pkt);
 
497
        SMBlib_errno = SMBlibE_SendFailed;
 
498
        return (SMBlibE_BAD);
 
499
 
 
500
    }
 
501
    /* Now get the response ... */
 
502
 
 
503
    if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) {
 
504
 
 
505
#ifdef DEBUG
 
506
        fprintf(stderr, "Error receiving response to SessSetupAndX\n");
 
507
#endif
 
508
 
 
509
        RFCNB_Free_Pkt(pkt);
 
510
        SMBlib_errno = SMBlibE_RecvFailed;
 
511
        return (SMBlibE_BAD);
 
512
 
 
513
    }
 
514
    /* Check out the response type ... */
 
515
 
 
516
    if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) {      /* Process error */
 
517
 
 
518
#ifdef DEBUG
 
519
        fprintf(stderr, "SMB_SessSetupAndX failed with errorclass = %i, Error Code = %i\n",
 
520
                CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset),
 
521
                SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset));
 
522
#endif
 
523
 
 
524
        SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset);
 
525
        RFCNB_Free_Pkt(pkt);
 
526
        SMBlib_errno = SMBlibE_Remote;
 
527
        return (SMBlibE_BAD);
 
528
 
 
529
    }
 
530
    /** @@@ mdz: check for guest login { **/
 
531
    if (SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset) & 0x1) {
 
532
        /* do we allow guest login? NO! */
 
533
        return (SMBlibE_BAD);
 
534
 
 
535
    }
 
536
    /** @@@ mdz: } **/
 
537
 
 
538
 
 
539
#ifdef DEBUG
 
540
    fprintf(stderr, "SessSetupAndX response. Action = %i\n",
 
541
            SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset));
 
542
#endif
 
543
 
 
544
    /* Now pick up the UID for future reference ... */
 
545
 
 
546
    Con_Handle->uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset);
 
547
    RFCNB_Free_Pkt(pkt);
 
548
 
 
549
    return (0);
 
550
 
 
551
}
 
552
 
 
553
 
 
554
/* Disconnect from the server, and disconnect all tree connects */
 
555
 
 
556
int
 
557
SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle)
 
558
{
 
559
 
 
560
    /* We just disconnect the connection for now ... */
 
561
    if (Con_Handle != NULL)
 
562
        RFCNB_Hangup(Con_Handle->Trans_Connect);
 
563
 
 
564
    if (!KeepHandle)
 
565
        free(Con_Handle);
 
566
 
 
567
    return (0);
 
568
 
 
569
}