-N option still prompted for password in smbclient -L usage
[samba.git] / source3 / client / client.c
index 52f4b837a6e7f73e99e05e4612e076671d568558..798dfe577e728c89396c9167fd0279279a25f750 100644 (file)
@@ -2,7 +2,7 @@
    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
@@ -40,6 +40,7 @@ extern pstring username;
 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;
@@ -129,16 +130,10 @@ extern int Client;
 
 #define USENMB
 
-extern int coding_system;
-static BOOL setup_term_code (char *code)
+static BOOL setup_term_code(char *code)
 {
-    int new;
-    new = interpret_coding_system (code, UNKNOWN_CODE);
-    if (new != UNKNOWN_CODE) {
-       coding_system = new;
+       interpret_coding_system(code);
        return True;
-    }
-    return False;
 }
 #define CNV_LANG(s) dos2unix_format(s,False)
 #define CNV_INPUT(s) unix2dos_format(s,True)
@@ -158,7 +153,7 @@ void cli_smb_close(char *inbuf, char *outbuf, int clnt_fd, int c_num, int f_num)
   SIVALS(outbuf,smb_vwv1, -1);
   
   send_smb(clnt_fd, outbuf);
-  receive_smb(clnt_fd,inbuf,CLIENT_TIMEOUT);
+  client_receive_smb(clnt_fd,inbuf,CLIENT_TIMEOUT);
 }
 
 /****************************************************************************
@@ -277,7 +272,7 @@ static BOOL chkpath(char *path,BOOL report)
 #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)));
@@ -315,7 +310,7 @@ static void send_message(char *inbuf,char *outbuf)
   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;
@@ -355,7 +350,7 @@ static void send_message(char *inbuf,char *outbuf)
       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;
@@ -378,7 +373,7 @@ static void send_message(char *inbuf,char *outbuf)
   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;
@@ -401,7 +396,7 @@ static void do_dskattr(void)
   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)));      
@@ -720,7 +715,7 @@ static int do_short_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (
        }
 
       send_smb(Client,outbuf);
-      receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+      client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
 
       received = SVAL(inbuf,smb_vwv0);
 
@@ -770,7 +765,7 @@ static int do_short_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (
       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)));      
@@ -1146,7 +1141,7 @@ static void do_get(char *rname,char *lname,file_info *finfo1)
     }
 
   send_smb(Client,outbuf);
-  receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+  client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
 
   if (CVAL(inbuf,smb_rcls) != 0)
     {
@@ -1273,7 +1268,7 @@ static void do_get(char *rname,char *lname,file_info *finfo1)
            }
          
          send_smb(Client,outbuf);
-         receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+         client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
          
          if (CVAL(inbuf,smb_rcls) != 0)
            {
@@ -1366,7 +1361,7 @@ static void do_get(char *rname,char *lname,file_info *finfo1)
          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)
            {
@@ -1430,7 +1425,7 @@ static void do_get(char *rname,char *lname,file_info *finfo1)
     *p++ = 4;
     *p = 0;
     send_smb(Client,outbuf);
-    receive_smb(Client,inbuf,CLIENT_TIMEOUT);
+    client_receive_smb(Client,inbuf,CLIENT_TIMEOUT);
   }
 
   {
@@ -1663,7 +1658,7 @@ static BOOL do_mkdir(char *name)
   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)
     {
@@ -1746,7 +1741,7 @@ static int smb_writeraw(char *outbuf,int fnum,int pos,char *buf,int n)
 
   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 */
@@ -1754,7 +1749,7 @@ static int smb_writeraw(char *outbuf,int fnum,int pos,char *buf,int n)
   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);
   }
@@ -1791,7 +1786,7 @@ static int smb_writefile(char *outbuf,int fnum,int pos,char *buf,int n)
   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)));
@@ -1846,7 +1841,7 @@ static void do_put(char *rname,char *lname,file_info *finfo)
   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)
     {
@@ -1918,7 +1913,7 @@ static void do_put(char *rname,char *lname,file_info *finfo)
   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)
     {
@@ -2186,43 +2181,6 @@ static void cmd_cancel(char *inbuf,char *outbuf )
 }
 
 
-/****************************************************************************
-  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,0,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;
-}
 
 
 /****************************************************************************
@@ -2284,7 +2242,7 @@ static void cmd_print(char *inbuf,char *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)
     {
@@ -2338,7 +2296,7 @@ static void cmd_print(char *inbuf,char *outbuf )
       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)
        {
@@ -2360,7 +2318,7 @@ static void cmd_print(char *inbuf,char *outbuf )
   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)
     {
@@ -2394,7 +2352,7 @@ static void cmd_queue(char *inbuf,char *outbuf )
   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)
     {
@@ -2473,8 +2431,8 @@ static void cmd_p_queue_4(char *inbuf,char *outbuf )
   p = skip_string(p,1);
 
   DEBUG(1,("Calling DosPrintJobEnum()...\n"));
-  if( cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param), 0,
-               10, 0, 4096,
+  if( cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param), 0, 0,
+               10, 4096,
                &rprcnt, &rdrcnt,
                param, NULL, NULL,
                &rparam, &rdata) )
@@ -2691,7 +2649,7 @@ static void do_del(file_info *finfo)
   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)));
@@ -2756,7 +2714,7 @@ static void cmd_rmdir(char *inbuf,char *outbuf )
   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)
     {
@@ -2802,7 +2760,7 @@ static void cmd_rename(char *inbuf,char *outbuf )
   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)
     {
@@ -3258,7 +3216,6 @@ struct
   {"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"},
@@ -3294,7 +3251,7 @@ static int process_tok(fstring tok)
          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;
@@ -3392,6 +3349,11 @@ static void wait_keyboard(char *buffer)
          }
       }
 #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);
       
@@ -3426,7 +3388,7 @@ static BOOL process(char *base_directory)
   
   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);
@@ -3533,7 +3495,7 @@ static void usage(char *pname)
           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"));
@@ -3738,6 +3700,7 @@ static void usage(char *pname)
        break;
       case 'N':
        got_pass = True;
+       no_pass = True;
        break;
       case 'P':
        connect_as_printer = True;
@@ -3822,7 +3785,7 @@ static void usage(char *pname)
          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);
@@ -3847,7 +3810,7 @@ static void usage(char *pname)
 #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();
@@ -3898,7 +3861,7 @@ static void usage(char *pname)
 
                if (cli_open_sockets(port))
                {
-                       if (!cli_send_login(NULL,NULL,True,True)) return(1);
+                       if (!cli_send_login(NULL,NULL,True,True,NULL)) return(1);
 
                        do_nt_login(desthost, myhostname, Client, cnum);