summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2004-02-02 01:46:30 +0000
committerGerald Carter <jerry@samba.org>2004-02-02 01:46:30 +0000
commita870ff546ce9128e3bf8bb3ddc88f5eeb98d2eda (patch)
tree9e2f27eb92aa97692268818a5d3ae4a921f53c13 /source3
parent152e2282164069d63dde7b15f96d637db5a25245 (diff)
downloadsamba-a870ff546ce9128e3bf8bb3ddc88f5eeb98d2eda.tar.gz
samba-a870ff546ce9128e3bf8bb3ddc88f5eeb98d2eda.tar.bz2
samba-a870ff546ce9128e3bf8bb3ddc88f5eeb98d2eda.zip
janitor duty (merges from 3.0) and cleanup compiler warning on SuSE 9 in the end mapper code
(This used to be commit 902d4a647a88d1def09d5b1eacb06ab1561f3dec)
Diffstat (limited to 'source3')
-rw-r--r--source3/groupdb/mapping.c74
-rw-r--r--source3/nsswitch/winbind_nss_linux.c138
-rw-r--r--source3/nsswitch/winbindd_group.c4
-rw-r--r--source3/rpc_parse/parse_epmapper.c96
4 files changed, 232 insertions, 80 deletions
diff --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c
index 97abbd46e3..048a6c5db0 100644
--- a/source3/groupdb/mapping.c
+++ b/source3/groupdb/mapping.c
@@ -701,10 +701,12 @@ BOOL get_group_from_gid(gid_t gid, GROUP_MAP *map)
BOOL get_sid_list_of_group(gid_t gid, DOM_SID **sids, int *num_sids)
{
struct group *grp;
- struct passwd *pwd;
int i=0;
char *gr;
DOM_SID *s;
+
+ struct sys_pwent *userlist;
+ struct sys_pwent *user;
if(!init_group_mapping()) {
DEBUG(0,("failed to initialize group mapping"));
@@ -751,41 +753,53 @@ BOOL get_sid_list_of_group(gid_t gid, DOM_SID **sids, int *num_sids)
winbind_off();
- setpwent();
- while ((pwd=getpwent()) != NULL) {
- if (pwd->pw_gid==gid) {
- SAM_ACCOUNT *group_member_acct = NULL;
- BOOL found_user;
- s = Realloc((*sids), sizeof(**sids)*(*num_sids+1));
- if (!s) {
- DEBUG(0,("get_sid_list_of_group: unable to enlarge SID list!\n"));
- winbind_on();
- return False;
- }
- else (*sids) = s;
+ user = userlist = getpwent_list();
+
+ while (user != NULL) {
+
+ SAM_ACCOUNT *group_member_acct = NULL;
+ BOOL found_user;
+
+ if (user->pw_gid != gid) {
+ user = user->next;
+ continue;
+ }
+
+ s = Realloc((*sids), sizeof(**sids)*(*num_sids+1));
+ if (!s) {
+ DEBUG(0,("get_sid_list_of_group: unable to enlarge "
+ "SID list!\n"));
+ pwent_free(userlist);
+ winbind_on();
+ return False;
+ }
+ else (*sids) = s;
- if (!NT_STATUS_IS_OK(pdb_init_sam(&group_member_acct))) {
- continue;
- }
+ if (!NT_STATUS_IS_OK(pdb_init_sam(&group_member_acct))) {
+ continue;
+ }
- become_root();
- found_user = pdb_getsampwnam(group_member_acct, pwd->pw_name);
- unbecome_root();
+ become_root();
+ found_user = pdb_getsampwnam(group_member_acct, user->pw_name);
+ unbecome_root();
- if (found_user) {
- sid_copy(&(*sids)[*num_sids], pdb_get_user_sid(group_member_acct));
+ if (found_user) {
+ sid_copy(&(*sids)[*num_sids],
+ pdb_get_user_sid(group_member_acct));
+ (*num_sids)++;
+ } else {
+ DEBUG(4,("get_sid_list_of_group: User %s [uid == %lu] "
+ "has no samba account\n",
+ user->pw_name, (unsigned long)user->pw_uid));
+ if (algorithmic_uid_to_sid(&(*sids)[*num_sids],
+ user->pw_uid))
(*num_sids)++;
- } else {
- DEBUG(4,("get_sid_list_of_group: User %s [uid == %lu] has no samba account\n",
- pwd->pw_name, (unsigned long)pwd->pw_uid));
- if (algorithmic_uid_to_sid(&(*sids)[*num_sids], pwd->pw_uid))
- (*num_sids)++;
- }
-
- pdb_free_sam(&group_member_acct);
}
+ pdb_free_sam(&group_member_acct);
+
+ user = user->next;
}
- endpwent();
+ pwent_free(userlist);
DEBUG(10, ("got primary groups, members: [%d]\n", *num_sids));
winbind_on();
diff --git a/source3/nsswitch/winbind_nss_linux.c b/source3/nsswitch/winbind_nss_linux.c
index ac4a861ff1..362047f62b 100644
--- a/source3/nsswitch/winbind_nss_linux.c
+++ b/source3/nsswitch/winbind_nss_linux.c
@@ -1009,3 +1009,141 @@ failed:
free_response(&response);
return ret;
}
+
+/* map a sid to a uid */
+NSS_STATUS
+_nss_winbind_sidtouid(const char *sid, uid_t *uid, int *errnop)
+{
+ NSS_STATUS ret;
+ struct winbindd_response response;
+ struct winbindd_request request;
+
+#ifdef DEBUG_NSS
+ fprintf(stderr, "[%5d]: sidtouid %s\n", getpid(), sid);
+#endif
+
+ ZERO_STRUCT(request);
+ ZERO_STRUCT(response);
+
+ strncpy(request.data.sid, sid, sizeof(request.data.sid) - 1);
+ request.data.sid[sizeof(request.data.sid) - 1] = '\0';
+
+ ret = winbindd_request(WINBINDD_SID_TO_UID, &request, &response);
+ if (ret != NSS_STATUS_SUCCESS) {
+ *errnop = errno = EINVAL;
+ goto failed;
+ }
+
+ *uid = response.data.uid;
+
+failed:
+ return ret;
+}
+
+/* map a sid to a gid */
+NSS_STATUS
+_nss_winbind_sidtogid(const char *sid, gid_t *gid, int *errnop)
+{
+ NSS_STATUS ret;
+ struct winbindd_response response;
+ struct winbindd_request request;
+
+#ifdef DEBUG_NSS
+ fprintf(stderr, "[%5d]: sidtogid %s\n", getpid(), sid);
+#endif
+
+ ZERO_STRUCT(request);
+ ZERO_STRUCT(response);
+
+ strncpy(request.data.sid, sid, sizeof(request.data.sid) - 1);
+ request.data.sid[sizeof(request.data.sid) - 1] = '\0';
+
+ ret = winbindd_request(WINBINDD_SID_TO_GID, &request, &response);
+ if (ret != NSS_STATUS_SUCCESS) {
+ *errnop = errno = EINVAL;
+ goto failed;
+ }
+
+ *gid = response.data.gid;
+
+failed:
+ return ret;
+}
+
+/* map a uid to a SID string */
+NSS_STATUS
+_nss_winbind_uidtosid(uid_t uid, char **sid, char *buffer,
+ size_t buflen, int *errnop)
+{
+ NSS_STATUS ret;
+ struct winbindd_response response;
+ struct winbindd_request request;
+
+#ifdef DEBUG_NSS
+ fprintf(stderr, "[%5d]: uidtosid %s\n", getpid(), name);
+#endif
+
+ ZERO_STRUCT(response);
+ ZERO_STRUCT(request);
+
+ request.data.uid = uid;
+
+ ret = winbindd_request(WINBINDD_UID_TO_SID, &request, &response);
+ if (ret != NSS_STATUS_SUCCESS) {
+ *errnop = errno = EINVAL;
+ goto failed;
+ }
+
+ if (buflen < strlen(response.data.sid.sid)+1) {
+ ret = NSS_STATUS_TRYAGAIN;
+ *errnop = errno = ERANGE;
+ goto failed;
+ }
+
+ *errnop = errno = 0;
+ *sid = buffer;
+ strcpy(*sid, response.data.sid.sid);
+
+failed:
+ free_response(&response);
+ return ret;
+}
+
+/* map a gid to a SID string */
+NSS_STATUS
+_nss_winbind_gidtosid(gid_t gid, char **sid, char *buffer,
+ size_t buflen, int *errnop)
+{
+ NSS_STATUS ret;
+ struct winbindd_response response;
+ struct winbindd_request request;
+
+#ifdef DEBUG_NSS
+ fprintf(stderr, "[%5d]: gidtosid %s\n", getpid(), name);
+#endif
+
+ ZERO_STRUCT(response);
+ ZERO_STRUCT(request);
+
+ request.data.gid = gid;
+
+ ret = winbindd_request(WINBINDD_GID_TO_SID, &request, &response);
+ if (ret != NSS_STATUS_SUCCESS) {
+ *errnop = errno = EINVAL;
+ goto failed;
+ }
+
+ if (buflen < strlen(response.data.sid.sid)+1) {
+ ret = NSS_STATUS_TRYAGAIN;
+ *errnop = errno = ERANGE;
+ goto failed;
+ }
+
+ *errnop = errno = 0;
+ *sid = buffer;
+ strcpy(*sid, response.data.sid.sid);
+
+failed:
+ free_response(&response);
+ return ret;
+}
diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c
index b31dc92b38..4805e628dd 100644
--- a/source3/nsswitch/winbindd_group.c
+++ b/source3/nsswitch/winbindd_group.c
@@ -1098,7 +1098,7 @@ enum winbindd_result winbindd_getusersids(struct winbindd_cli_state *state)
enum winbindd_result result = WINBINDD_ERROR;
unsigned int i;
TALLOC_CTX *mem_ctx;
- char *ret;
+ char *ret = NULL;
uint32 num_groups;
unsigned ofs, ret_size = 0;
@@ -1144,7 +1144,7 @@ enum winbindd_result winbindd_getusersids(struct winbindd_cli_state *state)
ofs = 0;
for (i = 0; i < num_groups; i++) {
const char *s = sid_string_static(user_grpsids[i]);
- safe_strcpy(ret + ofs, s, ret_size - ofs);
+ safe_strcpy(ret + ofs, s, ret_size - ofs - 1);
ofs += strlen(ret+ofs) + 1;
}
diff --git a/source3/rpc_parse/parse_epmapper.c b/source3/rpc_parse/parse_epmapper.c
index 89dc0994c6..bc2cd17503 100644
--- a/source3/rpc_parse/parse_epmapper.c
+++ b/source3/rpc_parse/parse_epmapper.c
@@ -45,37 +45,37 @@ BOOL epm_io_handle(const char *desc, EPM_HANDLE *handle, prs_struct *ps,
/*******************************************************************
inits an EPM_FLOOR structure.
********************************************************************/
-NTSTATUS init_epm_floor(EPM_FLOOR *floor, uint8 protocol)
+NTSTATUS init_epm_floor(EPM_FLOOR *efloor, uint8 protocol)
{
/* handle lhs */
- floor->lhs.protocol = protocol;
- floor->lhs.length = sizeof(floor->lhs.protocol);
+ efloor->lhs.protocol = protocol;
+ efloor->lhs.length = sizeof(efloor->lhs.protocol);
- switch(floor->lhs.protocol) {
+ switch(efloor->lhs.protocol) {
case EPM_FLOOR_UUID:
- floor->lhs.length += sizeof(floor->lhs.uuid.uuid);
- floor->lhs.length += sizeof(floor->lhs.uuid.version);
+ efloor->lhs.length += sizeof(efloor->lhs.uuid.uuid);
+ efloor->lhs.length += sizeof(efloor->lhs.uuid.version);
break;
default:
break;
}
/* handle rhs */
- switch(floor->lhs.protocol) {
+ switch(efloor->lhs.protocol) {
case EPM_FLOOR_RPC:
case EPM_FLOOR_UUID:
- floor->rhs.length = sizeof(floor->rhs.unknown);
+ efloor->rhs.length = sizeof(efloor->rhs.unknown);
break;
case EPM_FLOOR_TCP:
- floor->rhs.length = sizeof(floor->rhs.tcp.port);
+ efloor->rhs.length = sizeof(efloor->rhs.tcp.port);
break;
case EPM_FLOOR_IP:
- floor->rhs.length = sizeof(floor->rhs.ip.addr);
+ efloor->rhs.length = sizeof(efloor->rhs.ip.addr);
break;
case EPM_FLOOR_NMPIPES:
case EPM_FLOOR_LRPC:
case EPM_FLOOR_NETBIOS:
- floor->rhs.length = strlen(floor->rhs.string) + 1;
+ efloor->rhs.length = strlen(efloor->rhs.string) + 1;
break;
default:
break;
@@ -87,118 +87,118 @@ NTSTATUS init_epm_floor(EPM_FLOOR *floor, uint8 protocol)
/*******************************************************************
inits an EPM_FLOOR structure with a UUID
********************************************************************/
-NTSTATUS init_epm_floor_uuid(EPM_FLOOR *floor,
+NTSTATUS init_epm_floor_uuid(EPM_FLOOR *efloor,
const struct uuid uuid, uint16 version)
{
- memcpy(&floor->lhs.uuid.uuid, &uuid, sizeof(uuid));
- floor->lhs.uuid.version = version;
- floor->rhs.unknown = 0;
- return init_epm_floor(floor, EPM_FLOOR_UUID);
+ memcpy(&efloor->lhs.uuid.uuid, &uuid, sizeof(uuid));
+ efloor->lhs.uuid.version = version;
+ efloor->rhs.unknown = 0;
+ return init_epm_floor(efloor, EPM_FLOOR_UUID);
}
/*******************************************************************
inits an EPM_FLOOR structure for RPC
********************************************************************/
-NTSTATUS init_epm_floor_rpc(EPM_FLOOR *floor)
+NTSTATUS init_epm_floor_rpc(EPM_FLOOR *efloor)
{
- floor->rhs.unknown = 0;
- return init_epm_floor(floor, EPM_FLOOR_RPC);
+ efloor->rhs.unknown = 0;
+ return init_epm_floor(efloor, EPM_FLOOR_RPC);
}
/*******************************************************************
inits an EPM_FLOOR structure for TCP
********************************************************************/
-NTSTATUS init_epm_floor_tcp(EPM_FLOOR *floor, uint16 port)
+NTSTATUS init_epm_floor_tcp(EPM_FLOOR *efloor, uint16 port)
{
- floor->rhs.tcp.port = htons(port);
- return init_epm_floor(floor, EPM_FLOOR_TCP);
+ efloor->rhs.tcp.port = htons(port);
+ return init_epm_floor(efloor, EPM_FLOOR_TCP);
}
/*******************************************************************
inits an EPM_FLOOR structure for IP
********************************************************************/
-NTSTATUS init_epm_floor_ip(EPM_FLOOR *floor, uint8 addr[4])
+NTSTATUS init_epm_floor_ip(EPM_FLOOR *efloor, uint8 addr[4])
{
- memcpy(&floor->rhs.ip.addr, addr, sizeof(addr));
- return init_epm_floor(floor, EPM_FLOOR_IP);
+ memcpy(&efloor->rhs.ip.addr, addr, sizeof(addr));
+ return init_epm_floor(efloor, EPM_FLOOR_IP);
}
/*******************************************************************
inits an EPM_FLOOR structure for named pipe
********************************************************************/
-NTSTATUS init_epm_floor_np(EPM_FLOOR *floor, const char *pipe_name)
+NTSTATUS init_epm_floor_np(EPM_FLOOR *efloor, const char *pipe_name)
{
- safe_strcpy(floor->rhs.string, pipe_name, sizeof(floor->rhs.string)-1);
- return init_epm_floor(floor, EPM_FLOOR_NMPIPES);
+ safe_strcpy(efloor->rhs.string, pipe_name, sizeof(efloor->rhs.string)-1);
+ return init_epm_floor(efloor, EPM_FLOOR_NMPIPES);
}
/*******************************************************************
inits an EPM_FLOOR structure for named pipe
********************************************************************/
-NTSTATUS init_epm_floor_lrpc(EPM_FLOOR *floor, const char *pipe_name)
+NTSTATUS init_epm_floor_lrpc(EPM_FLOOR *efloor, const char *pipe_name)
{
- safe_strcpy(floor->rhs.string, pipe_name, sizeof(floor->rhs.string)-1);
- return init_epm_floor(floor, EPM_FLOOR_LRPC);
+ safe_strcpy(efloor->rhs.string, pipe_name, sizeof(efloor->rhs.string)-1);
+ return init_epm_floor(efloor, EPM_FLOOR_LRPC);
}
/*******************************************************************
inits an EPM_FLOOR structure for named pipe
********************************************************************/
-NTSTATUS init_epm_floor_nb(EPM_FLOOR *floor, char *host_name)
+NTSTATUS init_epm_floor_nb(EPM_FLOOR *efloor, char *host_name)
{
- safe_strcpy(floor->rhs.string, host_name, sizeof(floor->rhs.string)-1);
- return init_epm_floor(floor, EPM_FLOOR_NETBIOS);
+ safe_strcpy(efloor->rhs.string, host_name, sizeof(efloor->rhs.string)-1);
+ return init_epm_floor(efloor, EPM_FLOOR_NETBIOS);
}
/*******************************************************************
reads and writes EPM_FLOOR.
********************************************************************/
-BOOL epm_io_floor(const char *desc, EPM_FLOOR *floor,
+BOOL epm_io_floor(const char *desc, EPM_FLOOR *efloor,
prs_struct *ps, int depth)
{
prs_debug(ps, depth, desc, "epm_io_floor");
depth++;
- if (!prs_uint16("lhs_length", ps, depth, &floor->lhs.length))
+ if (!prs_uint16("lhs_length", ps, depth, &efloor->lhs.length))
return False;
- if (!prs_uint8("protocol", ps, depth, &floor->lhs.protocol))
+ if (!prs_uint8("protocol", ps, depth, &efloor->lhs.protocol))
return False;
- switch (floor->lhs.protocol) {
+ switch (efloor->lhs.protocol) {
case EPM_FLOOR_UUID:
- if (!smb_io_uuid("uuid", &floor->lhs.uuid.uuid, ps, depth))
+ if (!smb_io_uuid("uuid", &efloor->lhs.uuid.uuid, ps, depth))
return False;
if (!prs_uint16("version", ps, depth,
- &floor->lhs.uuid.version))
+ &efloor->lhs.uuid.version))
return False;
break;
}
- if (!prs_uint16("rhs_length", ps, depth, &floor->rhs.length))
+ if (!prs_uint16("rhs_length", ps, depth, &efloor->rhs.length))
return False;
- switch (floor->lhs.protocol) {
+ switch (efloor->lhs.protocol) {
case EPM_FLOOR_UUID:
case EPM_FLOOR_RPC:
- if (!prs_uint16("unknown", ps, depth, &floor->rhs.unknown))
+ if (!prs_uint16("unknown", ps, depth, &efloor->rhs.unknown))
return False;
break;
case EPM_FLOOR_TCP:
- if (!prs_uint16("tcp_port", ps, depth, &floor->rhs.tcp.port))
+ if (!prs_uint16("tcp_port", ps, depth, &efloor->rhs.tcp.port))
return False;
break;
case EPM_FLOOR_IP:
if (!prs_uint8s(False, "ip_addr", ps, depth,
- floor->rhs.ip.addr,
- sizeof(floor->rhs.ip.addr)))
+ efloor->rhs.ip.addr,
+ sizeof(efloor->rhs.ip.addr)))
return False;
break;
case EPM_FLOOR_NMPIPES:
case EPM_FLOOR_LRPC:
case EPM_FLOOR_NETBIOS:
if (!prs_uint8s(False, "string", ps, depth,
- floor->rhs.string,
- floor->rhs.length))
+ efloor->rhs.string,
+ efloor->rhs.length))
return False;
break;
default: