From c03f6b32a3f07f429b645f4647d3c7d8f2241999 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 22 Jul 2005 17:45:39 +0000 Subject: r8716: adding 'username map script' which if defined takes precendence over the username map file. (This used to be commit 46f2897fdc1f9308f2cc15834c8b039c17c34707) --- source3/lib/username.c | 69 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 15 deletions(-) (limited to 'source3/lib/username.c') diff --git a/source3/lib/username.c b/source3/lib/username.c index e691e4c1f1..1973a8c7c6 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -93,7 +93,7 @@ char *get_user_home_dir(const char *user) Returns True if username was changed, false otherwise. ********************************************************************/ -BOOL map_username(char *user) +BOOL map_username(fstring user) { static BOOL initialised=False; static fstring last_from,last_to; @@ -102,18 +102,11 @@ BOOL map_username(char *user) char *s; pstring buf; BOOL mapped_user = False; - + char *cmd = lp_username_map_script(); + if (!*user) return False; - - if (!*mapfile) - return False; - - if (!initialised) { - *last_from = *last_to = 0; - initialised = True; - } - + if (strequal(user,last_to)) return False; @@ -122,6 +115,52 @@ BOOL map_username(char *user) fstrcpy(user,last_to); return True; } + + /* first try the username map script */ + + if ( *cmd ) { + char **qlines; + pstring command; + int numlines, ret, fd; + + pstr_sprintf( command, "%s \"%s\"", cmd, user ); + + DEBUG(10,("Running [%s]\n", command)); + ret = smbrun(command, &fd); + DEBUGADD(10,("returned [%d]\n", ret)); + + if ( ret != 0 ) { + if (fd != -1) + close(fd); + return False; + } + + numlines = 0; + qlines = fd_lines_load(fd, &numlines); + DEBUGADD(10,("Lines returned = [%d]\n", numlines)); + close(fd); + + /* should be either no lines or a single line with the mapped username */ + + if (numlines) { + DEBUG(3,("Mapped user %s to %s\n", user, qlines[0] )); + fstrcpy( user, qlines[0] ); + } + + file_lines_free(qlines); + + return numlines != 0; + } + + /* ok. let's try the mapfile */ + + if (!*mapfile) + return False; + + if (!initialised) { + *last_from = *last_to = 0; + initialised = True; + } f = x_fopen(mapfile,O_RDONLY, 0); if (!f) { @@ -172,10 +211,10 @@ BOOL map_username(char *user) if (strchr_m(dosname,'*') || user_in_list(user, (const char **)dosuserlist, NULL, 0)) { DEBUG(3,("Mapped user %s to %s\n",user,unixname)); mapped_user = True; - fstrcpy(last_from,user); - sscanf(unixname,"%s",user); - fstrcpy(last_to,user); - if(return_if_mapped) { + fstrcpy( last_from,user ); + fstrcpy( user, unixname ); + fstrcpy( last_to,user ); + if ( return_if_mapped ) { str_list_free (&dosuserlist); x_fclose(f); return True; -- cgit