a little hack to smbclient to support extracting NT error codes
[kai/samba.git] / source3 / client / client.c
index 329956ce94bdec3bdcf430eaf2e9843b21d16ff9..403eea2fc99f5aaeb7b7151e0fc03fe7d3939ef1 100644 (file)
@@ -34,6 +34,7 @@ pstring cd_path = "";
 pstring service="";
 pstring desthost="";
 extern pstring myname;
+extern pstring myhostname;
 pstring password = "";
 pstring username="";
 pstring workgroup="";
@@ -142,12 +143,8 @@ extern int Client;
 
 #define USENMB
 
-#ifdef KANJI
 extern int coding_system;
-#define CNV_LANG(s) (coding_system == DOSV_CODE?s:dos_to_unix(s, False))
-#define CNV_INPUT(s) (coding_system == DOSV_CODE?s:unix_to_dos(s, True))
-static BOOL
-setup_term_code (char *code)
+static BOOL setup_term_code (char *code)
 {
     int new;
     new = interpret_coding_system (code, UNKNOWN_CODE);
@@ -157,10 +154,8 @@ setup_term_code (char *code)
     }
     return False;
 }
-#else
 #define CNV_LANG(s) dos2unix_format(s,False)
 #define CNV_INPUT(s) unix2dos_format(s,True)
-#endif
 
 /****************************************************************************
 setup basics in a outgoing packet
@@ -280,6 +275,18 @@ static BOOL chkpath(char *path,BOOL report)
   *p++ = 4;
   strcpy(p,path2);
 
+#if 0
+  {
+         /* this little bit of code can be used to extract NT error codes.
+            Just feed a bunch of "cd foo" commands to smbclient then watch
+            in netmon (tridge) */
+         static int code=0;
+         SIVAL(outbuf, smb_rcls, code | 0xC0000000);
+         SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | (1<<14));
+         code++;
+  }
+#endif
+
   send_smb(Client,outbuf);
   receive_smb(Client,inbuf,CLIENT_TIMEOUT);
 
@@ -3308,15 +3315,11 @@ static BOOL send_login(char *inbuf,char *outbuf,BOOL start_session,BOOL use_setu
       int passlen = strlen(pass)+1;
       strcpy(pword,pass);      
 
-#ifdef SMB_PASSWD
       if (doencrypt && *pass) {
        DEBUG(3,("Using encrypted passwords\n"));
        passlen = 24;
        SMBencrypt((uchar *)pass,(uchar *)cryptkey,(uchar *)pword);
       }
-#else
-      doencrypt = False;
-#endif
 
       /* if in share level security then don't send a password now */
       if (!(sec_mode & 1)) {strcpy(pword, "");passlen=1;} 
@@ -3427,12 +3430,10 @@ static BOOL send_login(char *inbuf,char *outbuf,BOOL start_session,BOOL use_setu
     fstring pword;
     strcpy(pword,pass);
 
-#ifdef SMB_PASSWD
     if (doencrypt && *pass) {
       passlen=24;
       SMBencrypt((uchar *)pass,(uchar *)cryptkey,(uchar *)pword);      
     }
-#endif
 
     /* if in user level security then don't send a password now */
     if ((sec_mode & 1)) {
@@ -4391,10 +4392,6 @@ static void usage(char *pname)
   DEBUG(0,("Usage: %s service <password> [-p port] [-d debuglevel] [-l log] ",
           pname));
 
-#ifdef KANJI
-  DEBUG(0,("[-t termcode] "));
-#endif /* KANJI */
-
   DEBUG(0,("\nVersion %s\n",VERSION));
   DEBUG(0,("\t-p port               listen on the specified port\n"));
   DEBUG(0,("\t-d debuglevel         set the debuglevel\n"));
@@ -4410,9 +4407,7 @@ static void usage(char *pname)
   DEBUG(0,("\t-U username           set the network username\n"));
   DEBUG(0,("\t-W workgroup          set the workgroup name\n"));
   DEBUG(0,("\t-c command string     execute semicolon separated commands\n"));
-#ifdef KANJI
   DEBUG(0,("\t-t terminal code      terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"));
-#endif /* KANJI */
   DEBUG(0,("\t-T<c|x>IXgbNa          command line tar\n"));
   DEBUG(0,("\t-D directory          start from directory\n"));
   DEBUG(0,("\n"));
@@ -4434,6 +4429,14 @@ static void usage(char *pname)
   BOOL message = False;
   extern char tar_type;
   static pstring servicesf = CONFIGFILE;
+  pstring term_code;
+  char *p;
+
+#ifdef KANJI
+  strcpy(term_code, KANJI);
+#else /* KANJI */
+  *term_code = 0;
+#endif /* KANJI */
 
   *query_host = 0;
   *base_directory = 0;
@@ -4453,10 +4456,27 @@ static void usage(char *pname)
   umask(myumask);
 
   if (getenv("USER"))
+  {
+    strcpy(username,getenv("USER"));
+
+    /* modification to support userid%passwd syntax in the USER var
+       25.Aug.97, jdblair@uab.edu */
+
+    if ((p=strchr(username,'%')))
     {
-      strcpy(username,getenv("USER"));
-      strupper(username);
+      *p = 0;
+      strcpy(password,p+1);
+      got_pass = True;
+      memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
     }
+    strupper(username);
+  }
+
+ /* modification to support PASSWD environmental var
+  25.Aug.97, jdblair@uab.edu */
+
+  if (getenv("PASSWD"))
+    strcpy(password,getenv("PASSWD"));
 
   if (*username == 0 && getenv("LOGNAME"))
     {
@@ -4505,9 +4525,6 @@ static void usage(char *pname)
        }
     }
 
-#ifdef KANJI
-  setup_term_code (KANJI);
-#endif
   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)
     switch (opt)
@@ -4603,13 +4620,7 @@ static void usage(char *pname)
        strcpy(servicesf, optarg);
        break;
       case 't':
-#ifdef KANJI
-       if (!setup_term_code (optarg)) {
-           DEBUG(0, ("%s: unknown terminal code name\n", optarg));
-           usage (pname);
-           exit (1);
-       }
-#endif
+        strcpy(term_code, optarg);
        break;
       default:
        usage(pname);
@@ -4625,10 +4636,27 @@ static void usage(char *pname)
 
   DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
 
+  if(!get_myname(myhostname,NULL))
+  {
+    DEBUG(0,("Failed to get my hostname.\n"));
+  }
+
   if (!lp_load(servicesf,True)) {
     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);
+        }
+  }
+
   if (*workgroup == 0)
     strcpy(workgroup,lp_workgroup());