SAM database "set user info".
[samba.git] / source3 / smbd / reply.c
index 1abb084124b030153bc06c08f5c378b1dd2b958d..57742003ff6e876cfc98e7e9ea7810f0fb32caf1 100644 (file)
@@ -60,6 +60,51 @@ static void overflow_attack(int len)
 }
 
 
+/****************************************************************************
+  does _both_ nt->unix and unix->unix username remappings.
+****************************************************************************/
+static void map_nt_and_unix_username(const char *domain, char *user)
+{
+       DOM_NAME_MAP gmep;
+       fstring nt_username;
+
+       /*
+        * Pass the user through the NT -> unix user mapping
+        * function.
+        */
+   
+       if (lp_server_role() != ROLE_DOMAIN_NONE)
+       {
+               memset(nt_username, 0, sizeof(nt_username));
+               if (domain != NULL)
+               {
+                       slprintf(nt_username, sizeof(nt_username)-1, "%s\\%s",
+                                domain, user);
+               }
+               else
+               {
+                       fstrcpy(nt_username, user);
+               }
+
+               if (lookupsmbpwntnam(nt_username, &gmep))
+               {
+                       fstrcpy(user, gmep.unix_name);
+               }
+       }
+
+       /*
+        * Pass the user through the unix -> unix user mapping
+        * function.
+        */
+
+       (void)map_username(user);
+
+       /*
+        * Do any UNIX username case mangling.
+        */
+       (void)Get_Pwnam( user, True);
+}
+
 /****************************************************************************
   reply to an special message 
 ****************************************************************************/
@@ -220,17 +265,7 @@ int reply_tcon(connection_struct *conn,
 
        parse_connect(smb_buf(inbuf)+1,service,user,password,&pwlen,dev);
 
-       /*
-        * Pass the user through the NT -> unix user mapping
-        * function.
-        */
-   
-       (void)map_username(user);
-
-       /*
-        * Do any UNIX username case mangling.
-        */
-       (void)Get_Pwnam( user, True);
+       map_nt_and_unix_username(global_myworkgroup, user);
 
        conn = make_connection(service,user,password,pwlen,dev,vuid,&ecode);
   
@@ -300,18 +335,8 @@ int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
        StrnCpy(devicename,path + strlen(path) + 1,6);
        DEBUG(4,("Got device type %s\n",devicename));
 
-       /*
-        * Pass the user through the NT -> unix user mapping
-        * function.
-        */
-       
-       (void)map_username(user);
-       
-       /*
-        * Do any UNIX username case mangling.
-        */
-       (void)Get_Pwnam(user, True);
-       
+       map_nt_and_unix_username(global_myworkgroup, user);
+
        conn = make_connection(service,user,password,passlen,devicename,vuid,&ecode);
        
        if (!conn)
@@ -486,6 +511,7 @@ reply to a session setup command
 int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize)
 {
   uint16 sess_vuid;
+  uchar user_sess_key[16];
   int gid;
   int uid;
   int   smb_bufsize;    
@@ -642,17 +668,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int
 
   pstrcpy( orig_user, user);
 
-  /*
-   * Pass the user through the NT -> unix user mapping
-   * function.
-   */
-   
-  (void)map_username(user);
-
-  /*
-   * Do any UNIX username case mangling.
-   */
-  (void)Get_Pwnam( user, True);
+       map_nt_and_unix_username(domain, user);
 
   add_session_user(user);
 
@@ -691,13 +707,13 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int
 
     if(smb_ntpasslen)
     {
-      if(!password_ok(user, smb_ntpasswd,smb_ntpasslen,NULL))
+      if(!password_ok(user, smb_ntpasswd,smb_ntpasslen,NULL,user_sess_key))
         DEBUG(0,("NT Password did not match ! Defaulting to Lanman\n"));
       else
         valid_nt_password = True;
     } 
 
-    if (!valid_nt_password && !password_ok(user, smb_apasswd,smb_apasslen,NULL))
+    if (!valid_nt_password && !password_ok(user, smb_apasswd,smb_apasslen,NULL,user_sess_key))
     {
       if (lp_security() >= SEC_USER) 
       {
@@ -735,7 +751,11 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int
     int homes = lp_servicenumber(HOMES_NAME);
     char *home = get_home_dir(user);
     if (homes >= 0 && home)
-      lp_add_home(user,homes,home);
+       {
+               pstring home_dir;
+               fstrcpy(home_dir, home);
+               lp_add_home(user,homes,home_dir);
+       }
   }
 
 
@@ -772,7 +792,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int
 
   /* register the name and uid as being validated, so further connections
      to a uid can get through without a password, on the same VC */
-  sess_vuid = register_vuid(uid,gid,user,sesssetup_user,guest);
+  sess_vuid = register_vuid(uid,gid,user,sesssetup_user,guest,user_sess_key);
  
   SSVAL(outbuf,smb_uid,sess_vuid);
   SSVAL(inbuf,smb_uid,sess_vuid);