exper.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* UNIX SMBlib NetBIOS implementation
10 
11  Version 1.0
12  SMBlib Routines. Experimental Section ...
13 
14  Copyright (C) Richard Sharpe 1996
15 */
16 
17 /*
18  This program is free software; you can redistribute it and/or modify
19  it under the terms of the GNU General Public License as published by
20  the Free Software Foundation; either version 2 of the License, or
21  (at your option) any later version.
22 
23  This program is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  GNU General Public License for more details.
27 
28  You should have received a copy of the GNU General Public License
29  along with this program; if not, write to the Free Software
30  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32 
33 #include "squid.h"
34 #include "rfcnb/rfcnb.h"
35 #include "smblib/smblib-priv.h"
36 
37 #include <signal.h>
38 #if HAVE_STRING_H
39 #include <string.h>
40 #endif
41 
42 /* Logon and tree connect to the server. If a tree handle was given to us, */
43 /* we use it and return it, otherwise we create one ... */
44 
46  SMB_Tree_Handle Tree_Handle,
47  char *UserName,
48  char *PassWord,
49  char *service,
50  char *service_type)
51 
52 {
53  struct RFCNB_Pkt *pkt;
54  int param_len, i, pkt_len, andx_len, andx_param_len;
55  char *p, *AndXCom;
56  SMB_Tree_Handle tree;
57 
58  /* Lets create a tree if we need one ... */
59 
60  if (Tree_Handle == NULL) {
61 
62  tree = (SMB_Tree_Handle)malloc(sizeof(struct SMB_Tree_Structure));
63 
64  if (tree == NULL) {
65 
67  return(tree);
68 
69  } else { /* Initialize the tree */
70 
71  tree -> con = Con_Handle;
72  tree -> prev = tree -> next = NULL;
73 
74  }
75  } else
76  tree = Tree_Handle;
77 
78  /* First we need a packet etc ... but we need to know what protocol has */
79  /* been negotiated to figure out if we can do it and what SMB format to */
80  /* use ... */
81 
82  /* Since we are going to do a LogonAndX with a TCon as the second command*/
83  /* We need the packet size correct. So TCon starts at wct field */
84 
85  if (Con_Handle -> protocol < SMB_P_LanMan1) {
86 
88  if (Tree_Handle == NULL)
89  free(tree);
90  return(NULL);
91 
92  }
93 
94  /* Now build the correct structure */
95 
96  andx_len = SMB_tconx_len - SMB_hdr_wct_offset;
97 
98  /* We send a null password as we sent one in the setup and X */
99 
100  andx_param_len = strlen(service) + 1 + strlen(service_type) + 1;
101 
102  if (Con_Handle -> protocol < SMB_P_NT1) {
103 
104 #ifdef SMBLIB_DEBUG
105  fprintf(stderr, "Doing an LM session setup etc ...\n");
106 #endif
107 
108  /* We don't do encrypted passwords ... */
109 
110  param_len = strlen(UserName) + 1 + strlen(PassWord) + 1 +
111  strlen(Con_Handle -> PDomain) + 1 +
112  strlen(Con_Handle -> OSName) + 1;
113 
114  pkt_len = SMB_ssetpLM_len + param_len + andx_len + andx_param_len;
115 
116  pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len);
117 
118  if (pkt == NULL) {
119 
121  if (Tree_Handle == NULL)
122  free(tree);
123  return(NULL); /* Should handle the error */
124 
125  }
126 
127  memset(SMB_Hdr(pkt), 0, SMB_ssetpLM_len);
128  SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
130  SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid);
131  SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
132  SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid);
133  SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, 0);
134  *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 10;
135  *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = SMBtconX;
136  SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, SMB_ssetpLM_len + param_len);
137 
140  SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_vcn_offset, Con_Handle -> pid);
142  SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_pwl_offset, strlen(PassWord) + 1);
144  SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_bcc_offset, param_len);
145 
146  /* Now copy the param strings in with the right stuff */
147 
148  p = (char *)(SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset);
149 
150  /* Copy in password, then the rest. Password has no null at end */
151 
152  strcpy(p, PassWord);
153 
154  p = p + strlen(PassWord) + 1;
155 
156  strcpy(p, UserName);
157  p = p + strlen(UserName);
158  *p = 0;
159 
160  p = p + 1;
161 
162  strcpy(p, Con_Handle -> PDomain);
163  p = p + strlen(Con_Handle -> PDomain);
164  *p = 0;
165  p = p + 1;
166 
167  strcpy(p, Con_Handle -> OSName);
168  p = p + strlen(Con_Handle -> OSName);
169  *p = 0;
170 
171  AndXCom = SMB_Hdr(pkt) + SMB_ssetpLM_len + param_len - SMB_hdr_wct_offset;
172 
173  } else {
174 
175  /* We don't admit to UNICODE support ... */
176 
177 #ifdef SMBLIB_DEBUG
178  fprintf(stderr, "Doing NT LM Sess Setup etc ... \n");
179 #endif
180 
181  param_len = strlen(UserName) + 1 + strlen(PassWord) +
182  strlen(Con_Handle -> PDomain) + 1 +
183  strlen(Con_Handle -> OSName) + 1 +
184  strlen(Con_Handle -> LMType) + 1;
185 
186  pkt_len = SMB_ssetpNTLM_len + param_len + andx_len + andx_param_len;
187 
188  pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len);
189 
190  if (pkt == NULL) {
191 
193  if (Tree_Handle == NULL)
194  free(tree);
195  return(NULL); /* Should handle the error */
196 
197  }
198 
199  memset(SMB_Hdr(pkt), 0, SMB_ssetpNTLM_len);
200  SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
202  SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid);
203  SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
204  SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid);
205  SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, 0);
206  *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13;
207  *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = SMBtconX;
209 
214  SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cipl_offset, strlen(PassWord));
218  SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_bcc_offset, param_len);
219 
220  /* Now copy the param strings in with the right stuff */
221 
222  p = (char *)(SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset);
223 
224  /* Copy in password, then the rest. Password has no null at end */
225 
226  strcpy(p, PassWord);
227 
228  p = p + strlen(PassWord);
229 
230  strcpy(p, UserName);
231  p = p + strlen(UserName);
232  *p = 0;
233 
234  p = p + 1;
235 
236  strcpy(p, Con_Handle -> PDomain);
237  p = p + strlen(Con_Handle -> PDomain);
238  *p = 0;
239  p = p + 1;
240 
241  strcpy(p, Con_Handle -> OSName);
242  p = p + strlen(Con_Handle -> OSName);
243  *p = 0;
244  p = p + 1;
245 
246  strcpy(p, Con_Handle -> LMType);
247  p = p + strlen(Con_Handle -> LMType);
248  *p = 0;
249 
250  /* Now set up the TCON Part ... from WCT, make up a pointer that will
251  help us ... */
252 
253  AndXCom = SMB_Hdr(pkt) + SMB_ssetpNTLM_len + param_len - SMB_hdr_wct_offset;
254 
255  }
256  *(AndXCom + SMB_hdr_wct_offset) = 4;
257  *(AndXCom + SMB_tconx_axc_offset) = 0xFF; /* No command */
258  SSVAL(AndXCom, SMB_tconx_axo_offset, 0);
259  SSVAL(AndXCom, SMB_tconx_flg_offset, 0); /* Don't disconnect TID */
260  SSVAL(AndXCom, SMB_tconx_pwl_offset, 0); /* No password, */
261  SSVAL(AndXCom, SMB_tconx_bcc_offset, andx_param_len);
262 
263  p = (char *)(AndXCom + SMB_tconx_buf_offset);
264 
267  strcpy(p, service);
268  p = p + strlen(service) + 1;
269  strcpy(p, service_type);
270 
271  /* Now send it and get a response */
272 
273  if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
274 
275 #ifdef DEBUG
276  fprintf(stderr, "Error sending SessSetupAndTCon request\n");
277 #endif
278 
279  RFCNB_Free_Pkt(pkt);
280  free(tree);
282  return(NULL);
283 
284  }
285 
286  /* Now get the response ... */
287 
288  if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
289 
290 #ifdef DEBUG
291  fprintf(stderr, "Error receiving response to SessSetupAndTCon\n");
292 #endif
293 
294  RFCNB_Free_Pkt(pkt);
295  free(tree);
297  return(NULL);
298 
299  }
300 
301  /* Check out the response type ... */
302 
303  if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */
304 
305 #ifdef DEBUG
306  fprintf(stderr, "SMB_SessSetupAndTCon failed with errorclass = %i, Error Code = %i\n",
309 #endif
310 
311  /* Note, here, that we have not properly handled the error processing */
312  /* and so we cannot tell how much of our request crapped out */
313 
315  free(tree);
316  RFCNB_Free_Pkt(pkt);
318  return(NULL);
319 
320  }
321 
322 #ifdef DEBUG
323  fprintf(stderr, "SessSetupAndX response. Action = %i\n",
325 #endif
326 
327  /* Now pick up the UID for future reference ... */
328 
329  Con_Handle -> uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset);
330 
331  /* And pick up the TID as well */
332 
333  tree -> tid = SVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset);
334 
335  tree -> mbs = Con_Handle -> max_xmit;
336 
337  /* Link the tree into the list in con */
338 
339  if (Con_Handle -> first_tree == NULL) {
340 
341  Con_Handle -> first_tree == tree;
342  Con_Handle -> last_tree == tree;
343 
344  } else {
345 
346  Con_Handle -> last_tree -> next = tree;
347  tree -> prev = Con_Handle -> last_tree;
348  Con_Handle -> last_tree = tree;
349 
350  }
351 
352  RFCNB_Free_Pkt(pkt);
353 
354  return(tree);
355 
356 }
357 
358 /* Logon and TCon and Open to a file on the server, but we need to pass */
359 /* back a file pointer, so we better have one in the parameter list */
360 
361 int SMB_Logon_TCon_Open(SMB_Handle_Type Con_Handle, char *UserName,
362  char *PassWord,
363  char *service,
364  char *service_type,
365  SMB_Tree_Handle *Tree_Handle,
366  char *filename,
367  WORD mode,
368  WORD search,
369  SMB_File **File_Handle)
370 
371 {
372  struct RFCNB_Pkt *pkt;
373  int param_len, i, pkt_len, tcon_len, tcon_param_len, open_len,
374  open_param_len, header_len;
375  struct SMB_File_Def *file_tmp;
377  char *p, *AndXCom;
378 
379  /* First, we need a tree STRUCTURE as we are going to tree connect */
380 
381  tree = (SMB_Tree_Handle)malloc(sizeof(struct SMB_Tree_Structure));
382 
383  if (tree == NULL) {
384 
386  return(SMBlibE_BAD);
387 
388  } else {
389 
390  tree -> con = Con_Handle;
391  tree -> next = tree -> prev = NULL;
392 
393  }
394 
395  /* Next, we need a file handle as we are going to pass one back ... */
396  /* Hmm, there is a bug here ... We should check on File_Handle ... */
397 
398  if ((file_tmp = (SMB_File *)malloc(sizeof(SMB_File))) == NULL) {
399 
400 #ifdef DEBUG
401  fprintf(stderr, "Could not allocate file handle space ...");
402 #endif
403 
405  free(tree);
406  return(SMBlibE_BAD);
407 
408  }
409 
410  /* Next we need a packet etc ... but we need to know what protocol has */
411  /* been negotiated to figure out if we can do it and what SMB format to */
412  /* use ... */
413 
414  /* Since we are going to do a LogonAndX with a TCon as the second command*/
415  /* We need the packet size correct. So TCon starts at wct field */
416 
417  if (Con_Handle -> protocol < SMB_P_LanMan1) {
418 
419  free(tree);
420  free(file_tmp);
422  return(SMBlibE_BAD);
423 
424  }
425 
426  /* Now build the correct structure */
427 
428  /* We send a null password in the TconAndX ... */
429 
430  tcon_len = SMB_tconx_len - SMB_hdr_wct_offset;
431  tcon_param_len = strlen(service) + 1 + strlen(service_type) + 1;
432 
433  open_len = SMB_openx_len - SMB_hdr_wct_offset;
434  open_param_len = 1 + strlen(filename) + 1; /* AsciiID + null */
435 
436  if (Con_Handle -> protocol < SMB_P_NT1) {
437 
438  /* We don't do encrypted passwords yet */
439 
440  param_len = strlen(UserName) + 1 + strlen(PassWord) + 1 +
441  strlen(Con_Handle -> PDomain) + 1 +
442  strlen(Con_Handle -> OSName) + 1;
443 
444  header_len = SMB_ssetpLM_len + param_len;
445 
446  pkt_len = header_len + tcon_len + tcon_param_len +
447  open_len + open_param_len;
448 
449  pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len);
450 
451  if (pkt == NULL) {
452 
454  free(tree);
455  free(file_tmp);
456  return(SMBlibE_BAD); /* Should handle the error */
457 
458  }
459 
460  memset(SMB_Hdr(pkt), 0, SMB_ssetpLM_len);
461  SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
463  SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid);
464  SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
465  SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid);
466  SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, 0);
467  *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 10;
468  *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = SMBtconX;
469  SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, SMB_ssetpLM_len + param_len);
470 
473  SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_vcn_offset, Con_Handle -> pid);
475  SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_pwl_offset, strlen(PassWord) + 1);
477  SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_bcc_offset, param_len);
478 
479  /* Now copy the param strings in with the right stuff */
480 
481  p = (char *)(SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset);
482 
483  /* Copy in password, then the rest. Password has no null at end */
484 
485  strcpy(p, PassWord);
486 
487  p = p + strlen(PassWord) + 1;
488 
489  strcpy(p, UserName);
490  p = p + strlen(UserName);
491  *p = 0;
492 
493  p = p + 1;
494 
495  strcpy(p, Con_Handle -> PDomain);
496  p = p + strlen(Con_Handle -> PDomain);
497  *p = 0;
498  p = p + 1;
499 
500  strcpy(p, Con_Handle -> OSName);
501  p = p + strlen(Con_Handle -> OSName);
502  *p = 0;
503 
504  AndXCom = SMB_Hdr(pkt) + SMB_ssetpLM_len + param_len - SMB_hdr_wct_offset;
505 
506  } else {
507 
508  /* We don't admit to UNICODE support ... */
509 
510  param_len = strlen(UserName) + 1 + strlen(PassWord) +
511  strlen(Con_Handle -> PDomain) + 1 +
512  strlen(Con_Handle -> OSName) + 1 +
513  strlen(Con_Handle -> LMType) + 1;
514 
515  header_len = SMB_ssetpNTLM_len + param_len;
516 
517  pkt_len = header_len + tcon_len + tcon_param_len +
518  open_len + open_param_len;
519 
520  pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len);
521 
522  if (pkt == NULL) {
523 
525  free(tree);
526  free(file_tmp); /* Should only do if we created one ... */
527  return(-1); /* Should handle the error */
528 
529  }
530 
531  memset(SMB_Hdr(pkt), 0, SMB_ssetpNTLM_len);
532  SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
534  SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid);
535  SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
536  SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid);
537  SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, 0);
538  *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13;
539  *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = SMBtconX;
541 
546  SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cipl_offset, strlen(PassWord));
550  SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_bcc_offset, param_len);
551 
552  /* Now copy the param strings in with the right stuff */
553 
554  p = (char *)(SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset);
555 
556  /* Copy in password, then the rest. Password has no null at end */
557 
558  strcpy(p, PassWord);
559 
560  p = p + strlen(PassWord);
561 
562  strcpy(p, UserName);
563  p = p + strlen(UserName);
564  *p = 0;
565 
566  p = p + 1;
567 
568  strcpy(p, Con_Handle -> PDomain);
569  p = p + strlen(Con_Handle -> PDomain);
570  *p = 0;
571  p = p + 1;
572 
573  strcpy(p, Con_Handle -> OSName);
574  p = p + strlen(Con_Handle -> OSName);
575  *p = 0;
576  p = p + 1;
577 
578  strcpy(p, Con_Handle -> LMType);
579  p = p + strlen(Con_Handle -> LMType);
580  *p = 0;
581 
582  /* Now set up the TCON Part ... from WCT, make up a pointer that will
583  help us ... */
584 
585  AndXCom = SMB_Hdr(pkt) + SMB_ssetpNTLM_len + param_len - SMB_hdr_wct_offset;
586 
587  }
588 
589  *(AndXCom + SMB_hdr_wct_offset) = 4;
590  *(AndXCom + SMB_tconx_axc_offset) = SMBopenX;
591  SSVAL(AndXCom, SMB_tconx_axo_offset, (header_len +
592  tcon_len + tcon_param_len));
593  SSVAL(AndXCom, SMB_tconx_flg_offset, 0); /* Don't disconnect TID */
594  SSVAL(AndXCom, SMB_tconx_pwl_offset, 0); /* No password */
595  SSVAL(AndXCom, SMB_tconx_bcc_offset, tcon_param_len);
596 
597  p = (char *)(AndXCom + SMB_tconx_buf_offset);
598 
599  /* *p = 0;
600  p = p + 1; */
601  strcpy(p, service);
602  p = p + strlen(service) + 1;
603  strcpy(p, service_type);
604 
605  /* Now the open bit ... */
606 
607  AndXCom = AndXCom + tcon_len + tcon_param_len; /* Should get us there */
608 
609  *(AndXCom + SMB_hdr_wct_offset) = 15;
610  *(AndXCom + SMB_openx_axc_offset) = 0xFF;
611  *(AndXCom + SMB_openx_axr_offset) = 0;
612  SSVAL(AndXCom, SMB_openx_axo_offset, 0);
613  SSVAL(AndXCom, SMB_openx_flg_offset, 0);
614  SSVAL(AndXCom, SMB_openx_mod_offset, mode);
615  SSVAL(AndXCom, SMB_openx_atr_offset, search);
616  SSVAL(AndXCom, SMB_openx_fat_offset, 0);
617  SIVAL(AndXCom, SMB_openx_tim_offset, 0);
618  SSVAL(AndXCom, SMB_openx_ofn_offset, 0x0011); /* Create or open */
619  SIVAL(AndXCom, SMB_openx_als_offset, 0);
620  SSVAL(AndXCom, SMB_openx_bcc_offset, open_param_len);
621 
622  p = (char *)(AndXCom + SMB_openx_buf_offset);
623 
624  /* *p = SMBasciiID; */
625  strcpy(p, filename);
626 
627  /* Now send it and get a response */
628 
629  if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
630 
631 #ifdef DEBUG
632  fprintf(stderr, "Error sending SessSetupAndTCon request\n");
633 #endif
634 
635  RFCNB_Free_Pkt(pkt);
636  free(tree);
637  free(file_tmp);
639  return(SMBlibE_BAD);
640 
641  }
642 
643  /* Now get the response ... */
644 
645  if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
646 
647 #ifdef DEBUG
648  fprintf(stderr, "Error receiving response to SessSetupAndTCon\n");
649 #endif
650 
651  RFCNB_Free_Pkt(pkt);
652  free(tree);
653  free(file_tmp);
655  return(SMBlibE_BAD);
656 
657  }
658 
659  /* Check out the response type ... */
660 
661  if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */
662 
663 #ifdef DEBUG
664  fprintf(stderr, "SMB_SessSetupAndTCon failed with errorclass = %i, Error Code = %i\n",
667 #endif
668 
669  /* Note, here, that we have not properly handled the error processing */
670  /* and so we cannot tell how much of our request crapped out */
671 
673  RFCNB_Free_Pkt(pkt);
674  free(tree);
675  free(file_tmp);
677  return(SMBlibE_BAD);
678 
679  }
680 
681 #ifdef DEBUG
682  fprintf(stderr, "SessSetupAndX response. Action = %i\n",
684 #endif
685 
686  /* Now pick up the UID for future reference ... */
687 
688  Con_Handle -> uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset);
689 
690  /* And pick up the TID as well */
691 
692  tree -> tid = SVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset);
693  tree -> mbs = Con_Handle -> max_xmit; /* We need this */
694 
695 #ifdef DEBUG
696  fprintf(stderr, "mbs=%i\n", tree -> mbs);
697 #endif
698 
699  /* Now we populate the file hanble and pass it back ... */
700 
701  strncpy(file_tmp -> filename, filename, sizeof(file_tmp -> filename) - 1);
702  file_tmp -> tree = tree;
703 
704  /* Pick up a pointer to the right part ... */
705 
706  AndXCom = SMB_Hdr(pkt) + SVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset) -
708 
709  /* Now skip the response to the TConX */
710 
711  AndXCom = SMB_Hdr(pkt) + SVAL(AndXCom, SMB_tconxr_axo_offset) -
713 
714 #ifdef DEBUG
715  fprintf(stderr, "Word Params = %x, AXO = %x\n",
716  CVAL(AndXCom, SMB_hdr_wct_offset),
717  SVAL(AndXCom, SMB_openxr_axo_offset));
718 #endif
719 
720  /* Now pick up the things from the openX response that we need */
721 
722  file_tmp -> fid = SVAL(AndXCom, SMB_openxr_fid_offset);
723  file_tmp -> lastmod = IVAL(AndXCom, SMB_openxr_tim_offset);
724  file_tmp -> size = IVAL(AndXCom, SMB_openxr_fsz_offset);
725  file_tmp -> access = SVAL(AndXCom, SMB_openxr_acc_offset);
726  file_tmp -> fileloc = 0;
727 
728  *File_Handle = file_tmp;
729 
730  /* Now link the tree into the right place ... */
731 
732  if (Con_Handle -> first_tree == NULL) {
733 
734  Con_Handle -> first_tree == tree;
735  Con_Handle -> last_tree == tree;
736 
737  } else {
738 
739  Con_Handle -> last_tree -> next = tree;
740  tree -> prev = Con_Handle -> last_tree;
741  Con_Handle -> last_tree = tree;
742 
743  }
744 
745  RFCNB_Free_Pkt(pkt);
746 
747  *Tree_Handle = tree;
748 
749  return(0);
750 
751 }
752 
#define SMB_hdr_err_offset
Definition: smblib-priv.h:181
#define IVAL(buf, pos)
Definition: byteorder.h:58
#define SMB_hdr_idf_offset
Definition: smblib-priv.h:177
#define SMB_hdr_uid_offset
Definition: smblib-priv.h:195
#define SMB_ssetpNTLM_cipl_offset
Definition: smblib-priv.h:397
#define SMB_openx_als_offset
Definition: smblib-priv.h:304
#define SMB_ssetpNTLM_buf_offset
Definition: smblib-priv.h:403
#define SMB_openxr_fid_offset
Definition: smblib-priv.h:321
#define SMB_hdr_mid_offset
Definition: smblib-priv.h:196
int SMB_Logon_TCon_Open(SMB_Handle_Type Con_Handle, char *UserName, char *PassWord, char *service, char *service_type, SMB_Tree_Handle *Tree_Handle, char *filename, WORD mode, WORD search, SMB_File **File_Handle)
Definition: exper.c:361
int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length)
Definition: session.c:235
#define SMB_hdr_rcls_offset
Definition: smblib-priv.h:179
unsigned short WORD
Definition: smblib-priv.h:145
#define SMB_openx_buf_offset
Definition: smblib-priv.h:307
int SMBlib_errno
Definition: smblib.c:35
#define SMB_hdr_axc_offset
Definition: smblib-priv.h:201
#define SMB_openx_flg_offset
Definition: smblib-priv.h:296
#define SMB_tconx_pwl_offset
Definition: smblib-priv.h:268
#define SMB_ssetpLM_mbs_offset
Definition: smblib-priv.h:382
#define SMB_ssetpLM_buf_offset
Definition: smblib-priv.h:390
#define SMB_tconx_axc_offset
Definition: smblib-priv.h:264
struct SMB_Tree_Structure * SMB_Tree_Handle
static pid_t pid
Definition: IcmpSquid.cc:34
int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length)
Definition: session.c:183
#define SMB_openx_axo_offset
Definition: smblib-priv.h:295
#define SMB_openx_tim_offset
Definition: smblib-priv.h:302
#define SSVAL(buf, pos, val)
Definition: byteorder.h:63
int size
Definition: ModDevPoll.cc:69
#define NULL
Definition: types.h:145
#define SMBopenX
Definition: smblib-priv.h:119
#define SMB_hdr_axo_offset
Definition: smblib-priv.h:203
#define SMB_ssetpNTLM_vcn_offset
Definition: smblib-priv.h:395
#define SMB_tconx_len
Definition: smblib-priv.h:271
#define SMBtconX
Definition: smblib-priv.h:123
#define SMB_ssetpLM_mmc_offset
Definition: smblib-priv.h:383
#define SIVAL(buf, pos, val)
Definition: byteorder.h:64
#define SMB_openx_len
Definition: smblib-priv.h:308
#define SMB_ssetpLM_snk_offset
Definition: smblib-priv.h:385
#define SMB_ssetpNTLM_mbs_offset
Definition: smblib-priv.h:392
#define CVAL(buf, pos)
Definition: byteorder.h:52
#define SMB_ssetpLM_len
Definition: smblib-priv.h:389
#define SMB_openxr_tim_offset
Definition: smblib-priv.h:323
#define SMB_ssetpNTLM_bcc_offset
Definition: smblib-priv.h:401
#define SMB_hdr_wct_offset
Definition: smblib-priv.h:197
#define SMB_Hdr(p)
Definition: smblib-priv.h:163
#define SMBLIB_MAX_XMIT
Definition: smblib-priv.h:524
#define SMB_tconx_buf_offset
Definition: smblib-priv.h:270
#define SMB_openxr_fsz_offset
Definition: smblib-priv.h:324
SMB_Tree_Handle tree
Definition: smblib-priv.h:533
#define SMB_openx_axc_offset
Definition: smblib-priv.h:293
#define SMB_ssetpr_act_offset
Definition: smblib-priv.h:406
#define SMB_openxr_axo_offset
Definition: smblib-priv.h:320
#define SMB_hdr_pid_offset
Definition: smblib-priv.h:194
SMB_Tree_Handle SMB_Logon_And_TCon(SMB_Handle_Type Con_Handle, SMB_Tree_Handle Tree_Handle, char *UserName, char *PassWord, char *service, char *service_type)
Definition: exper.c:45
#define SMB_hdr_com_offset
Definition: smblib-priv.h:178
#define SMB_openxr_acc_offset
Definition: smblib-priv.h:325
#define SMB_ssetpLM_bcc_offset
Definition: smblib-priv.h:388
#define SMB_P_NT1
#define SMB_openx_atr_offset
Definition: smblib-priv.h:300
#define SMB_hdr_tid_offset
Definition: smblib-priv.h:193
#define SMB_ssetpNTLM_len
Definition: smblib-priv.h:402
#define SMB_openx_mod_offset
Definition: smblib-priv.h:299
#define SMB_ssetpLM_pwl_offset
Definition: smblib-priv.h:386
#define SMB_openx_ofn_offset
Definition: smblib-priv.h:303
#define SMB_tconx_axo_offset
Definition: smblib-priv.h:266
int SMBlib_SMB_Error
Definition: smblib.c:36
#define SMBC_SUCCESS
Definition: smblib-common.h:52
#define SMB_ssetpLM_res_offset
Definition: smblib-priv.h:387
#define SMB_ssetpNTLM_cap_offset
Definition: smblib-priv.h:400
#define SMBlibE_Remote
#define SMBlibE_ProtLow
void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt)
Definition: rfcnb-util.c:231
#define SMBsesssetupX
Definition: smblib-priv.h:122
#define SMBlibE_SendFailed
#define SVAL(buf, pos)
Definition: byteorder.h:57
#define SMB_ssetpLM_vcn_offset
Definition: smblib-priv.h:384
#define SMB_openx_bcc_offset
Definition: smblib-priv.h:306
#define SMB_openx_fat_offset
Definition: smblib-priv.h:301
#define SMB_ssetpNTLM_cspl_offset
Definition: smblib-priv.h:398
#define SMB_ssetpNTLM_res_offset
Definition: smblib-priv.h:399
#define SMB_DEF_IDF
Definition: smblib-priv.h:50
#define SMB_ssetpNTLM_mmc_offset
Definition: smblib-priv.h:394
#define SMB_tconxr_axo_offset
Definition: smblib-priv.h:275
#define SMB_openx_axr_offset
Definition: smblib-priv.h:294
#define SMBlibE_BAD
struct RFCNB_Pkt * next
Definition: rfcnb-common.h:46
#define SMB_P_LanMan1
#define SMBlibE_RecvFailed
#define SMB_tconx_flg_offset
Definition: smblib-priv.h:267
char filename[256]
Definition: smblib-priv.h:534
#define SMB_ssetpNTLM_snk_offset
Definition: smblib-priv.h:396
struct RFCNB_Pkt * RFCNB_Alloc_Pkt(int n)
Definition: rfcnb-util.c:202
#define SMBlibE_NoSpace
#define SMB_tconx_bcc_offset
Definition: smblib-priv.h:269

 

Introduction

Documentation

Support

Miscellaneous