summaryrefslogtreecommitdiff
path: root/source3/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
commita2d2206cc941f39df8713d9cee26099f603af82f (patch)
treed438f8496920c07242d3c839767711c0a1e8d58c /source3/lib
parent1aa8036b451412c00503a791ae6e0600491b2ca0 (diff)
downloadsamba-a2d2206cc941f39df8713d9cee26099f603af82f.tar.gz
samba-a2d2206cc941f39df8713d9cee26099f603af82f.tar.bz2
samba-a2d2206cc941f39df8713d9cee26099f603af82f.zip
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) (This used to be commit 97ed4fea67095dfb83227e7b5fffc236ff277e02)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/username.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/source3/lib/username.c b/source3/lib/username.c
index b8d152c83f..a78a344eb8 100644
--- a/source3/lib/username.c
+++ b/source3/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);
+}