summaryrefslogtreecommitdiffstats
path: root/source/lib/username.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-12-11 17:48:26 +0000
committerGerald Carter <jerry@samba.org>2000-12-11 17:48:26 +0000
commit059f4fee5d8ad72cd699995c660263ed2cc4f25f (patch)
treeeea65e3adc065ca6535edbc28bc6aee5e144f45f /source/lib/username.c
parent71e5e802b78b22af9be7d3e84e869f311937e542 (diff)
downloadsamba-059f4fee5d8ad72cd699995c660263ed2cc4f25f.tar.gz
samba-059f4fee5d8ad72cd699995c660263ed2cc4f25f.tar.xz
samba-059f4fee5d8ad72cd699995c660263ed2cc4f25f.zip
new version of Get_Pwnam()
o check the username in all lowercase o check the username as transmitted if this would be a different case o check the username in all upper case if this is a new version -- jerry
Diffstat (limited to 'source/lib/username.c')
-rw-r--r--source/lib/username.c102
1 files changed, 50 insertions, 52 deletions
diff --git a/source/lib/username.c b/source/lib/username.c
index 0665e3db795..7ba7b647e93 100644
--- a/source/lib/username.c
+++ b/source/lib/username.c
@@ -169,67 +169,65 @@ static struct passwd *_Get_Pwnam(char *s)
/****************************************************************************
- A wrapper for getpwnam() that tries with all lower and all upper case
- if the initial name fails. Also tried with first letter capitalised
+ A wrapper for getpwnam(). The following variations are tried...
+ - in all lower case
+ - as transmitted IF a different case
+ - in all upper case IF that is different from the transmitted username
+ - using the lp_usernamelevel() for permutations
Note that this can change user!
****************************************************************************/
struct passwd *Get_Pwnam(char *user,BOOL allow_change)
{
- fstring user2;
- int last_char;
- int usernamelevel = lp_usernamelevel();
-
- struct passwd *ret;
-
- if (!user || !(*user))
- return(NULL);
+ fstring user2, orig_username;
+ int usernamelevel = lp_usernamelevel();
+ struct passwd *ret;
+
+ if (!user || !(*user))
+ return(NULL);
+
+ /* make a few copies to work with */
+ fstrcpy(orig_username, user);
+ if (!allow_change)
+ {
+ /* allow_change was False, so make a copy and temporarily
+ assign the char* user to the temp copy */
+ fstrcpy(user2,user);
+ user = &user2[0];
+ }
- StrnCpy(user2,user,sizeof(user2)-1);
+ /* try in all lower case first as this is the most
+ common case on UNIX systems */
+ strlower(user);
+ ret = _Get_Pwnam(user);
+ if (ret)
+ return(ret);
+
+ /* try as transmitted, but only if the original username
+ gives us a different case */
+ if (strcmp(user, orig_username) != 0)
+ {
+ ret = _Get_Pwnam(orig_username);
+ if (ret)
+ return(ret);
+ }
- if (!allow_change) {
- user = &user2[0];
- }
+ /* finally, try in all caps if that is a new case */
+ strupper(user);
+ if (strcmp(user, orig_username) != 0)
+ {
+ ret = _Get_Pwnam(user);
+ if (ret)
+ return(ret);
+ }
- ret = _Get_Pwnam(user);
- if (ret)
- return(ret);
-
- strlower(user);
- ret = _Get_Pwnam(user);
- if (ret)
- return(ret);
-
- strupper(user);
- ret = _Get_Pwnam(user);
- if (ret)
- return(ret);
-
- /* Try with first letter capitalised. */
- if (strlen(user) > 1)
- strlower(user+1);
- ret = _Get_Pwnam(user);
- if (ret)
- return(ret);
-
- /* try with last letter capitalised */
- strlower(user);
- last_char = strlen(user)-1;
- user[last_char] = toupper(user[last_char]);
- ret = _Get_Pwnam(user);
- if (ret)
- return(ret);
-
- /* Try all combinations up to usernamelevel. */
- strlower(user);
- ret = uname_string_combinations(user, _Get_Pwnam, usernamelevel);
- if (ret)
- return(ret);
-
- if (allow_change)
- fstrcpy(user,user2);
+ /* Try all combinations up to usernamelevel. */
+ strlower(user);
+ ret = uname_string_combinations(user, _Get_Pwnam, usernamelevel);
+ if (ret)
+ return(ret);
- return(NULL);
+ return(NULL);
}
/****************************************************************************