58char *SMB_DOSTimToStr(
int DOS_time);
71void SMB_Print_Pkt(FILE fd,
RFCNB_Pkt *pkt,
BOOL command,
int Offset,
int Len)
91char *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);
121 static char SMB_Attrib_Temp[128];
123 SMB_Attrib_Temp[0] = 0;
126 strcat(SMB_Attrib_Temp, (
verbose?
"Read Only ":
"R"));
129 strcat(SMB_Attrib_Temp, (
verbose?
"Hidden ":
"H"));
132 strcat(SMB_Attrib_Temp, (
verbose?
"System ":
"S"));
135 strcat(SMB_Attrib_Temp, (
verbose?
"Volume ":
"V"));
138 strcat(SMB_Attrib_Temp, (
verbose?
"Directory ":
"D"));
141 strcat(SMB_Attrib_Temp, (
verbose?
"Archive ":
"A"));
143 return(SMB_Attrib_Temp);
164 if (Con_Handle !=
NULL) {
165 return(Con_Handle -> max_xmit);
176 if (Con_Handle !=
NULL) {
177 return(Con_Handle -> prot_IDX);
190 if (Con_Handle !=
NULL) {
191 return(Con_Handle -> protocol);
209 int ourType = (prot_index < 0 || prot_index > 11);
218 if (strcmp(dialects[prot_index],
SMB_Prots[i]) == 0) {
245 int prots_len, i, pkt_len, prot, alloc_len;
252 for (i = 0; Prots[i] !=
NULL; i++) {
254 prots_len = prots_len + strlen(Prots[i]) + 2;
302 for (i = 0; Prots[i] !=
NULL; i++) {
305 strcpy(p + 1, Prots[i]);
306 p = p + strlen(Prots[i]) + 2;
312 if (
RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
315 fprintf(stderr,
"Error sending negotiate protocol\n");
326 if (
RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, alloc_len) < 0) {
329 fprintf(stderr,
"Error receiving response to negotiate\n");
341 fprintf(stderr,
"SMB_Negotiate failed with errorclass = %i, Error Code = %i\n",
356 fprintf(stderr,
"None of our protocols was accepted ... ");
404 xstrncpy(p, Con_Handle -> Svr_PDom,
sizeof(Con_Handle -> Svr_PDom));
427 xstrncpy(p, Con_Handle -> Svr_PDom,
sizeof(Con_Handle -> Svr_PDom));
434 fprintf(stderr,
"Unknown NegProt response format ... Ignored\n");
442 fprintf(stderr,
"Protocol selected is: %i:%s\n", prot, Prots[prot]);
455 if (gethostname(name,
len) < 0) {
457 strncpy(name,
"unknown",
len);
462 fprintf(stderr,
"gethostname in SMB_Get_My_Name returned error:");
469 if (
NULL != (address = strchr(name,
'.'))) {
480 const char *password,
485 int param_len, pkt_len;
491 if ((path ==
NULL) | (password ==
NULL) | (device ==
NULL)) {
494 fprintf(stderr,
"Bad parameter passed to SMB_TreeConnect\n");
504 param_len = strlen(path) + 2 + strlen(password) + 2 + strlen(device) + 2;
522 if (Tree_Handle ==
NULL) {
540 tree -> con = Con_Handle;
541 xstrncpy(tree -> path, path,
sizeof(tree -> path));
542 xstrncpy(tree -> device_type, device,
sizeof(tree -> device_type));
562 p = p + strlen(path) + 2;
564 strcpy(p + 1, password);
565 p = p + strlen(password) + 2;
567 strcpy(p + 1, device);
571 if (
RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
574 fprintf(stderr,
"Error sending TCon request\n");
577 if (Tree_Handle ==
NULL)
587 if (
RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
590 fprintf(stderr,
"Error receiving response to TCon\n");
593 if (Tree_Handle ==
NULL)
606 fprintf(stderr,
"SMB_TCon failed with errorclass = %i, Error Code = %i\n",
611 if (Tree_Handle ==
NULL)
624 fprintf(stderr,
"TConn succeeded, with TID=%i, Max Xmit=%i\n",
625 tree -> tid, tree -> mbs);
630 if (Con_Handle -> first_tree ==
NULL) {
632 Con_Handle -> first_tree = tree;
633 Con_Handle -> last_tree = tree;
637 Con_Handle -> last_tree ->
next = tree;
638 tree -> prev = Con_Handle -> last_tree;
639 Con_Handle -> last_tree = tree;
680 if (
RFCNB_Send(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) {
683 fprintf(stderr,
"Error sending TDis request\n");
694 if (
RFCNB_Recv(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) {
697 fprintf(stderr,
"Error receiving response to TCon\n");
711 fprintf(stderr,
"SMB_TDis failed with errorclass = %i, Error Code = %i\n",
723 Tree_Handle -> tid = 0xFFFF;
724 Tree_Handle -> mbs = 0;
728 fprintf(stderr,
"Tree disconnect successful ...\n");
734 if (discard ==
TRUE) {
737 Tree_Handle -> con -> first_tree = Tree_Handle -> prev;
739 Tree_Handle ->
next -> prev = Tree_Handle -> prev;
741 if (Tree_Handle -> prev ==
NULL)
742 Tree_Handle -> con -> last_tree = Tree_Handle ->
next;
744 Tree_Handle -> prev ->
next = Tree_Handle ->
next;
780 "Request completed successfully.",
781 "Server returned a non-zero SMB Error Class and Code.",
782 "A lower layer protocol error occurred.",
783 "Function not yet implemented.",
784 "The protocol negotiated does not support the request.",
785 "No space available for operation.",
786 "One or more bad parameters passed.",
787 "None of the protocols we offered were accepted.",
788 "The attempt to send an SMB request failed. See protocol error info.",
789 "The attempt to get an SMB response failed. See protocol error info.",
790 "The logon request failed, but you were logged in as guest.",
791 "The attempt to call the remote server failed. See protocol error info.",
792 "The protocol dialect specified in a NegProt and accepted by the server is unknown.",
794 "No such error code.",
820 if (strlen(msgbuf) <
len) {
822 strncat(msgbuf,
"\n\t",
len - strlen(msgbuf));
826 strncat(msgbuf, prot_msg,
len - strlen(msgbuf));
#define SIVAL(buf, pos, val)
#define SSVAL(buf, pos, val)
Network/connection security abstraction layer.
struct RFCNB_Pkt * RFCNB_Alloc_Pkt(int n)
void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt)
int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length)
void RFCNB_Get_Error(char *buffer, int buf_len)
int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length)
#define SMBlibE_SendFailed
#define SMBlibE_ProtUnknown
#define SMBlibE_NegNoProt
#define SMBlibE_RecvFailed
#define SMBlibE_NoSuchMsg
struct SMB_Tree_Structure * SMB_Tree_Handle
#define SMB_negrNTLM_buf_offset
#define SMB_tcon_buf_offset
#define SMB_hdr_rcls_offset
#define SMB_hdr_wct_offset
#define SMB_negrLM_buf_offset
#define SMB_negrNTLM_mmc_offset
#define SMB_negrLM_mnv_offset
#define SMB_negrNTLM_mbs_offset
#define SMB_negrNTLM_mrs_offset
#define SMB_negrNTLM_ekl_offset
#define SMB_hdr_err_offset
#define SMB_negp_bcc_offset
#define SMB_negrLM_sk_offset
#define SMB_negrLM_sec_offset
#define SMB_sec_user_mask
#define SMB_negrLM_mmc_offset
#define SMB_sec_encrypt_mask
#define SMB_negrLM_mbs_offset
#define SMB_negrLM_ekl_offset
#define SMB_hdr_mid_offset
#define SMB_tconr_tid_offset
#define SMB_negp_buf_offset
#define SMB_hdr_idf_offset
#define SMB_negrNTLM_stz_offset
#define SMB_hdr_uid_offset
#define SMB_negrNTLM_sec_offset
#define SMB_tconr_mbs_offset
#define SMB_hdr_pid_offset
#define SMB_negrLM_rm_offset
#define SMB_negrLM_stz_offset
#define SMB_tcon_bcc_offset
#define SMB_hdr_tid_offset
#define SMB_negrNTLM_sk_offset
#define SMB_negrCP_idx_offset
#define SMB_hdr_com_offset
#define SMB_negrNTLM_mnv_offset
SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type Con_Handle, SMB_Tree_Handle Tree_Handle, const char *path, const char *password, const char *device)
static const char * SMBlib_Error_Messages[]
void SMB_Get_My_Name(char *name, int len)
int SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle, BOOL discard)
int SMB_Figure_Protocol(const char *dialects[], int prot_index)
int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
int SMB_Get_Last_SMB_Err()
void SMB_Get_Error_Msg(int msg, char *msgbuf, int len)
int SMB_Get_Protocol(SMB_Handle_Type Con_Handle)
char * xstrncpy(char *dst, const char *src, size_t n)