2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 /* UNIX SMBlib NetBIOS implementation
12 SMBlib Utility Routines
14 Copyright (C) Richard Sharpe 1996
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.
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.
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.
34 #include "rfcnb/rfcnb.h"
35 #include "smblib/smblib-priv.h"
36 #include "smblib/smblib.h"
42 int SMB_Types
[] = {SMB_P_Core
,
58 char *SMB_DOSTimToStr(int DOS_time
);
59 char *SMB_AtrToStr(int attribs
, BOOL verbose
);
60 int SMB_Get_Tree_MBS(SMB_Tree_Handle tree
);
61 int SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle
);
62 int SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle
);
63 #endif /* UNDEFINED */
64 int SMB_Get_Protocol(SMB_Handle_Type Con_Handle
);
65 int SMB_Figure_Protocol(const char *dialects
[], int prot_index
);
66 int SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle
, BOOL discard
);
69 /* Print out an SMB pkt in all its gory detail ... */
71 void SMB_Print_Pkt(FILE fd
, RFCNB_Pkt
*pkt
, BOOL command
, int Offset
, int Len
)
75 /* Well, just how do we do this ... print it I suppose */
77 /* Print out the SMB header ... */
79 /* Print the command */
81 /* Print the other bits in the header */
88 /* Convert a DOS Date_Time to a local host type date time for printing */
91 char *SMB_DOSTimToStr(int DOS_time
)
94 static char SMB_Time_Temp
[48];
95 int DOS_sec
, DOS_min
, DOS_hour
, DOS_day
, DOS_month
, DOS_year
;
99 DOS_sec
= (DOS_time
& 0x001F) * 2;
100 DOS_min
= (DOS_time
& 0x07E0) >> 5;
101 DOS_hour
= ((DOS_time
& 0xF800) >> 11);
103 DOS_day
= (DOS_time
& 0x001F0000) >> 16;
104 DOS_month
= (DOS_time
& 0x01E00000) >> 21;
105 DOS_year
= ((DOS_time
& 0xFE000000) >> 25) + 80;
107 snprintf(SMB_Time_Temp
, 48, "%2d/%02d/%2d %2d:%02d:%02d", DOS_day
, DOS_month
,
108 DOS_year
, DOS_hour
, DOS_min
, DOS_sec
);
110 return(SMB_Time_Temp
);
114 /* Convert an attribute byte/word etc to a string ... We return a pointer
115 to a static string which we guarantee is long enough. If verbose is
116 true, we print out long form of strings ... */
118 char *SMB_AtrToStr(int attribs
, BOOL verbose
)
121 static char SMB_Attrib_Temp
[128];
123 SMB_Attrib_Temp
[0] = 0;
125 if (attribs
& SMB_FA_ROF
)
126 strcat(SMB_Attrib_Temp
, (verbose
?"Read Only ":"R"));
128 if (attribs
& SMB_FA_HID
)
129 strcat(SMB_Attrib_Temp
, (verbose
?"Hidden ":"H"));
131 if (attribs
& SMB_FA_SYS
)
132 strcat(SMB_Attrib_Temp
, (verbose
?"System ":"S"));
134 if (attribs
& SMB_FA_VOL
)
135 strcat(SMB_Attrib_Temp
, (verbose
?"Volume ":"V"));
137 if (attribs
& SMB_FA_DIR
)
138 strcat(SMB_Attrib_Temp
, (verbose
?"Directory ":"D"));
140 if (attribs
& SMB_FA_ARC
)
141 strcat(SMB_Attrib_Temp
, (verbose
?"Archive ":"A"));
143 return(SMB_Attrib_Temp
);
147 /* Pick up the Max Buffer Size from the Tree Structure ... */
149 int SMB_Get_Tree_MBS(SMB_Tree_Handle tree
)
159 /* Pick up the Max buffer size */
161 int SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle
)
164 if (Con_Handle
!= NULL
) {
165 return(Con_Handle
-> max_xmit
);
171 /* Pickup the protocol index from the connection structure */
173 int SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle
)
176 if (Con_Handle
!= NULL
) {
177 return(Con_Handle
-> prot_IDX
);
179 return(0xFFFF); /* Invalid protocol */
183 #endif /* UNDEFINED */
185 /* Pick up the protocol from the connection structure */
187 int SMB_Get_Protocol(SMB_Handle_Type Con_Handle
)
190 if (Con_Handle
!= NULL
) {
191 return(Con_Handle
-> protocol
);
193 return(0xFFFF); /* Invalid protocol */
198 /* Figure out what protocol was accepted, given the list of dialect strings */
199 /* We offered, and the index back from the server. We allow for a user */
200 /* supplied list, and assume that it is a subset of our list */
202 int SMB_Figure_Protocol(const char *dialects
[], int prot_index
)
207 if (dialects
== SMB_Prots
) { /* The jobs is easy, just index into table */
209 return(SMB_Types
[prot_index
]);
210 } else { /* Search through SMB_Prots looking for a match */
212 for (i
= 0; SMB_Prots
[i
] != NULL
; i
++) {
214 if (strcmp(dialects
[prot_index
], SMB_Prots
[i
]) == 0) { /* A match */
216 return(SMB_Types
[i
]);
222 /* If we got here, then we are in trouble, because the protocol was not */
223 /* One we understand ... */
225 return(SMB_P_Unknown
);
231 /* Negotiate the protocol we will use from the list passed in Prots */
232 /* we return the index of the accepted protocol in NegProt, -1 indicates */
233 /* none acceptible, and our return value is 0 if ok, <0 if problems */
235 int SMB_Negotiate(SMB_Handle_Type Con_Handle
, const char *Prots
[])
238 // struct SMB_Neg_Prot_Def *prot_pkt;
239 // struct SMB_Neg_Prot_Resp_Def *resp_pkt;
240 struct RFCNB_Pkt
*pkt
;
241 int prots_len
, i
, pkt_len
, prot
, alloc_len
;
244 /* Figure out how long the prot list will be and allocate space for it */
248 for (i
= 0; Prots
[i
] != NULL
; i
++) {
250 prots_len
= prots_len
+ strlen(Prots
[i
]) + 2; /* Account for null etc */
254 /* The -1 accounts for the one byte smb_buf we have because some systems */
255 /* don't like char msg_buf[] */
257 pkt_len
= SMB_negp_len
+ prots_len
;
259 /* Make sure that the pkt len is long enough for the max response ... */
260 /* Which is a problem, because the encryption key len eec may be long */
262 if (pkt_len
< (SMB_hdr_wct_offset
+ (19 * 2) + 40)) {
264 alloc_len
= SMB_hdr_wct_offset
+ (19 * 2) + 40;
272 pkt
= (struct RFCNB_Pkt
*)RFCNB_Alloc_Pkt(alloc_len
);
276 SMBlib_errno
= SMBlibE_NoSpace
;
281 /* Now plug in the bits we need */
283 memset(SMB_Hdr(pkt
), 0, SMB_negp_len
);
284 SIVAL(SMB_Hdr(pkt
), SMB_hdr_idf_offset
, SMB_DEF_IDF
); /* Plunk in IDF */
285 *(SMB_Hdr(pkt
) + SMB_hdr_com_offset
) = SMBnegprot
;
286 SSVAL(SMB_Hdr(pkt
), SMB_hdr_pid_offset
, Con_Handle
-> pid
);
287 SSVAL(SMB_Hdr(pkt
), SMB_hdr_tid_offset
, 0);
288 SSVAL(SMB_Hdr(pkt
), SMB_hdr_mid_offset
, Con_Handle
-> mid
);
289 SSVAL(SMB_Hdr(pkt
), SMB_hdr_uid_offset
, Con_Handle
-> uid
);
290 *(SMB_Hdr(pkt
) + SMB_hdr_wct_offset
) = 0;
292 SSVAL(SMB_Hdr(pkt
), SMB_negp_bcc_offset
, prots_len
);
294 /* Now copy the prot strings in with the right stuff */
296 p
= (char *)(SMB_Hdr(pkt
) + SMB_negp_buf_offset
);
298 for (i
= 0; Prots
[i
] != NULL
; i
++) {
301 strcpy(p
+ 1, Prots
[i
]);
302 p
= p
+ strlen(Prots
[i
]) + 2; /* Adjust len of p for null plus dialectID */
306 /* Now send the packet and sit back ... */
308 if (RFCNB_Send(Con_Handle
-> Trans_Connect
, pkt
, pkt_len
) < 0) {
311 fprintf(stderr
, "Error sending negotiate protocol\n");
315 SMBlib_errno
= -SMBlibE_SendFailed
; /* Failed, check lower layer errno */
320 /* Now get the response ... */
322 if (RFCNB_Recv(Con_Handle
-> Trans_Connect
, pkt
, alloc_len
) < 0) {
325 fprintf(stderr
, "Error receiving response to negotiate\n");
329 SMBlib_errno
= -SMBlibE_RecvFailed
; /* Failed, check lower layer errno */
334 if (CVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
) != SMBC_SUCCESS
) { /* Process error */
337 fprintf(stderr
, "SMB_Negotiate failed with errorclass = %i, Error Code = %i\n",
338 CVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
),
339 SVAL(SMB_Hdr(pkt
), SMB_hdr_err_offset
));
342 SMBlib_SMB_Error
= IVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
);
344 SMBlib_errno
= SMBlibE_Remote
;
349 if (SVAL(SMB_Hdr(pkt
), SMB_negrCP_idx_offset
) == 0xFFFF) {
352 fprintf(stderr
, "None of our protocols was accepted ... ");
356 SMBlib_errno
= SMBlibE_NegNoProt
;
361 /* Now, unpack the info from the response, if any and evaluate the proto */
362 /* selected. We must make sure it is one we like ... */
364 Con_Handle
-> prot_IDX
= prot
= SVAL(SMB_Hdr(pkt
), SMB_negrCP_idx_offset
);
365 Con_Handle
-> protocol
= SMB_Figure_Protocol(Prots
, prot
);
367 if (Con_Handle
-> protocol
== SMB_P_Unknown
) { /* No good ... */
370 SMBlib_errno
= SMBlibE_ProtUnknown
;
375 switch (CVAL(SMB_Hdr(pkt
), SMB_hdr_wct_offset
)) {
377 case 0x01: /* No more info ... */
381 case 13: /* Up to and including LanMan 2.1 */
383 Con_Handle
-> Security
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_sec_offset
);
384 Con_Handle
-> encrypt_passwords
= ((Con_Handle
-> Security
& SMB_sec_encrypt_mask
) != 0x00);
385 Con_Handle
-> Security
= Con_Handle
-> Security
& SMB_sec_user_mask
;
387 Con_Handle
-> max_xmit
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_mbs_offset
);
388 Con_Handle
-> MaxMPX
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_mmc_offset
);
389 Con_Handle
-> MaxVC
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_mnv_offset
);
390 Con_Handle
-> Raw_Support
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_rm_offset
);
391 Con_Handle
-> SessionKey
= IVAL(SMB_Hdr(pkt
), SMB_negrLM_sk_offset
);
392 Con_Handle
-> SvrTZ
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_stz_offset
);
393 Con_Handle
-> Encrypt_Key_Len
= SVAL(SMB_Hdr(pkt
), SMB_negrLM_ekl_offset
);
395 p
= (SMB_Hdr(pkt
) + SMB_negrLM_buf_offset
);
396 memcpy(Con_Handle
->Encrypt_Key
, p
, 8);
398 p
= (SMB_Hdr(pkt
) + SMB_negrLM_buf_offset
+ Con_Handle
-> Encrypt_Key_Len
);
400 strncpy(p
, Con_Handle
-> Svr_PDom
, sizeof(Con_Handle
-> Svr_PDom
) - 1);
404 case 17: /* NT LM 0.12 and LN LM 1.0 */
406 Con_Handle
-> Security
= SVAL(SMB_Hdr(pkt
), SMB_negrNTLM_sec_offset
);
407 Con_Handle
-> encrypt_passwords
= ((Con_Handle
-> Security
& SMB_sec_encrypt_mask
) != 0x00);
408 Con_Handle
-> Security
= Con_Handle
-> Security
& SMB_sec_user_mask
;
410 Con_Handle
-> max_xmit
= IVAL(SMB_Hdr(pkt
), SMB_negrNTLM_mbs_offset
);
411 Con_Handle
-> MaxMPX
= SVAL(SMB_Hdr(pkt
), SMB_negrNTLM_mmc_offset
);
412 Con_Handle
-> MaxVC
= SVAL(SMB_Hdr(pkt
), SMB_negrNTLM_mnv_offset
);
413 Con_Handle
-> MaxRaw
= IVAL(SMB_Hdr(pkt
), SMB_negrNTLM_mrs_offset
);
414 Con_Handle
-> SessionKey
= IVAL(SMB_Hdr(pkt
), SMB_negrNTLM_sk_offset
);
415 Con_Handle
-> SvrTZ
= SVAL(SMB_Hdr(pkt
), SMB_negrNTLM_stz_offset
);
416 Con_Handle
-> Encrypt_Key_Len
= CVAL(SMB_Hdr(pkt
), SMB_negrNTLM_ekl_offset
);
418 p
= (SMB_Hdr(pkt
) + SMB_negrNTLM_buf_offset
);
419 memcpy(Con_Handle
->Encrypt_Key
, p
, 8);
421 p
= (SMB_Hdr(pkt
) + SMB_negrLM_buf_offset
+ Con_Handle
-> Encrypt_Key_Len
);
423 strncpy(p
, Con_Handle
-> Svr_PDom
, sizeof(Con_Handle
-> Svr_PDom
) - 1);
430 fprintf(stderr
, "Unknown NegProt response format ... Ignored\n");
431 fprintf(stderr
, " wct = %i\n", CVAL(SMB_Hdr(pkt
), SMB_hdr_wct_offset
));
438 fprintf(stderr
, "Protocol selected is: %i:%s\n", prot
, Prots
[prot
]);
446 /* Get our hostname */
448 void SMB_Get_My_Name(char *name
, int len
)
451 if (gethostname(name
, len
) < 0) { /* Error getting name */
453 strncpy(name
, "unknown", len
);
455 /* Should check the error */
458 fprintf(stderr
, "gethostname in SMB_Get_My_Name returned error:");
464 /* only keep the portion up to the first "." */
465 if (NULL
!= (address
= strchr(name
, '.'))) {
466 *address
= '\0'; /* truncate at first '.' */
471 /* Send a TCON to the remote server ... */
473 SMB_Tree_Handle
SMB_TreeConnect(SMB_Handle_Type Con_Handle
,
474 SMB_Tree_Handle Tree_Handle
,
476 const char *password
,
480 struct RFCNB_Pkt
*pkt
;
481 int param_len
, pkt_len
;
483 SMB_Tree_Handle tree
;
485 /* Figure out how much space is needed for path, password, dev ... */
487 if ((path
== NULL
) | (password
== NULL
) | (device
== NULL
)) {
490 fprintf(stderr
, "Bad parameter passed to SMB_TreeConnect\n");
493 SMBlib_errno
= SMBlibE_BadParam
;
498 /* The + 2 is because of the \0 and the marker ... */
500 param_len
= strlen(path
) + 2 + strlen(password
) + 2 + strlen(device
) + 2;
502 /* The -1 accounts for the one byte smb_buf we have because some systems */
503 /* don't like char msg_buf[] */
505 pkt_len
= SMB_tcon_len
+ param_len
;
507 pkt
= (struct RFCNB_Pkt
*)RFCNB_Alloc_Pkt(pkt_len
);
511 SMBlib_errno
= SMBlibE_NoSpace
;
512 return(NULL
); /* Should handle the error */
516 /* Now allocate a tree for this to go into ... */
518 if (Tree_Handle
== NULL
) {
520 tree
= (SMB_Tree_Handle
)malloc(sizeof(struct SMB_Tree_Structure
));
525 SMBlib_errno
= SMBlibE_NoSpace
;
535 tree
-> next
= tree
-> prev
= NULL
;
536 tree
-> con
= Con_Handle
;
537 strncpy(tree
-> path
, path
, sizeof(tree
-> path
));
538 strncpy(tree
-> device_type
, device
, sizeof(tree
-> device_type
));
540 /* Now plug in the values ... */
542 memset(SMB_Hdr(pkt
), 0, SMB_tcon_len
);
543 SIVAL(SMB_Hdr(pkt
), SMB_hdr_idf_offset
, SMB_DEF_IDF
); /* Plunk in IDF */
544 *(SMB_Hdr(pkt
) + SMB_hdr_com_offset
) = SMBtcon
;
545 SSVAL(SMB_Hdr(pkt
), SMB_hdr_pid_offset
, Con_Handle
-> pid
);
546 SSVAL(SMB_Hdr(pkt
), SMB_hdr_tid_offset
, 0);
547 SSVAL(SMB_Hdr(pkt
), SMB_hdr_mid_offset
, Con_Handle
-> mid
);
548 SSVAL(SMB_Hdr(pkt
), SMB_hdr_uid_offset
, Con_Handle
-> uid
);
549 *(SMB_Hdr(pkt
) + SMB_hdr_wct_offset
) = 0;
551 SSVAL(SMB_Hdr(pkt
), SMB_tcon_bcc_offset
, param_len
);
553 /* Now copy the param strings in with the right stuff */
555 p
= (char *)(SMB_Hdr(pkt
) + SMB_tcon_buf_offset
);
558 p
= p
+ strlen(path
) + 2;
560 strcpy(p
+ 1, password
);
561 p
= p
+ strlen(password
) + 2;
563 strcpy(p
+ 1, device
);
565 /* Now send the packet and sit back ... */
567 if (RFCNB_Send(Con_Handle
-> Trans_Connect
, pkt
, pkt_len
) < 0) {
570 fprintf(stderr
, "Error sending TCon request\n");
573 if (Tree_Handle
== NULL
)
576 SMBlib_errno
= -SMBlibE_SendFailed
;
581 /* Now get the response ... */
583 if (RFCNB_Recv(Con_Handle
-> Trans_Connect
, pkt
, pkt_len
) < 0) {
586 fprintf(stderr
, "Error receiving response to TCon\n");
589 if (Tree_Handle
== NULL
)
592 SMBlib_errno
= -SMBlibE_RecvFailed
;
597 /* Check out the response type ... */
599 if (CVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
) != SMBC_SUCCESS
) { /* Process error */
602 fprintf(stderr
, "SMB_TCon failed with errorclass = %i, Error Code = %i\n",
603 CVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
),
604 SVAL(SMB_Hdr(pkt
), SMB_hdr_err_offset
));
607 if (Tree_Handle
== NULL
)
609 SMBlib_SMB_Error
= IVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
);
611 SMBlib_errno
= SMBlibE_Remote
;
616 tree
-> tid
= SVAL(SMB_Hdr(pkt
), SMB_tconr_tid_offset
);
617 tree
-> mbs
= SVAL(SMB_Hdr(pkt
), SMB_tconr_mbs_offset
);
620 fprintf(stderr
, "TConn succeeded, with TID=%i, Max Xmit=%i\n",
621 tree
-> tid
, tree
-> mbs
);
624 /* Now link the Tree to the Server Structure ... */
626 if (Con_Handle
-> first_tree
== NULL
) {
628 Con_Handle
-> first_tree
= tree
;
629 Con_Handle
-> last_tree
= tree
;
633 Con_Handle
-> last_tree
-> next
= tree
;
634 tree
-> prev
= Con_Handle
-> last_tree
;
635 Con_Handle
-> last_tree
= tree
;
644 int SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle
, BOOL discard
)
647 struct RFCNB_Pkt
*pkt
;
650 pkt_len
= SMB_tdis_len
;
652 pkt
= (struct RFCNB_Pkt
*)RFCNB_Alloc_Pkt(pkt_len
);
656 SMBlib_errno
= SMBlibE_NoSpace
;
657 return(SMBlibE_BAD
); /* Should handle the error */
661 /* Now plug in the values ... */
663 memset(SMB_Hdr(pkt
), 0, SMB_tdis_len
);
664 SIVAL(SMB_Hdr(pkt
), SMB_hdr_idf_offset
, SMB_DEF_IDF
); /* Plunk in IDF */
665 *(SMB_Hdr(pkt
) + SMB_hdr_com_offset
) = SMBtdis
;
666 SSVAL(SMB_Hdr(pkt
), SMB_hdr_pid_offset
, Tree_Handle
-> con
-> pid
);
667 SSVAL(SMB_Hdr(pkt
), SMB_hdr_mid_offset
, Tree_Handle
-> con
-> mid
);
668 SSVAL(SMB_Hdr(pkt
), SMB_hdr_uid_offset
, Tree_Handle
-> con
-> uid
);
669 *(SMB_Hdr(pkt
) + SMB_hdr_wct_offset
) = 0;
671 SSVAL(SMB_Hdr(pkt
), SMB_hdr_tid_offset
, Tree_Handle
-> tid
);
672 SSVAL(SMB_Hdr(pkt
), SMB_tcon_bcc_offset
, 0);
674 /* Now send the packet and sit back ... */
676 if (RFCNB_Send(Tree_Handle
-> con
-> Trans_Connect
, pkt
, pkt_len
) < 0) {
679 fprintf(stderr
, "Error sending TDis request\n");
683 SMBlib_errno
= -SMBlibE_SendFailed
;
688 /* Now get the response ... */
690 if (RFCNB_Recv(Tree_Handle
-> con
-> Trans_Connect
, pkt
, pkt_len
) < 0) {
693 fprintf(stderr
, "Error receiving response to TCon\n");
697 SMBlib_errno
= -SMBlibE_RecvFailed
;
702 /* Check out the response type ... */
704 if (CVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
) != SMBC_SUCCESS
) { /* Process error */
707 fprintf(stderr
, "SMB_TDis failed with errorclass = %i, Error Code = %i\n",
708 CVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
),
709 SVAL(SMB_Hdr(pkt
), SMB_hdr_err_offset
));
712 SMBlib_SMB_Error
= IVAL(SMB_Hdr(pkt
), SMB_hdr_rcls_offset
);
714 SMBlib_errno
= SMBlibE_Remote
;
719 Tree_Handle
-> tid
= 0xFFFF; /* Invalid TID */
720 Tree_Handle
-> mbs
= 0; /* Invalid */
724 fprintf(stderr
, "Tree disconnect successful ...\n");
728 /* What about the tree handle ? */
730 if (discard
== TRUE
) { /* Unlink it and free it ... */
732 if (Tree_Handle
-> next
== NULL
)
733 Tree_Handle
-> con
-> first_tree
= Tree_Handle
-> prev
;
735 Tree_Handle
-> next
-> prev
= Tree_Handle
-> prev
;
737 if (Tree_Handle
-> prev
== NULL
)
738 Tree_Handle
-> con
-> last_tree
= Tree_Handle
-> next
;
740 Tree_Handle
-> prev
-> next
= Tree_Handle
-> next
;
749 /* Pick up the last LMBlib error ... */
751 int SMB_Get_Last_Error()
755 return(SMBlib_errno
);
759 /* Pick up the last error returned in an SMB packet */
760 /* We will need macros to extract error class and error code */
762 int SMB_Get_Last_SMB_Err()
766 return(SMBlib_SMB_Error
);
770 /* Pick up the error message associated with an error from SMBlib */
772 /* Keep this table in sync with the message codes in smblib-common.h */
774 static const char *SMBlib_Error_Messages
[] = {
776 "Request completed successfully.",
777 "Server returned a non-zero SMB Error Class and Code.",
778 "A lower layer protocol error occurred.",
779 "Function not yet implemented.",
780 "The protocol negotiated does not support the request.",
781 "No space available for operation.",
782 "One or more bad parameters passed.",
783 "None of the protocols we offered were accepted.",
784 "The attempt to send an SMB request failed. See protocol error info.",
785 "The attempt to get an SMB response failed. See protocol error info.",
786 "The logon request failed, but you were logged in as guest.",
787 "The attempt to call the remote server failed. See protocol error info.",
788 "The protocol dialect specified in a NegProt and accepted by the server is unknown.",
789 /* This next one simplifies error handling */
790 "No such error code.",
794 void SMB_Get_Error_Msg(int msg
, char *msgbuf
, int len
)
801 SMBlib_Error_Messages
[msg
>SMBlibE_NoSuchMsg
?SMBlibE_NoSuchMsg
:msg
],
803 msgbuf
[len
- 1] = 0; /* Make sure it is a string */
804 } else { /* Add the lower layer message ... */
808 msg
= -msg
; /* Make it positive */
811 SMBlib_Error_Messages
[msg
>SMBlibE_NoSuchMsg
?SMBlibE_NoSuchMsg
:msg
],
814 msgbuf
[len
- 1] = 0; /* make sure it is a string */
816 if (strlen(msgbuf
) < len
) { /* If there is space, put rest in */
818 strncat(msgbuf
, "\n\t", len
- strlen(msgbuf
));
820 RFCNB_Get_Error(prot_msg
, sizeof(prot_msg
) - 1);
822 strncat(msgbuf
, prot_msg
, len
- strlen(msgbuf
));