Unix SMB/Netbios implementation.
Version 1.9.
SMB client
- Copyright (C) Andrew Tridgell 1994-1997
+ Copyright (C) Andrew Tridgell 1994-1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
extern pstring workgroup;
char *cmdstr="";
extern BOOL got_pass;
+extern BOOL no_pass;
extern BOOL connect_as_printer;
extern BOOL connect_as_ipc;
extern struct in_addr ipzero;
-char cryptkey[8];
extern BOOL doencrypt;
extern pstring user_socket_options;
#define USENMB
-extern int coding_system;
-static BOOL setup_term_code (char *code)
+#define CNV_LANG(s) dos_to_unix(s,False)
+#define CNV_INPUT(s) unix_to_dos(s,True)
+
+/****************************************************************************
+send an SMBclose on an SMB file handle
+****************************************************************************/
+void cli_smb_close(char *inbuf, char *outbuf, int clnt_fd, int c_num, int f_num)
{
- int new;
- new = interpret_coding_system (code, UNKNOWN_CODE);
- if (new != UNKNOWN_CODE) {
- coding_system = new;
- return True;
- }
- return False;
+ bzero(outbuf,smb_size);
+ set_message(outbuf,3,0,True);
+
+ CVAL (outbuf,smb_com) = SMBclose;
+ SSVAL(outbuf,smb_tid,c_num);
+ cli_setup_pkt(outbuf);
+ SSVAL (outbuf,smb_vwv0, f_num);
+ SIVALS(outbuf,smb_vwv1, -1);
+
+ send_smb(clnt_fd, outbuf);
+ client_receive_smb(clnt_fd,inbuf,CLIENT_TIMEOUT);
}
-#define CNV_LANG(s) dos2unix_format(s,False)
-#define CNV_INPUT(s) unix2dos_format(s,True)
/****************************************************************************
write to a local file with CR/LF->LF translation if appropriate. return the
#endif
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (report && CVAL(inbuf,smb_rcls) != 0)
DEBUG(2,("chkpath: %s\n",smb_errstr(inbuf)));
send_smb(Client,outbuf);
- if (!receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
+ if (!client_receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
{
printf("SMBsendstrt failed. (%s)\n",smb_errstr(inbuf));
return;
send_smb(Client,outbuf);
- if (!receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
+ if (!client_receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
{
printf("SMBsendtxt failed (%s)\n",smb_errstr(inbuf));
return;
send_smb(Client,outbuf);
- if (!receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
+ if (!client_receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
{
printf("SMBsendend failed (%s)\n",smb_errstr(inbuf));
return;
cli_setup_pkt(outbuf);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
DEBUG(0,("Error in dskattr: %s\n",smb_errstr(inbuf)));
}
/* ??? original code added 1 pad byte after param */
- cli_send_trans_request(outbuf,SMBtrans2,NULL,FID_UNUSED,0,
+ cli_send_trans_request(outbuf,SMBtrans2,NULL,0,FID_UNUSED,0,
NULL,param,&setup,
0,12+strlen(mask)+1,1,
BUFFER_SIZE,10,0);
}
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
received = SVAL(inbuf,smb_vwv0);
memcpy(p,status,21);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
DEBUG(0,("Error closing search: %s\n",smb_errstr(inbuf)));
cli_setup_pkt(outbuf);
SSVAL(outbuf,smb_vwv0,0xFF);
- SSVAL(outbuf,smb_vwv2,1);
+ SSVAL(outbuf,smb_vwv2,1); /* return additional info */
SSVAL(outbuf,smb_vwv3,(DENY_NONE<<4));
SSVAL(outbuf,smb_vwv4,aSYSTEM | aHIDDEN);
SSVAL(outbuf,smb_vwv5,aSYSTEM | aHIDDEN);
SSVAL(outbuf,smb_vwv8,1);
+ SSVAL(outbuf,smb_vwv11,0xffff);
+ SSVAL(outbuf,smb_vwv12,0xffff);
p = smb_buf(outbuf);
strcpy(p,rname);
}
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
}
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
SSVAL(outbuf,smb_vwv4,finfo.size - nread);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
if (!close_done)
{
- bzero(outbuf,smb_size);
- set_message(outbuf,3,0,True);
- CVAL(outbuf,smb_com) = SMBclose;
- SSVAL(outbuf,smb_tid,cnum);
- cli_setup_pkt(outbuf);
-
- SSVAL(outbuf,smb_vwv0,fnum);
- SIVALS(outbuf,smb_vwv1,-1);
-
- send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ cli_smb_close(inbuf, outbuf, Client, cnum, fnum);
if (!ignore_close_error && CVAL(inbuf,smb_rcls) != 0)
{
*p++ = 4;
*p = 0;
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
}
{
strcpy(p,name);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
send_smb(Client,outbuf);
- if (!receive_smb(Client,inbuf,CLIENT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
+ if (!client_receive_smb(Client,inbuf,CLIENT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
return(0);
_smb_setlen(buf-4,n); /* HACK! XXXX */
if (write_socket(Client,buf-4,n+4) != n+4)
return(0);
- if (!receive_smb(Client,inbuf,CLIENT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0) {
+ if (!client_receive_smb(Client,inbuf,CLIENT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0) {
DEBUG(0,("Error writing remote file (2)\n"));
return(0);
}
memcpy(smb_buf(outbuf)+3,buf,n);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0) {
DEBUG(0,("%s writing remote file\n",smb_errstr(inbuf)));
strcpy(p,rname);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
put_dos_date3(outbuf,smb_vwv1,close_time);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
SSVAL(p,0,job);
p += 2;
- if (cli_call_api(PIPE_LANMAN, PTR_DIFF(p,param),0,
- 6,1000,
+ if (cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param),0, 0,
+ 6, 1000,
&rprcnt,&rdrcnt,
- param,NULL,
+ param,NULL, NULL,
&rparam,&rdata))
{
int res = SVAL(rparam,0);
}
-/****************************************************************************
- get info on a file
- ****************************************************************************/
-static void cmd_stat(char *inbuf,char *outbuf)
-{
- fstring buf;
- pstring param;
- char *resp_data=NULL;
- char *resp_param=NULL;
- int resp_data_len = 0;
- int resp_param_len=0;
- char *p;
- uint16 setup = TRANSACT2_QPATHINFO;
-
- if (!next_token(NULL,buf,NULL)) {
- printf("stat <file>\n");
- return;
- }
-
- bzero(param,6);
- SSVAL(param,0,4); /* level */
- p = param+6;
- strcpy(p,cur_dir);
- strcat(p,buf);
-
- cli_send_trans_request(outbuf,SMBtrans2,NULL,FID_UNUSED,0,
- NULL,param,&setup,
- 0,6 + strlen(p)+1,1,
- BUFFER_SIZE,2,0);
-
- cli_receive_trans_response(inbuf,SMBtrans2,
- &resp_data_len,&resp_param_len,
- &resp_data,&resp_param);
-
- if (resp_data) free(resp_data); resp_data = NULL;
- if (resp_param) free(resp_param); resp_param = NULL;
-}
/****************************************************************************
strcpy(p,rname);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
SSVAL(smb_buf(outbuf),1,n);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
SSVAL(outbuf,smb_vwv0,fnum);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
SSVAL(outbuf,smb_vwv1,0); /* the index into the queue */
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
p = skip_string(p,1);
DEBUG(1,("Calling DosPrintJobEnum()...\n"));
- if( cli_call_api(PIPE_LANMAN, PTR_DIFF(p,param), 0,
+ if( cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param), 0, 0,
10, 4096,
&rprcnt, &rdrcnt,
- param, NULL,
+ param, NULL, NULL,
&rparam, &rdata) )
{
int converter;
p = skip_string(p,1);
DEBUG(1,("Calling DosPrintQueueGetInfo()...\n"));
- if( cli_call_api(PIPE_LANMAN, PTR_DIFF(p,param), 0,
- 10, 4096,
+ if( cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param), 0, 0,
+ 10, 4096,
&rprcnt, &rdrcnt,
- param, NULL,
+ param, NULL, NULL,
&rparam, &rdata) )
{
int converter;
strcpy(p,mask);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
DEBUG(0,("%s deleting remote file %s\n",smb_errstr(inbuf),CNV_LANG(mask)));
strcpy(p,mask);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
strcpy(p,dest);
send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+ client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
if (CVAL(inbuf,smb_rcls) != 0)
{
SSVAL(p,2,BUFFER_SIZE);
p += 4;
- if (cli_call_api(PIPE_LANMAN, PTR_DIFF(p,param),0,
- 1024,BUFFER_SIZE,
+ if (cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param),0, 0,
+ 1024, BUFFER_SIZE,
&rprcnt,&rdrcnt,
- param,NULL,
+ param,NULL, NULL,
&rparam,&rdata))
{
int res = SVAL(rparam,0);
SSVAL(p,2,1000);
p += 6;
- if (cli_call_api(PIPE_LANMAN, PTR_DIFF(p,param),0,
- 6,1000,
+ if (cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param),0, 0,
+ 6, 1000,
&rprcnt,&rdrcnt,
- param,NULL,
+ param,NULL, NULL,
&rparam,&rdata))
{
int res = SVAL(rparam,0);
/* first ask for a list of servers in this workgroup */
SIVAL(svtype_p,0,SV_TYPE_ALL);
- if (cli_call_api(PIPE_LANMAN, PTR_DIFF(p+4,param),0,
- 8,BUFFER_SIZE - SAFETY_MARGIN,
+ if (cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p+4,param),0, 0,
+ 8, BUFFER_SIZE - SAFETY_MARGIN,
&rprcnt,&rdrcnt,
- param,NULL,
+ param,NULL, NULL,
&rparam,&rdata))
{
int res = SVAL(rparam,0);
/* now ask for a list of workgroups */
SIVAL(svtype_p,0,SV_TYPE_DOMAIN_ENUM);
- if (cli_call_api(PIPE_LANMAN, PTR_DIFF(p+4,param),0,
- 8,BUFFER_SIZE - SAFETY_MARGIN,
+ if (cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p+4,param),0, 0,
+ 8, BUFFER_SIZE - SAFETY_MARGIN,
&rprcnt,&rdrcnt,
- param,NULL,
+ param,NULL, NULL,
&rparam,&rdata))
{
int res = SVAL(rparam,0);
{"queue",cmd_queue,"show the print queue"},
{"qinfo",cmd_qinfo,"show print queue information"},
{"cancel",cmd_cancel,"<jobid> cancel a print queue entry"},
- {"stat",cmd_stat,"<file> get info on a file (experimental!)"},
{"quit",cli_send_logout,"logoff the server"},
{"q",cli_send_logout,"logoff the server"},
{"exit",cli_send_logout,"logoff the server"},
cmd = i;
break;
}
- else if (strnequal(commands[i].name, tok, tok_len+1))
+ else if (strnequal(commands[i].name, tok, tok_len))
{
matches++;
cmd = i;
}
}
#endif
+
+ /* We deliberately use receive_smb instead of
+ client_receive_smb as we want to receive
+ session keepalives and then drop them here.
+ */
if (FD_ISSET(Client,&fds))
receive_smb(Client,buffer,0);
bzero(OutBuffer,smb_size);
- if (!cli_send_login(InBuffer,OutBuffer,True,True))
+ if (!cli_send_login(InBuffer,OutBuffer,True,True,NULL))
return(False);
if (*base_directory) do_cd(base_directory);
return(True);
}
-
/****************************************************************************
usage on the program
****************************************************************************/
pname));
DEBUG(0,("\nVersion %s\n",VERSION));
- DEBUG(0,("\t-p port listen on the specified port\n"));
+ DEBUG(0,("\t-p port connect to the specified port\n"));
DEBUG(0,("\t-d debuglevel set the debuglevel\n"));
DEBUG(0,("\t-l log basename. Basename for log/debug files\n"));
DEBUG(0,("\t-n netbios name. Use this name as my netbios name\n"));
DEBUG(0,("\t-m max protocol set the max protocol level\n"));
DEBUG(0,("\t-L host get a list of shares available on a host\n"));
DEBUG(0,("\t-I dest IP use this IP to connect to\n"));
+ DEBUG(0,("\t-R name resolve order use these name resolution services only\n"));
DEBUG(0,("\t-E write messages to stderr instead of stdout\n"));
DEBUG(0,("\t-U username set the network username\n"));
DEBUG(0,("\t-W workgroup set the workgroup name\n"));
extern int optind;
pstring query_host;
BOOL message = False;
+ BOOL nt_domain_logon = False;
extern char tar_type;
static pstring servicesf = CONFIGFILE;
pstring term_code;
+ pstring new_name_resolve_order;
char *p;
#ifdef KANJI
*query_host = 0;
*base_directory = 0;
+ *new_name_resolve_order = 0;
+
DEBUGLEVEL = 2;
setup_logging(pname,True);
}
while ((opt =
- getopt(argc, argv,"s:B:O:M:i:Nn:d:Pp:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
+ getopt(argc, argv,"s:B:O:R:M:S:i:Nn:d:Pp:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
switch (opt)
{
case 'm':
case 'O':
strcpy(user_socket_options,optarg);
break;
+ case 'R':
+ pstrcpy(new_name_resolve_order, optarg);
+ break;
+ case 'S':
+ strcpy(desthost,optarg);
+ strupper(desthost);
+ nt_domain_logon = True;
+ break;
case 'M':
name_type = 0x03; /* messages are sent to NetBIOS name type 0x3 */
strcpy(desthost,optarg);
break;
case 'N':
got_pass = True;
+ no_pass = True;
break;
case 'P':
connect_as_printer = True;
DEBUG(0,("Failed to get my hostname.\n"));
}
- if (!lp_load(servicesf,True)) {
+ if (!lp_load(servicesf,True,False,False)) {
fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
}
codepage_initialise(lp_client_code_page());
- if(lp_client_code_page() == KANJI_CODEPAGE)
- {
- if (!setup_term_code (term_code))
- {
- DEBUG(0, ("%s: unknown terminal code name\n", optarg));
- usage (pname);
- exit (1);
- }
- }
+ interpret_coding_system(term_code);
if (*workgroup == 0)
strcpy(workgroup,lp_workgroup());
get_myname((*myname)?NULL:myname,NULL);
strupper(myname);
+ if(*new_name_resolve_order)
+ lp_set_name_resolve_order(new_name_resolve_order);
+
if (tar_type) {
recurse=True;
return(1);
bzero(OutBuffer,smb_size);
- if (!cli_send_login(InBuffer,OutBuffer,True,True))
+ if (!cli_send_login(InBuffer,OutBuffer,True,True,NULL))
return(False);
if (*base_directory) do_cd(base_directory);
return(1);
}
- if (*query_host)
+ if (*query_host && !nt_domain_logon)
{
int ret = 0;
sprintf(service,"\\\\%s\\IPC$",query_host);
#if 0
*username = 0;
#endif
- if (!cli_send_login(NULL,NULL,True,True))
+ if (!cli_send_login(NULL,NULL,True,True,NULL))
return(1);
server_info();