client/client.c: I18N fixes.
authorJeremy Allison <jra@samba.org>
Wed, 5 Jan 2000 19:59:42 +0000 (19:59 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 5 Jan 2000 19:59:42 +0000 (19:59 +0000)
smbd/dir.c: Reformatting comments.
smbd/ipc.c: New password change code for Win98.
Jeremy.
(This used to be commit 9e90122afd1b6a7cf38660fc3bc3aa8e526bf08b)

source3/client/client.c
source3/smbd/dir.c
source3/smbd/ipc.c

index bff00365050e486bd4c3ae4b76f7834d8220ac8a..5c668b84b33aed5b8f78a702b12a373ee8b6336a 100644 (file)
@@ -105,10 +105,6 @@ static double dir_total;
 
 #define USENMB
 
-#define CNV_LANG(s) dos_to_unix(s,False)
-#define CNV_INPUT(s) unix_to_dos(s,True)
-
-
 /****************************************************************************
 write to a local file with CR/LF->LF translation if appropriate. return the 
 number taken from the buffer. This may not equal the number written.
@@ -237,8 +233,8 @@ show cd/pwd
 ****************************************************************************/
 static void cmd_pwd(void)
 {
-       DEBUG(0,("Current directory is %s",CNV_LANG(service)));
-       DEBUG(0,("%s\n",CNV_LANG(cur_dir)));
+       DEBUG(0,("Current directory is %s",service));
+       DEBUG(0,("%s\n",cur_dir));
 }
 
 
@@ -288,7 +284,7 @@ static void cmd_cd(void)
        if (next_token(NULL,buf,NULL,sizeof(buf)))
                do_cd(buf);
        else
-               DEBUG(0,("Current directory is %s\n",CNV_LANG(cur_dir)));
+               DEBUG(0,("Current directory is %s\n",cur_dir));
 }
 
 
@@ -326,7 +322,7 @@ static void display_finfo(file_info *finfo)
        if (do_this_one(finfo)) {
                time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
                DEBUG(0,("  %-30s%7.7s %8.0f  %s",
-                        CNV_LANG(finfo->name),
+                        finfo->name,
                         attrib_string(finfo->mode),
                         (double)finfo->size,
                         asctime(LocalTime(&t))));
@@ -549,7 +545,7 @@ void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec,
                                                strlen(next_file) - 2;
                                        *save_ch = '\0';
                                }
-                               DEBUG(0,("\n%s\n",CNV_LANG(next_file)));
+                               DEBUG(0,("\n%s\n",next_file));
                                if (save_ch)
                                {
                                        *save_ch = '\\';
@@ -659,7 +655,7 @@ static void do_get(char *rname,char *lname)
        fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
 
        if (fnum == -1) {
-               DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
+               DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),rname));
                return;
        }
 
@@ -707,7 +703,7 @@ static void do_get(char *rname,char *lname)
 
        if (nread < size) {
                DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
-               CNV_LANG(rname), (long)nread));
+               rname, (long)nread));
        }
 
        free(data);
@@ -789,10 +785,10 @@ static void do_mget(file_info *finfo)
 
        if (finfo->mode & aDIR)
                slprintf(quest,sizeof(pstring)-1,
-                        "Get directory %s? ",CNV_LANG(finfo->name));
+                        "Get directory %s? ",finfo->name);
        else
                slprintf(quest,sizeof(pstring)-1,
-                        "Get file %s? ",CNV_LANG(finfo->name));
+                        "Get file %s? ",finfo->name);
 
        if (prompt && !yesno(quest)) return;
 
@@ -815,13 +811,13 @@ static void do_mget(file_info *finfo)
        
        if (!dos_directory_exist(finfo->name,NULL) && 
            dos_mkdir(finfo->name,0777) != 0) {
-               DEBUG(0,("failed to create directory %s\n",CNV_LANG(finfo->name)));
+               DEBUG(0,("failed to create directory %s\n",finfo->name));
                pstrcpy(cur_dir,saved_curdir);
                return;
        }
        
        if (dos_chdir(finfo->name) != 0) {
-               DEBUG(0,("failed to chdir to directory %s\n",CNV_LANG(finfo->name)));
+               DEBUG(0,("failed to chdir to directory %s\n",finfo->name));
                pstrcpy(cur_dir,saved_curdir);
                return;
        }
@@ -914,7 +910,7 @@ static BOOL do_mkdir(char *name)
 {
        if (!cli_mkdir(cli, name)) {
                DEBUG(0,("%s making remote directory %s\n",
-                        cli_errstr(cli),CNV_LANG(name)));
+                        cli_errstr(cli),name));
                return(False);
        }
 
@@ -989,7 +985,7 @@ static void do_put(char *rname,char *lname)
        fnum = cli_open(cli, rname, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE);
   
        if (fnum == -1) {
-               DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
+               DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),rname));
                return;
        }
 
@@ -1009,7 +1005,7 @@ static void do_put(char *rname,char *lname)
 
   
        DEBUG(1,("putting file %s as %s ",lname,
-                CNV_LANG(rname)));
+                rname));
   
        buf = (char *)malloc(maxwrite);
        while (!feof(f)) {
@@ -1032,7 +1028,7 @@ static void do_put(char *rname,char *lname)
        }
 
        if (!cli_close(cli, fnum)) {
-               DEBUG(0,("%s closing remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
+               DEBUG(0,("%s closing remote file %s\n",cli_errstr(cli),rname));
                fclose(f);
                if (buf) free(buf);
                return;
@@ -1304,7 +1300,7 @@ static void do_del(file_info *finfo)
                return;
 
        if (!cli_unlink(cli, mask)) {
-               DEBUG(0,("%s deleting remote file %s\n",cli_errstr(cli),CNV_LANG(mask)));
+               DEBUG(0,("%s deleting remote file %s\n",cli_errstr(cli),mask));
        }
 }
 
@@ -1368,7 +1364,7 @@ static void cmd_rmdir(void)
 
        if (!cli_rmdir(cli, mask)) {
                DEBUG(0,("%s removing remote directory file %s\n",
-                        cli_errstr(cli),CNV_LANG(mask)));
+                        cli_errstr(cli),mask));
        }  
 }
 
@@ -1781,9 +1777,6 @@ static void process_command_string(char *cmd)
                        cmd = p + 1;
                }
                
-               /* input language code to internal one */
-               CNV_INPUT (line);
-               
                /* and get the first part of the command */
                ptr = line;
                if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
@@ -1791,9 +1784,9 @@ static void process_command_string(char *cmd)
                if ((i = process_tok(tok)) >= 0) {
                        commands[i].fn();
                } else if (i == -2) {
-                       DEBUG(0,("%s: command abbreviation ambiguous\n",CNV_LANG(tok)));
+                       DEBUG(0,("%s: command abbreviation ambiguous\n",tok));
                } else {
-                       DEBUG(0,("%s: command not found\n",CNV_LANG(tok)));
+                       DEBUG(0,("%s: command not found\n",tok));
                }
        }
 }      
@@ -1827,7 +1820,7 @@ static void process_stdin(void)
                        temp = (char *)NULL;
                }
 
-               snprintf( prompt_str, PROMPTSIZE - 1, "smb: %s> ", CNV_LANG(cur_dir) );
+               snprintf( prompt_str, PROMPTSIZE - 1, "smb: %s> ", cur_dir );
 
                temp = readline( prompt_str );          /* We read the line here */
 
@@ -1840,7 +1833,7 @@ static void process_stdin(void)
                strncpy( line, temp, 1023 ); /* Maximum size of (pstring)line. Null is guarranteed. */
 #else 
                /* display a prompt */
-               DEBUG(0,("smb: %s> ", CNV_LANG(cur_dir)));
+               DEBUG(0,("smb: %s> ", cur_dir));
                dbgflush( );
                
                wait_keyboard();
@@ -1850,9 +1843,6 @@ static void process_stdin(void)
                        break;
 #endif
 
-               /* input language code to internal one */
-               CNV_INPUT (line);
-               
                /* special case - first char is ! */
                if (*line == '!') {
                        system(line + 1);
@@ -1866,9 +1856,9 @@ static void process_stdin(void)
                if ((i = process_tok(tok)) >= 0) {
                        commands[i].fn();
                } else if (i == -2) {
-                       DEBUG(0,("%s: command abbreviation ambiguous\n",CNV_LANG(tok)));
+                       DEBUG(0,("%s: command abbreviation ambiguous\n",tok));
                } else {
-                       DEBUG(0,("%s: command not found\n",CNV_LANG(tok)));
+                       DEBUG(0,("%s: command not found\n",tok));
                }
        }
 }
index 28faa9a06b7eea04f31eb95e48b9265235304b19..cae6281e9144f4094bd1a30c02cd706d53730fd3 100644 (file)
@@ -790,38 +790,32 @@ int TellDir(void *p)
   return(dirp->pos);
 }
 
+/*******************************************************************************
+ This section manages a global directory cache.
+ (It should probably be split into a separate module.  crh)
+********************************************************************************/
 
-/* -------------------------------------------------------------------------- **
- * This section manages a global directory cache.
- * (It should probably be split into a separate module.  crh)
- * -------------------------------------------------------------------------- **
- */
-
-typedef struct
-  {
+typedef struct {
   ubi_dlNode  node;
   char       *path;
   char       *name;
   char       *dname;
   int         snum;
-  } dir_cache_entry;
+} dir_cache_entry;
 
 static ubi_dlNewList( dir_cache );
 
+/*****************************************************************************
+ Add an entry to the directory cache.
+ Input:  path  -
+         name  -
+         dname -
+         snum  -
+ Output: None.
+*****************************************************************************/
+
 void DirCacheAdd( char *path, char *name, char *dname, int snum )
-  /* ------------------------------------------------------------------------ **
-   * Add an entry to the directory cache.
-   *
-   *  Input:  path  -
-   *          name  -
-   *          dname -
-   *          snum  -
-   *
-   *  Output: None.
-   *
-   * ------------------------------------------------------------------------ **
-   */
-  {
+{
   int               pathlen;
   int               namelen;
   dir_cache_entry  *entry;
@@ -852,27 +846,23 @@ void DirCacheAdd( char *path, char *name, char *dname, int snum )
   while( DIRCACHESIZE < dir_cache->count )
     free( ubi_dlRemTail( dir_cache ) );
 
-  } /* DirCacheAdd */
+}
 
+/*****************************************************************************
+ Search for an entry to the directory cache.
+ Input:  path  -
+         name  -
+         snum  -
+ Output: The dname string of the located entry, or NULL if the entry was
+         not found.
+
+ Notes:  This uses a linear search, which is is okay because of
+         the small size of the cache.  Use a splay tree or hash
+         for large caches.
+*****************************************************************************/
 
 char *DirCacheCheck( char *path, char *name, int snum )
-  /* ------------------------------------------------------------------------ **
-   * Search for an entry to the directory cache.
-   *
-   *  Input:  path  -
-   *          name  -
-   *          snum  -
-   *
-   *  Output: The dname string of the located entry, or NULL if the entry was
-   *          not found.
-   *
-   *  Notes:  This uses a linear search, which is is okay because of
-   *          the small size of the cache.  Use a splay tree or hash
-   *          for large caches.
-   *
-   * ------------------------------------------------------------------------ **
-   */
-  {
+{
   dir_cache_entry *entry;
 
   for( entry = (dir_cache_entry *)ubi_dlFirst( dir_cache );
@@ -889,18 +879,15 @@ char *DirCacheCheck( char *path, char *name, int snum )
     }
 
   return(NULL);
-  } /* DirCacheCheck */
+}
+
+/*****************************************************************************
+ Remove all cache entries which have an snum that matches the input.
+ Input:  snum  -
+ Output: None.
+*****************************************************************************/
 
 void DirCacheFlush(int snum)
-  /* ------------------------------------------------------------------------ **
-   * Remove all cache entries which have an snum that matches the input.
-   *
-   *  Input:  snum  -
-   *
-   *  Output: None.
-   *
-   * ------------------------------------------------------------------------ **
-   */
 {
        dir_cache_entry *entry;
        ubi_dlNodePtr    next;
@@ -912,11 +899,4 @@ void DirCacheFlush(int snum)
                        free( ubi_dlRemThis( dir_cache, entry ) );
                entry = (dir_cache_entry *)next;
        }
-} /* DirCacheFlush */
-
-/* -------------------------------------------------------------------------- **
- * End of the section that manages the global directory cache.
- * -------------------------------------------------------------------------- **
- */
-
-
+}
index cb4127aee42fd25c2ce188b19889b237c53b11ce..086a4bfa0b4f58af2faeb59abf865ed884a0f131 100644 (file)
@@ -1660,9 +1660,53 @@ static BOOL api_NetRemoteTOD(connection_struct *conn,uint16 vuid, char *param,ch
   return(True);
 }
 
+/***********************************************************
+ Code to check a plaintext password against smbpasswd entries.
+***********************************************************/
+
+static BOOL check_plaintext_password(char *user,char *old_passwd,
+                                     int old_passwd_size, struct smb_passwd **psmbpw)
+{
+  struct smb_passwd *smbpw = NULL;
+  uchar old_pw[16],old_ntpw[16];
+
+  become_root(False);
+  *psmbpw = smbpw = getsmbpwnam(user);
+  unbecome_root(False);
+
+  if (smbpw == NULL) {
+    DEBUG(0,("check_plaintext_password: getsmbpwnam returned NULL\n"));
+    return False;
+  }
+
+  if (smbpw->acct_ctrl & ACB_DISABLED) {
+    DEBUG(0,("check_plaintext_password: account %s disabled.\n", user));
+    return(False);
+  }
+
+  nt_lm_owf_gen(old_passwd,old_ntpw,old_pw);
+
+#ifdef DEBUG_PASSWORD
+  DEBUG(100,("check_plaintext_password: smbpw->smb_nt_passwd \n"));
+  dump_data(100,smbpw->smb_nt_passwd,16);
+  DEBUG(100,("check_plaintext_password: old_ntpw \n"));
+  dump_data(100,old_ntpw,16);
+  DEBUG(100,("check_plaintext_password: smbpw->smb_passwd \n"));
+  dump_data(100,smbpw->smb_passwd,16);
+  DEBUG(100,("check_plaintext_password: old_pw\n"));
+  dump_data(100,old_pw,16);
+#endif
+
+  if(memcmp(smbpw->smb_nt_passwd,old_ntpw,16) && memcmp(smbpw->smb_passwd,old_pw,16))
+    return(False);
+  else
+    return(True);
+}
+
 /****************************************************************************
-  set the user password
-  ****************************************************************************/
+ Set the user password.
+*****************************************************************************/
+
 static BOOL api_SetUserPassword(connection_struct *conn,uint16 vuid, char *param,char *data,
                                int mdrcnt,int mprcnt,
                                char **rdata,char **rparam,
@@ -1704,20 +1748,59 @@ static BOOL api_SetUserPassword(connection_struct *conn,uint16 vuid, char *param
   (void)Get_Pwnam( user, True);
 
   /*
-   * Attempt the plaintext password change first.
-   * Older versions of Windows seem to do this.
+   * Attempt to verify the old password against smbpasswd entries
+   * Win98 clients send old and new password in plaintext for this call.
    */
 
-  if (password_ok(user, pass1,strlen(pass1),NULL) &&
-      chgpasswd(user,pass1,pass2,False))
   {
-    SSVAL(*rparam,0,NERR_Success);
+    fstring saved_pass2;
+    struct smb_passwd *smbpw = NULL;
+
+    /*
+     * Save the new password as change_oem_password overwrites it
+     * with zeros.
+     */
+
+    fstrcpy(saved_pass2, pass2);
+
+    if (check_plaintext_password(user,pass1,strlen(pass1),&smbpw) &&
+        change_oem_password(smbpw,pass2,False))
+    {
+      SSVAL(*rparam,0,NERR_Success);
+
+      /*
+       * If unix password sync was requested, attempt to change
+       * the /etc/passwd database also. Return failure if this cannot
+       * be done.
+       */
+
+      if(lp_unix_password_sync() && !chgpasswd(user,pass1,saved_pass2,False))
+        SSVAL(*rparam,0,NERR_badpass);
+    }
+  }
+
+  /*
+   * If the above failed, attempt the plaintext password change.
+   * This tests against the /etc/passwd database only.
+   */
+
+  if(SVAL(*rparam,0) != NERR_Success)
+  {
+    if (password_ok(user, pass1,strlen(pass1),NULL) &&
+        chgpasswd(user,pass1,pass2,False))
+    {
+      SSVAL(*rparam,0,NERR_Success);
+    }
   }
 
   /*
    * If the plaintext change failed, attempt
-   * the encrypted. NT will generate this
-   * after trying the samr method.
+   * the old encrypted method. NT will generate this
+   * after trying the samr method. Note that this
+   * method is done as a last resort as this
+   * password change method loses the NT password hash
+   * and cannot change the UNIX password as no plaintext
+   * is received.
    */
 
   if(SVAL(*rparam,0) != NERR_Success)