summaryrefslogtreecommitdiff
path: root/source/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1997-09-19 17:12:08 +0000
committerJeremy Allison <jra@samba.org>1997-09-19 17:12:08 +0000
commit97ed4fea67095dfb83227e7b5fffc236ff277e02 (patch)
treee2f69503102450f7da94b28183775adfb81a37d7 /source/lib
parenteeb0e883536954adb090269a520a913b1676d59c (diff)
downloadsamba-97ed4fea67095dfb83227e7b5fffc236ff277e02.tar.gz
Makefile: Changed proto: target to not include c files not used currently.
Caused proto.h to be from a sorted list of C files. arcfour.h: Added prototypes. client.c: Added username%password in environment patch from John Blair <jdblair@frodo.tucc.uab.edu> loadparm.c: Added username manipulation code from Peter McCool [SMTP:peter@qimr.edu.au] username.c: Added username manipulation code from Peter McCool [SMTP:peter@qimr.edu.au] mkproto.awk: Added arc4_key type. proto.h: Updated & sorted. Jeremy (jallison@whistle.com)
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/username.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/source/lib/username.c b/source/lib/username.c
index b8d152c83fd..a78a344eb89 100644
--- a/source/lib/username.c
+++ b/source/lib/username.c
@@ -22,6 +22,9 @@
#include "includes.h"
extern int DEBUGLEVEL;
+/* internal functions - modified versions of the ones in password.c */
+static struct passwd *uname_string_combinations(char *s, struct passwd * (*fn) (), int N);
+static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (), int N);
/****************************************************************************
get a users home directory. tries as-is then lower case
@@ -141,6 +144,8 @@ Note that this changes user!
struct passwd *Get_Pwnam(char *user,BOOL allow_change)
{
fstring user2;
+ int last_char;
+ int usernamelevel = lp_usernamelevel();
struct passwd *ret;
@@ -172,6 +177,19 @@ struct passwd *Get_Pwnam(char *user,BOOL allow_change)
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]);
+ DEBUG(3, ("Trying username %s\n", user));
+ 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)
strcpy(user,user2);
@@ -250,4 +268,57 @@ BOOL user_in_list(char *user,char *list)
return(False);
}
+/* The functions below have been taken from password.c and slightly modified */
+/****************************************************************************
+apply a function to upper/lower case combinations
+of a string and return true if one of them returns true.
+try all combinations with N uppercase letters.
+offset is the first char to try and change (start with 0)
+it assumes the string starts lowercased
+****************************************************************************/
+static struct passwd *uname_string_combinations2(char *s,int offset,struct passwd *(*fn)(),int N)
+{
+ int len = strlen(s);
+ int i;
+ struct passwd *ret;
+
+#ifdef PASSWORD_LENGTH
+ len = MIN(len,PASSWORD_LENGTH);
+#endif
+
+ if (N <= 0 || offset >= len)
+ return(fn(s));
+
+ for (i=offset;i<(len-(N-1));i++)
+
+ {
+ char c = s[i];
+ if (!islower(c)) continue;
+ s[i] = toupper(c);
+ ret = uname_string_combinations2(s,i+1,fn,N-1);
+ if(ret) return(ret);
+ s[i] = c;
+ }
+ return(NULL);
+}
+
+/****************************************************************************
+apply a function to upper/lower case combinations
+of a string and return true if one of them returns true.
+try all combinations with up to N uppercase letters.
+offset is the first char to try and change (start with 0)
+it assumes the string starts lowercased
+****************************************************************************/
+static struct passwd * uname_string_combinations(char *s,struct passwd * (*fn)(),int N)
+{
+ int n;
+ struct passwd *ret;
+
+ for (n=1;n<=N;n++)
+ {
+ ret = uname_string_combinations2(s,0,fn,n);
+ if(ret) return(ret);
+ }
+ return(NULL);
+}