*/
#include "includes.h"
+#include "system/passwd.h"
#include "memcache.h"
+#include "../lib/util/util_pw.h"
/* internal functions */
static struct passwd *uname_string_combinations(char *s, TALLOC_CTX *mem_ctx,
return tcopy_passwd(mem_ctx, pw);
}
- pw = sys_getpwnam(name);
+ pw = getpwnam(name);
if (pw == NULL) {
return NULL;
}
return tcopy_passwd(mem_ctx, pw);
}
-/****************************************************************************
- talloc copy a struct passwd.
-****************************************************************************/
-
-struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from)
-{
- struct passwd *ret = TALLOC_P(mem_ctx, struct passwd);
- if (!ret) {
- return NULL;
- }
- ret->pw_name = talloc_strdup(ret, from->pw_name);
- ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
- ret->pw_uid = from->pw_uid;
- ret->pw_gid = from->pw_gid;
- ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
- ret->pw_dir = talloc_strdup(ret, from->pw_dir);
- ret->pw_shell = talloc_strdup(ret, from->pw_shell);
- return ret;
-}
-
/****************************************************************************
Flush all cached passwd structs.
****************************************************************************/
memcache_flush(NULL, GETPWNAM_CACHE);
}
-/****************************************************************************
- talloc'ed version of getpwuid.
-****************************************************************************/
-
-struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
-{
- struct passwd *temp = sys_getpwuid(uid);
-
- if (!temp) {
- return NULL;
- }
-
- return tcopy_passwd(mem_ctx, temp);
-}
-
/****************************************************************************
Get a users home directory.
****************************************************************************/
}
/****************************************************************************
- * A wrapper for sys_getpwnam(). The following variations are tried:
+ * A wrapper for getpwnam(). The following variations are tried:
* - as transmitted
* - in all lower case if this differs from transmitted
* - in all upper case if this differs from transmitted
/* Try in all lower case first as this is the most
common case on UNIX systems */
- strlower_m(user2);
+ if (!strlower_m(user2)) {
+ DEBUG(5,("strlower_m %s failed\n", user2));
+ goto done;
+ }
+
DEBUG(5,("Trying _Get_Pwnam(), username as lowercase is %s\n",user2));
ret = getpwnam_alloc_cached(mem_ctx, user2);
if(ret)
}
/* Try as uppercase, if username wasn't originally uppercase */
- strupper_m(user2);
+ if (!strupper_m(user2)) {
+ goto done;
+ }
+
if(strcmp(user, user2) != 0) {
DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n",
user2));
}
/* Try all combinations up to usernamelevel */
- strlower_m(user2);
+ if (!strlower_m(user2)) {
+ DEBUG(5,("strlower_m %s failed\n", user2));
+ goto done;
+ }
DEBUG(5,("Checking combinations of %d uppercase letters in %s\n",
lp_usernamelevel(), user2));
ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc_cached,
for (i=offset;i<(len-(N-1));i++) {
char c = s[i];
- if (!islower_ascii((int)c))
+ if (!islower_m((int)c))
continue;
- s[i] = toupper_ascii(c);
+ s[i] = toupper_m(c);
ret = uname_string_combinations2(s, mem_ctx, i+1, fn, N-1);
if(ret)
return(ret);