summaryrefslogtreecommitdiff
path: root/source3/lib/username.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2001-10-29 07:28:32 +0000
committerAndrew Bartlett <abartlet@samba.org>2001-10-29 07:28:32 +0000
commit2038649e51f48a489aeec49947e1b791f0b3df43 (patch)
treeb3df7e09c5d563306f9a1b359a4b2579829b1a01 /source3/lib/username.c
parent0db1899256517507fb5a441bd75725e3fcecc2e8 (diff)
downloadsamba-2038649e51f48a489aeec49947e1b791f0b3df43.tar.gz
samba-2038649e51f48a489aeec49947e1b791f0b3df43.tar.bz2
samba-2038649e51f48a489aeec49947e1b791f0b3df43.zip
This commit is number 3 of 4.
In particular this commit focuses on: Changing the Get_Pwnam code so that it can work in a const-enforced environment. While these changes have been mildly tested, and are pretty small, any assistance in this is appreciated. ---- These changes allow for 'const' in the Samba tree. There are a number of good reasons to do this: - I want to allow the SAM_ACCOUNT structure to move from wasteful pstrings and fstrings to allocated strings. We can't do that if people are modifying these outputs, as they may well make assumptions about getting pstrings and fstrings - I want --with-pam_smbpass to compile with a slightly sane volume of warnings, currently its pretty bad, even in 2.2 where is compiles at all. - Tridge assures me that he no longer opposes 'const religion' based on the ability to #define const the problem away. - Changed Get_Pwnam(x,y) into two variants (so that the const parameter can work correctly): - Get_Pwnam(const x) and Get_Pwnam_Modify(x). - Reworked smbd/chgpasswd.c to work with these mods, passing around a 'struct passwd' rather than the modified username (This used to be commit e7634f81c5116ff4addfb7e495f54b6bb78e8f77)
Diffstat (limited to 'source3/lib/username.c')
-rw-r--r--source3/lib/username.c77
1 files changed, 58 insertions, 19 deletions
diff --git a/source3/lib/username.c b/source3/lib/username.c
index 24195b196b..074e6c8992 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -22,18 +22,18 @@
#include "includes.h"
/* internal functions */
-static struct passwd *uname_string_combinations(char *s, struct passwd * (*fn) (char *), int N);
-static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (char *), int N);
+static struct passwd *uname_string_combinations(char *s, struct passwd * (*fn) (const char *), int N);
+static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (const char *), int N);
/****************************************************************************
Get a users home directory.
****************************************************************************/
-char *get_user_home_dir(char *user)
+char *get_user_home_dir(const char *user)
{
static struct passwd *pass;
- pass = Get_Pwnam(user, False);
+ pass = Get_Pwnam(user);
if (!pass) return(NULL);
return(pass->pw_dir);
@@ -158,7 +158,7 @@ BOOL map_username(char *user)
Get_Pwnam wrapper
****************************************************************************/
-static struct passwd *_Get_Pwnam(char *s)
+static struct passwd *_Get_Pwnam(const char *s)
{
struct passwd *ret;
@@ -183,18 +183,16 @@ static struct passwd *_Get_Pwnam(char *s)
* - in all lower case if this differs from transmitted
* - in all upper case if this differs from transmitted
* - using lp_usernamelevel() for permutations.
- * NOTE: This can potentially modify 'user' depending on value of
- * allow_change!
*/
-struct passwd *Get_Pwnam(char *user,BOOL allow_change)
+struct passwd *Get_Pwnam_internals(const char *user, char *user2)
{
- fstring user2;
struct passwd *ret = NULL;
- if (!user || !(*user))
+ if (!user2 || !(*user2))
return(NULL);
- fstrcpy(user2, user);
+ if (!user || !(*user))
+ return(NULL);
/* Try in all lower case first as this is the most
common case on UNIX systems */
@@ -228,19 +226,53 @@ struct passwd *Get_Pwnam(char *user,BOOL allow_change)
done:
DEBUG(5,("Get_Pwnam %s find a valid username!\n",ret ? "did":"didn't"));
+ return ret;
+}
+
+/****************************************************************************
+ Get_Pwnam wrapper for modification.
+ NOTE: This can potentially modify 'user'!
+****************************************************************************/
+
+struct passwd *Get_Pwnam_Modify(char *user)
+{
+ fstring user2;
+ struct passwd *ret;
+
+ fstrcpy(user2, user);
+
+ ret = Get_Pwnam_internals(user, user2);
+
/* If caller wants the modified username, ensure they get it */
- if(allow_change)
- fstrcpy(user,user2);
+ fstrcpy(user,user2);
/* We can safely assume ret is NULL if none of the above succeed */
return(ret);
}
/****************************************************************************
+ Get_Pwnam wrapper without modification.
+ NOTE: This with NOT modify 'user'!
+****************************************************************************/
+
+struct passwd *Get_Pwnam(const char *user)
+{
+ fstring user2;
+ struct passwd *ret;
+
+ fstrcpy(user2, user);
+
+ ret = Get_Pwnam_internals(user, user2);
+
+ /* We can safely assume ret is NULL if none of the above succeed */
+ return(ret);
+}
+
+/****************************************************************************
Check if a user is in a netgroup user list.
****************************************************************************/
-static BOOL user_in_netgroup_list(char *user,char *ngname)
+static BOOL user_in_netgroup_list(const char *user, const char *ngname)
{
#ifdef HAVE_NETGROUP
static char *mydomain = NULL;
@@ -333,11 +365,11 @@ failed with error %s\n", strerror(errno) ));
Check if a user is in a UNIX group.
****************************************************************************/
-static BOOL user_in_unix_group_list(char *user,char *gname)
+static BOOL user_in_unix_group_list(const char *user,const char *gname)
{
struct group *gptr;
char **member;
- struct passwd *pass = Get_Pwnam(user,False);
+ struct passwd *pass = Get_Pwnam(user);
DEBUG(10,("user_in_unix_group_list: checking user %s in group %s\n", user, gname));
@@ -532,7 +564,11 @@ struct passwd *smb_getpwnam(char *user, BOOL allow_change)
char *sep;
extern pstring global_myname;
- pw = Get_Pwnam(user, allow_change);
+ if (allow_change) {
+ pw = Get_Pwnam_Modify(user);
+ } else {
+ pw = Get_Pwnam(user);
+ }
if (pw) return pw;
/* if it is a domain qualified name and it isn't in our password
@@ -543,8 +579,11 @@ struct passwd *smb_getpwnam(char *user, BOOL allow_change)
p = strchr_m(user,*sep);
if (p &&
strncasecmp(global_myname, user, strlen(global_myname))==0) {
- return Get_Pwnam(p+1, allow_change);
+ if (allow_change) {
+ pw = Get_Pwnam_Modify(p+1);
+ } else {
+ pw = Get_Pwnam(p+1);
+ }
}
-
return NULL;
}