diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/username.c | 69 | ||||
-rw-r--r-- | source3/param/loadparm.c | 3 |
2 files changed, 57 insertions, 15 deletions
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; diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index ae5af60e46..00f191db28 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -159,6 +159,7 @@ typedef struct char *szAddMachineScript; char *szShutdownScript; char *szAbortShutdownScript; + char *szUsernameMapScript; char *szCheckPasswordScript; char *szWINSHook; char *szWINSPartners; @@ -1071,6 +1072,7 @@ static struct parm_struct parm_table[] = { {"add machine script", P_STRING, P_GLOBAL, &Globals.szAddMachineScript, NULL, NULL, FLAG_ADVANCED}, {"shutdown script", P_STRING, P_GLOBAL, &Globals.szShutdownScript, NULL, NULL, FLAG_ADVANCED}, {"abort shutdown script", P_STRING, P_GLOBAL, &Globals.szAbortShutdownScript, NULL, NULL, FLAG_ADVANCED}, + {"username map script", P_STRING, P_GLOBAL, &Globals.szUsernameMapScript, NULL, NULL, FLAG_ADVANCED}, {"logon script", P_STRING, P_GLOBAL, &Globals.szLogonScript, NULL, NULL, FLAG_ADVANCED}, {"logon path", P_STRING, P_GLOBAL, &Globals.szLogonPath, NULL, NULL, FLAG_ADVANCED}, @@ -1755,6 +1757,7 @@ FN_GLOBAL_STRING(lp_addmachine_script, &Globals.szAddMachineScript) FN_GLOBAL_STRING(lp_shutdown_script, &Globals.szShutdownScript) FN_GLOBAL_STRING(lp_abort_shutdown_script, &Globals.szAbortShutdownScript) +FN_GLOBAL_STRING(lp_username_map_script, &Globals.szUsernameMapScript) FN_GLOBAL_STRING(lp_check_password_script, &Globals.szCheckPasswordScript) |