summaryrefslogtreecommitdiff
path: root/source/nsswitch/wb_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/nsswitch/wb_client.c')
-rw-r--r--source/nsswitch/wb_client.c101
1 files changed, 53 insertions, 48 deletions
diff --git a/source/nsswitch/wb_client.c b/source/nsswitch/wb_client.c
index 6ade637c8c2..843b85c0c7b 100644
--- a/source/nsswitch/wb_client.c
+++ b/source/nsswitch/wb_client.c
@@ -32,28 +32,24 @@ NSS_STATUS winbindd_request(int req_type,
/* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
form DOMAIN/user into a domain and a user */
-static void parse_domain_user(char *domuser, fstring domain, fstring user)
+static BOOL parse_domain_user(char *domuser, fstring domain, fstring user)
{
- char *p;
- char *sep = lp_winbind_separator();
- if (!sep) sep = "\\";
- p = strchr(domuser,*sep);
- if (!p) p = strchr(domuser,'\\');
- if (!p) {
- fstrcpy(domain,"");
- fstrcpy(user, domuser);
- return;
- }
+ char *p = strchr(domuser,*lp_winbind_separator());
+
+ if (!p)
+ return False;
fstrcpy(user, p+1);
fstrcpy(domain, domuser);
domain[PTR_DIFF(p, domuser)] = 0;
strupper(domain);
+ return True;
}
/* Call winbindd to convert a name to a sid */
-BOOL winbind_lookup_name(const char *name, DOM_SID *sid, enum SID_NAME_USE *name_type)
+BOOL winbind_lookup_name(const char *name, DOM_SID *sid,
+ enum SID_NAME_USE *name_type)
{
struct winbindd_request request;
struct winbindd_response response;
@@ -62,6 +58,13 @@ BOOL winbind_lookup_name(const char *name, DOM_SID *sid, enum SID_NAME_USE *name
if (!sid || !name_type)
return False;
+ /*
+ * Don't do the lookup if the name has no separator.
+ */
+
+ if (!strchr(name, *lp_winbind_separator()))
+ return False;
+
/* Send off request */
ZERO_STRUCT(request);
@@ -80,7 +83,8 @@ BOOL winbind_lookup_name(const char *name, DOM_SID *sid, enum SID_NAME_USE *name
/* Call winbindd to convert sid to name */
-BOOL winbind_lookup_sid(DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAME_USE *name_type)
+BOOL winbind_lookup_sid(DOM_SID *sid, fstring dom_name, fstring name,
+ enum SID_NAME_USE *name_type)
{
struct winbindd_request request;
struct winbindd_response response;
@@ -104,7 +108,9 @@ BOOL winbind_lookup_sid(DOM_SID *sid, fstring dom_name, fstring name, enum SID_N
if (result == NSS_STATUS_SUCCESS) {
parse_domain_user(response.data.name.name, dom_name, name);
*name_type = (enum SID_NAME_USE)response.data.name.type;
- DEBUG(10,("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", sid_str, dom_name, name ));
+
+ DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n",
+ sid_str, dom_name, name));
}
return (result == NSS_STATUS_SUCCESS);
@@ -245,7 +251,7 @@ BOOL winbind_gid_to_sid(DOM_SID *sid, gid_t gid)
/* Fetch the list of groups a user is a member of from winbindd. This is
used by winbind_initgroups and winbind_getgroups. */
-static int wb_getgroups(char *user, gid_t **groups)
+static int wb_getgroups(const char *user, gid_t **groups)
{
struct winbindd_request request;
struct winbindd_response response;
@@ -281,13 +287,10 @@ int winbind_initgroups(char *user, gid_t gid)
{
gid_t *tgr, *groups = NULL;
int result;
- char *sep;
/* Call normal initgroups if we are a local user */
- sep = lp_winbind_separator();
-
- if (!strchr(user, *sep)) {
+ if (!strchr(user, *lp_winbind_separator())) {
return initgroups(user, gid);
}
@@ -317,8 +320,8 @@ int winbind_initgroups(char *user, gid_t gid)
errno = ENOMEM;
result = -1;
goto done;
- } else
- groups = tgr;
+ }
+ else groups = tgr;
groups[ngroups] = gid;
ngroups++;
@@ -343,7 +346,7 @@ int winbind_initgroups(char *user, gid_t gid)
/* Free response data if necessary */
done:
- safe_free(groups);
+ SAFE_FREE(groups);
return result;
}
@@ -353,16 +356,24 @@ int winbind_initgroups(char *user, gid_t gid)
time consuming. If size is zero, list is not modified and the total
number of groups for the user is returned. */
-int winbind_getgroups(char *user, int size, gid_t *list)
+int winbind_getgroups(const char *user, int size, gid_t *list)
{
gid_t *groups = NULL;
int result, i;
+ /*
+ * Don't do the lookup if the name has no separator.
+ */
+
+ if (!strchr(user, *lp_winbind_separator()))
+ return -1;
+
/* Fetch list of groups */
result = wb_getgroups(user, &groups);
- if (size == 0) goto done;
+ if (size == 0)
+ goto done;
if (result > size) {
result = -1;
@@ -377,13 +388,11 @@ int winbind_getgroups(char *user, int size, gid_t *list)
}
done:
- safe_free(groups);
+ SAFE_FREE(groups);
return result;
}
-/**********************************************************************************
- Utility function. Convert a uid_t to a name if possible.
-**********************************************************************************/
+/* Utility function. Convert a uid_t to a name if possible. */
BOOL winbind_uidtoname(fstring name, uid_t uid)
{
@@ -400,13 +409,13 @@ BOOL winbind_uidtoname(fstring name, uid_t uid)
if (name_type != SID_NAME_USER)
return False;
- slprintf(name, sizeof(fstring)-1, "%s%s%s", dom_name, lp_winbind_separator(), user_name );
+ slprintf(name, sizeof(fstring)-1, "%s%s%s", dom_name,
+ lp_winbind_separator(), user_name);
+
return True;
}
-/**********************************************************************************
- Utility function. Convert a gid_t to a name if possible.
-**********************************************************************************/
+/* Utility function. Convert a gid_t to a name if possible. */
BOOL winbind_gidtoname(fstring name, gid_t gid)
{
@@ -420,25 +429,24 @@ BOOL winbind_gidtoname(fstring name, gid_t gid)
if (!winbind_lookup_sid(&sid, dom_name, group_name, &name_type))
return False;
- if (name_type != SID_NAME_USER)
+ if (name_type != SID_NAME_DOM_GRP)
return False;
- slprintf(name, sizeof(fstring)-1, "%s%s%s", dom_name, lp_winbind_separator(), group_name );
+ slprintf(name, sizeof(fstring)-1, "%s%s%s", dom_name,
+ lp_winbind_separator(), group_name);
+
return True;
}
-/**********************************************************************************
- Utility function. Convert a name to a uid_t if possible.
-**********************************************************************************/
+/* Utility function. Convert a name to a uid_t if possible. */
-BOOL winbind_nametouid(uid_t *puid, char *name)
+BOOL winbind_nametouid(uid_t *puid, const char *name)
{
DOM_SID sid;
enum SID_NAME_USE name_type;
- if (!winbind_lookup_name(name, &sid, &name_type)) {
- return False;
- }
+ if (!winbind_lookup_name(name, &sid, &name_type))
+ return False;
if (name_type != SID_NAME_USER)
return False;
@@ -446,18 +454,15 @@ BOOL winbind_nametouid(uid_t *puid, char *name)
return winbind_sid_to_uid(puid, &sid);
}
-/**********************************************************************************
- Utility function. Convert a name to a gid_t if possible.
-**********************************************************************************/
+/* Utility function. Convert a name to a gid_t if possible. */
-BOOL winbind_nametogid(gid_t *pgid, char *gname)
+BOOL winbind_nametogid(gid_t *pgid, const char *gname)
{
DOM_SID g_sid;
enum SID_NAME_USE name_type;
- if (!winbind_lookup_name(gname, &g_sid, &name_type)) {
- return False;
- }
+ if (!winbind_lookup_name(gname, &g_sid, &name_type))
+ return False;
if (name_type != SID_NAME_DOM_GRP)
return False;