patch for winbind: Convert username spaces to underscore

mjd at alphalink.com.au mjd at alphalink.com.au
Tue May 14 21:38:01 GMT 2002


Hi,

We use winbind from Samba 2.2.3a on our Linux
CVS server so that PC users can authenticate to
the CVS servers using their Windows usernames.

We use this option in smb.conf for calculating
our home directories:

   template homedir = "/home/%D/%U"
 
One problem is that usernames here have spaces
in them, eg, my username is "mitch davis".  This
leads to a home directory of "/home/MYCOMPANY/mitch davis",
which causes grief to many Linux programs.

I made a patch for winbind which adds a
"template sanitizehomedir" option.  If this option
is on, then when the home directory is determined,
whitespace is replaced with underscores, eg, my
home dir becomes "/home/MYCOMPANY/mitch_davis".
Unix programs like this a lot better.

We have used this patch for about a month, and it
has worked with no problems.

Now my questions:

 - Does anyone else use usernames with spaces?
   What do you do about it?

 - How else could this problem be solved?  What
   would the experts here recommend?

 - If this way is a good way, should "template
   sanitizehomedir = true" be the default?

 - What should I do with my patch?

 - If you like it, where and how should I document
   it?

The attached patch is against today's CVS snapshot.
I have a release from my boss to distribute it.

Any help you could give me would be greatly appreciated.

Regards,

Mitch.
-------------- next part --------------
diff -u -r -x *.orig samba-orig/source/nsswitch/winbindd_user.c samba/source/nsswitch/winbindd_user.c
--- samba-orig/source/nsswitch/winbindd_user.c	Fri Mar 22 11:03:52 2002
+++ samba/source/nsswitch/winbindd_user.c	Wed May 15 14:26:41 2002
@@ -23,6 +23,21 @@
 
 #include "winbindd.h"
 
+/* Replace the whitespace in a homedir with underscores. */
+
+static void winbindd_sanitize_homedir(char *homedir)
+{
+	char *p;
+
+	DEBUG(4, ("winbindd_sanitize_homedir: before: %s\n", homedir));
+	for (p = homedir; *p != 0; p++) {
+		if (!isgraph(*p)) {
+			*p = '_';
+		}
+	}
+	DEBUG(4, ("winbindd_sanitize_homedir: after: %s\n", homedir));
+}
+
 /* Fill a pwent structure with information we have obtained */
 
 static BOOL winbindd_fill_pwent(char *dom_name, char *user_name, 
@@ -73,6 +88,9 @@
 	fstrcpy(current_user_info.domain, dom_name);
 
 	pstrcpy(homedir, lp_template_homedir());
+	
+	if (lp_winbind_sanitize_homedir())
+		winbindd_sanitize_homedir(homedir);
 	
 	safe_strcpy(pw->pw_dir, homedir, sizeof(pw->pw_dir) - 1);
 	
diff -u -r -x *.orig samba-orig/source/param/loadparm.c samba/source/param/loadparm.c
--- samba-orig/source/param/loadparm.c	Wed May 15 00:02:57 2002
+++ samba/source/param/loadparm.c	Wed May 15 14:26:41 2002
@@ -167,6 +167,7 @@
 	char *szWinbindUID;
 	char *szWinbindGID;
 	char *szTemplateHomedir;
+	BOOL bSanitizeHomedir;
 	char *szTemplateShell;
 	char *szWinbindSeparator;
 	BOOL bWinbindEnumUsers;
@@ -1092,6 +1093,7 @@
 	{"winbind uid", P_STRING, P_GLOBAL, &Globals.szWinbindUID, handle_winbind_uid, NULL, 0},
 	{"winbind gid", P_STRING, P_GLOBAL, &Globals.szWinbindGID, handle_winbind_gid, NULL, 0},
 	{"template homedir", P_STRING, P_GLOBAL, &Globals.szTemplateHomedir, NULL, NULL, 0},
+	{"template sanitizehomedir", P_STRING, P_GLOBAL, &Globals.bSanitizeHomedir, NULL, NULL, 0},
 	{"template shell", P_STRING, P_GLOBAL, &Globals.szTemplateShell, NULL, NULL, 0},
 	{"winbind separator", P_STRING, P_GLOBAL, &Globals.szWinbindSeparator, NULL, NULL, 0},
 	{"winbind cache time", P_INTEGER, P_GLOBAL, &Globals.winbind_cache_time, NULL, NULL, 0},
@@ -1565,6 +1567,7 @@
 FN_GLOBAL_STRING(lp_domain_admin_group, &Globals.szDomainAdminGroup)
 FN_GLOBAL_STRING(lp_domain_guest_group, &Globals.szDomainGuestGroup)
 FN_GLOBAL_STRING(lp_template_homedir, &Globals.szTemplateHomedir)
+FN_GLOBAL_BOOL(lp_winbind_sanitize_homedir, &Globals.bSanitizeHomedir)
 FN_GLOBAL_STRING(lp_template_shell, &Globals.szTemplateShell)
 FN_GLOBAL_STRING(lp_winbind_separator, &Globals.szWinbindSeparator)
 FN_GLOBAL_BOOL(lp_winbind_enum_users, &Globals.bWinbindEnumUsers)



More information about the samba-technical mailing list