Adding the same changes to HEAD as were added to BRANCH_1_9_18.
[samba.git] / source3 / client / client.c
index aaa0186a78db15ed86bf2bb7a53fd40b6de91631..3ce635fbeb2fab8a68d4d19cff1e1ce62f12134a 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,11 +40,11 @@ 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;
 
-char cryptkey[8];
 extern BOOL doencrypt;
 
 extern pstring user_socket_options;
@@ -130,19 +130,26 @@ extern int Client;
 
 #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 
@@ -260,7 +267,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)));
@@ -298,7 +305,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;
@@ -338,7 +345,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;
@@ -361,7 +368,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;
@@ -384,7 +391,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)));      
@@ -534,7 +541,7 @@ static int do_long_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (*
        }
       /* ??? 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);
@@ -703,7 +710,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);
 
@@ -753,7 +760,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)));      
@@ -1085,11 +1092,13 @@ static void do_get(char *rname,char *lname,file_info *finfo1)
   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);
@@ -1127,7 +1136,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)
     {
@@ -1254,7 +1263,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)
            {
@@ -1347,7 +1356,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)
            {
@@ -1381,17 +1390,7 @@ static void do_get(char *rname,char *lname,file_info *finfo1)
 
   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)
        {
@@ -1421,7 +1420,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);
   }
 
   {
@@ -1654,7 +1653,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)
     {
@@ -1737,7 +1736,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 */
@@ -1745,7 +1744,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);
   }
@@ -1782,7 +1781,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)));
@@ -1837,7 +1836,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)
     {
@@ -1909,7 +1908,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)
     {
@@ -2128,10 +2127,10 @@ static void do_cancel(int job)
   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);
@@ -2177,43 +2176,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,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;
-}
 
 
 /****************************************************************************
@@ -2275,7 +2237,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)
     {
@@ -2329,7 +2291,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)
        {
@@ -2351,7 +2313,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)
     {
@@ -2385,7 +2347,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)
     {
@@ -2464,10 +2426,10 @@ 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, 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;
@@ -2571,10 +2533,10 @@ static void cmd_qinfo(char *inbuf,char *outbuf )
   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;
@@ -2682,7 +2644,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)));
@@ -2747,7 +2709,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)
     {
@@ -2793,7 +2755,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)
     {
@@ -2967,10 +2929,10 @@ static BOOL browse_host(BOOL sort)
   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);
@@ -3059,10 +3021,10 @@ static void server_info()
   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);
@@ -3134,10 +3096,10 @@ static BOOL list_servers(char *wk_grp)
   /* 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);
@@ -3173,10 +3135,10 @@ static BOOL list_servers(char *wk_grp)
   /* 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);
@@ -3249,7 +3211,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"},
@@ -3285,7 +3246,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;
@@ -3383,6 +3344,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);
       
@@ -3417,7 +3383,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);
@@ -3515,7 +3481,6 @@ static BOOL process(char *base_directory)
   return(True);
 }
 
-
 /****************************************************************************
 usage on the program
 ****************************************************************************/
@@ -3525,7 +3490,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"));
@@ -3535,6 +3500,7 @@ static void usage(char *pname)
   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"));
@@ -3559,9 +3525,11 @@ static void usage(char *pname)
   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
@@ -3573,6 +3541,8 @@ static void usage(char *pname)
   *query_host = 0;
   *base_directory = 0;
 
+  *new_name_resolve_order = 0;
+
   DEBUGLEVEL = 2;
 
   setup_logging(pname,True);
@@ -3658,7 +3628,7 @@ static void usage(char *pname)
     }
 
   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':
@@ -3667,6 +3637,14 @@ static void usage(char *pname)
       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);
@@ -3724,6 +3702,7 @@ static void usage(char *pname)
        break;
       case 'N':
        got_pass = True;
+       no_pass = True;
        break;
       case 'P':
        connect_as_printer = True;
@@ -3773,21 +3752,13 @@ static void usage(char *pname)
     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());
@@ -3796,6 +3767,9 @@ static void usage(char *pname)
   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;
 
@@ -3808,7 +3782,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);
@@ -3822,7 +3796,7 @@ static void usage(char *pname)
       return(1);
   }
   
-  if (*query_host)
+  if (*query_host && !nt_domain_logon)
     {
       int ret = 0;
       sprintf(service,"\\\\%s\\IPC$",query_host);
@@ -3833,7 +3807,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();