Winbind and creating homedirs.

Johan Bergström johan.bergstrom at tietoenator.com
Tue Jun 29 17:15:00 GMT 2004


Hello.

We are running Samba 3.0.4 in AIX 5.1 and using winbind to authenticate 
users against our AD for them to login using telnet. We have a slight
problem, when a user login and doesn't have a homedir, it's put in / as
default.

I've tried to make a little change to nsswitch/winbindd_user.c to make a
homedir if it doesn't exist, but when I modified the code we started to
get other strange errors like winbindd crashing and loosing connection
with the DC. The code I added was in the  winbindd_fill_pwent()
function, and something like this with + in front of it,



+	char *hometemp;
+	struct stat pstat;

---

        fstrcpy(current_user_info.domain, dom_name);

        homedir = alloc_sub_specified(lp_template_homedir(), user_name,
dom_name, pw->pw_uid, pw->pw_gid);

+        /* Create homedir for the user if it doesn't exist - Johan
Bergstrom 2004-06-29 TE */

+        fstr_sprintf(hometemp, "/home/%s/%s", dom_name, user_name);
+        DEBUG(3, ("hometemp = %s\n homedir = %s\n", hometemp,homedir));

+        if (stat(hometemp,&pstat)<0) {
+                DEBUG(3, ("creating homedir %s\n", hometemp));
+                if (mkdir(hometemp,S_IRWXU)<0) {
+                        DEBUG(3, ("mkhomedir failed on %s\n",
hometemp));
+                } else {
+                        DEBUG(3, ("chowning %s to %d:%d\n", hometemp,
pw->pw_uid, pw->pw_gid));
+                        if (chown(hometemp,pw->pw_uid,pw->pw_gid)<0)
+                        DEBUG(3, ("chown failed on %s for %s:%s\n",
hometemp, pw->pw_uid, pw->pw_gid));
+                }
+        } else {
+                DEBUG(3, ("homedir %s exists, not creating\.n",
+hometemp));
+        }

        if (!homedir) {
+                safe_strcpy(homedir, hometemp, sizeof(homedir) - 1);
+                safe_strcpy(pw->pw_dir, homedir, sizeof(pw->pw_dir) -
1);
+        } else {
                safe_strcpy(pw->pw_dir, homedir, sizeof(pw->pw_dir) -
1);
+        }

        SAFE_FREE(homedir);
+        SAFE_FREE(hometemp);

+        /* End create homedir */


I'm aware that this might not be the best place to add this code, and
the reason I'm doing it is because we're having some problems with PAM
in AIX, so we can't really use pam_mkhomedir either.

I'd like to do some other modifications like create a default .profile
in the users homedir. But that's no biggie when I get it working, ie put
the code in the proper place. Anyone have any ideas why it starts acting
weird, and where I could this code instead of in winbindd_user.c ?



More information about the samba-technical mailing list