static bool do_winbind_dump_domain_list(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { const char *domain = NULL; int domain_len = 0; struct server_id myid; uint8_t *buf = NULL; int buf_len = 0; myid = messaging_server_id(msg_ctx); if (argc < 1 || argc > 2) { fprintf(stderr, "Usage: smbcontrol <dest> dump-domain-list " "<domain>\n"); return false; } if (argc == 2) { domain = argv[1]; domain_len = strlen(argv[1]) + 1; } messaging_register(msg_ctx, NULL, MSG_WINBIND_DUMP_DOMAIN_LIST, print_pid_string_cb); buf_len = sizeof(myid)+domain_len; buf = SMB_MALLOC_ARRAY(uint8_t, buf_len); if (!buf) { return false; } memcpy(buf, &myid, sizeof(myid)); memcpy(&buf[sizeof(myid)], domain, domain_len); if (!send_message(msg_ctx, pid, MSG_WINBIND_DUMP_DOMAIN_LIST, buf, buf_len)) { SAFE_FREE(buf); return false; } wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0); /* No replies were received within the timeout period */ SAFE_FREE(buf); if (num_replies == 0) { printf("No replies received\n"); } messaging_deregister(msg_ctx, MSG_WINBIND_DUMP_DOMAIN_LIST, NULL); return num_replies; }
bool getgroups_unix_user(TALLOC_CTX *mem_ctx, const char *user, gid_t primary_gid, gid_t **ret_groups, uint32_t *p_ngroups) { uint32_t ngrp; int max_grp; gid_t *temp_groups; gid_t *groups; int i; max_grp = MIN(128, groups_max()); temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp); if (! temp_groups) { return False; } if (sys_getgrouplist(user, primary_gid, temp_groups, &max_grp) == -1) { temp_groups = SMB_REALLOC_ARRAY(temp_groups, gid_t, max_grp); if (!temp_groups) { return False; } if (sys_getgrouplist(user, primary_gid, temp_groups, &max_grp) == -1) { DEBUG(0, ("get_user_groups: failed to get the unix " "group list\n")); SAFE_FREE(temp_groups); return False; } } ngrp = 0; groups = NULL; /* Add in primary group first */ if (!add_gid_to_array_unique(mem_ctx, primary_gid, &groups, &ngrp)) { SAFE_FREE(temp_groups); return False; } for (i=0; i<max_grp; i++) { if (!add_gid_to_array_unique(mem_ctx, temp_groups[i], &groups, &ngrp)) { SAFE_FREE(temp_groups); return False; } } *p_ngroups = ngrp; *ret_groups = groups; SAFE_FREE(temp_groups); return True; }
/**************************************************************************** get the current list of queued jobs ****************************************************************************/ static int generic_queue_get(const char *printer_name, enum printing_types printing_type, char *lpq_command, print_queue_struct **q, print_status_struct *status) { char **qlines; int fd; int numlines, i, qcount; print_queue_struct *queue = NULL; /* never do substitution when running the 'lpq command' since we can't get it rigt when using the background update daemon. Make the caller do it before passing off the command string to us here. */ print_run_command(-1, printer_name, False, lpq_command, &fd, NULL); if (fd == -1) { DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n", printer_name )); return 0; } numlines = 0; qlines = fd_lines_load(fd, &numlines,0,NULL); close(fd); /* turn the lpq output into a series of job structures */ qcount = 0; ZERO_STRUCTP(status); if (numlines && qlines) { queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1); if (!queue) { TALLOC_FREE(qlines); *q = NULL; return 0; } memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1)); for (i=0; i<numlines; i++) { /* parse the line */ if (parse_lpq_entry(printing_type,qlines[i], &queue[qcount],status,qcount==0)) { qcount++; } } } TALLOC_FREE(qlines); *q = queue; return qcount; }
bool login_cache_write(const struct samu *sampass, const struct login_cache *entry) { char *keystr; TDB_DATA databuf; bool ret; uint32_t entry_timestamp; uint32_t bad_password_time = entry->bad_password_time; if (!login_cache_init()) return False; if (pdb_get_nt_username(sampass) == NULL) { return False; } keystr = SMB_STRDUP(pdb_get_nt_username(sampass)); if (!keystr || !keystr[0]) { SAFE_FREE(keystr); return False; } entry_timestamp = (uint32_t)time(NULL); databuf.dsize = tdb_pack(NULL, 0, SAM_CACHE_FORMAT, entry_timestamp, entry->acct_ctrl, entry->bad_password_count, bad_password_time); databuf.dptr = SMB_MALLOC_ARRAY(uint8_t, databuf.dsize); if (!databuf.dptr) { SAFE_FREE(keystr); return False; } if (tdb_pack(databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT, entry_timestamp, entry->acct_ctrl, entry->bad_password_count, bad_password_time) != databuf.dsize) { SAFE_FREE(keystr); SAFE_FREE(databuf.dptr); return False; } ret = tdb_store_bystring(cache, keystr, databuf, 0); SAFE_FREE(keystr); SAFE_FREE(databuf.dptr); return ret == 0; }
static smb_ucs2_t *strdup_w(const smb_ucs2_t *src) { smb_ucs2_t *dest; size_t len = strlen_w(src); dest = SMB_MALLOC_ARRAY(smb_ucs2_t, len + 1); if (!dest) { DEBUG(0,("strdup_w: out of memory!\n")); return NULL; } memcpy(dest, src, len * sizeof(smb_ucs2_t)); dest[len] = 0; return dest; }
static int get_current_groups(gid_t gid, uint32_t *p_ngroups, gid_t **p_groups) { int i; gid_t grp; int ngroups; gid_t *groups = NULL; (*p_ngroups) = 0; (*p_groups) = NULL; /* this looks a little strange, but is needed to cope with systems that put the current egid in the group list returned from getgroups() (tridge) */ save_re_gid(); set_effective_gid(gid); samba_setgid(gid); ngroups = sys_getgroups(0,&grp); if (ngroups <= 0) { goto fail; } if((groups = SMB_MALLOC_ARRAY(gid_t, ngroups+1)) == NULL) { DEBUG(0,("setup_groups malloc fail !\n")); goto fail; } if ((ngroups = sys_getgroups(ngroups,groups)) == -1) { goto fail; } restore_re_gid(); (*p_ngroups) = ngroups; (*p_groups) = groups; DEBUG( 4, ( "get_current_groups: user is in %u groups: ", ngroups)); for (i = 0; i < ngroups; i++ ) { DEBUG( 4, ( "%s%d", (i ? ", " : ""), (int)groups[i] ) ); } DEBUG( 4, ( "\n" ) ); return ngroups; fail: SAFE_FREE(groups); restore_re_gid(); return -1; }
/* return a full list of groups for a user returns the number of groups the user is a member of. The return will include the users primary group. remember to free the resulting gid_t array NOTE! uses become_root() to gain correct priviages on systems that lack a native getgroups() call (uses initgroups and getgroups) */ BOOL getgroups_user(const char *user, gid_t primary_gid, gid_t **ret_groups, int *ngroups) { int ngrp, max_grp; gid_t *temp_groups; gid_t *groups; int i; max_grp = groups_max(); temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp); if (! temp_groups) { return False; } if (sys_getgrouplist(user, primary_gid, temp_groups, &max_grp) == -1) { gid_t *groups_tmp; groups_tmp = SMB_REALLOC_ARRAY(temp_groups, gid_t, max_grp); if (!groups_tmp) { SAFE_FREE(temp_groups); return False; } temp_groups = groups_tmp; if (sys_getgrouplist(user, primary_gid, temp_groups, &max_grp) == -1) { DEBUG(0, ("get_user_groups: failed to get the unix group list\n")); SAFE_FREE(temp_groups); return False; } } ngrp = 0; groups = NULL; /* Add in primary group first */ add_gid_to_array_unique(primary_gid, &groups, &ngrp); for (i=0; i<max_grp; i++) add_gid_to_array_unique(temp_groups[i], &groups, &ngrp); *ngroups = ngrp; *ret_groups = groups; SAFE_FREE(temp_groups); return True; }
/**************************************************************************** some systems don't have an initgroups call ****************************************************************************/ int initgroups(char *name,gid_t id) { #ifndef HAVE_SETGROUPS static int done; if (!done) { DEBUG(1,("WARNING: running without setgroups\n")); done=1; } /* yikes! no SETGROUPS or INITGROUPS? how can this work? */ return(0); #else /* HAVE_SETGROUPS */ gid_t *grouplst = NULL; int max_gr = groups_max(); int ret; int i,j; struct group *g; char *gr; if((grouplst = SMB_MALLOC_ARRAY(gid_t, max_gr)) == NULL) { DEBUG(0,("initgroups: malloc fail !\n")); return -1; } grouplst[0] = id; i = 1; while (i < max_gr && ((g = (struct group *)getgrent()) != (struct group *)NULL)) { if (g->gr_gid == id) continue; j = 0; gr = g->gr_mem[0]; while (gr && (*gr != (char)NULL)) { if (strcmp(name,gr) == 0) { grouplst[i] = g->gr_gid; i++; gr = (char *)NULL; break; } gr = g->gr_mem[++j]; } } endgrent(); ret = sys_setgroups(i,grouplst); SAFE_FREE(grouplst); return ret; #endif /* HAVE_SETGROUPS */ }
bool secrets_store_trusted_domain_password(const char* domain, const char* pwd, const DOM_SID *sid) { smb_ucs2_t *uni_dom_name; bool ret; /* packing structures */ uint8 *pass_buf = NULL; int pass_len = 0; struct trusted_dom_pass pass; ZERO_STRUCT(pass); if (push_ucs2_allocate(&uni_dom_name, domain) == (size_t)-1) { DEBUG(0, ("Could not convert domain name %s to unicode\n", domain)); return False; } strncpy_w(pass.uni_name, uni_dom_name, sizeof(pass.uni_name) - 1); pass.uni_name_len = strlen_w(uni_dom_name)+1; SAFE_FREE(uni_dom_name); /* last change time */ pass.mod_time = time(NULL); /* password of the trust */ pass.pass_len = strlen(pwd); fstrcpy(pass.pass, pwd); /* domain sid */ sid_copy(&pass.domain_sid, sid); /* Calculate the length. */ pass_len = tdb_trusted_dom_pass_pack(NULL, 0, &pass); pass_buf = SMB_MALLOC_ARRAY(uint8, pass_len); if (!pass_buf) { return false; } pass_len = tdb_trusted_dom_pass_pack(pass_buf, pass_len, &pass); ret = secrets_store(trustdom_keystr(domain), (void *)pass_buf, pass_len); SAFE_FREE(pass_buf); return ret; }
/**************************************************************************** allocate a bitmap of the specified size ****************************************************************************/ struct bitmap *bitmap_allocate(int n) { struct bitmap *bm; bm = SMB_MALLOC_P(struct bitmap); if (!bm) return NULL; bm->n = n; bm->b = SMB_MALLOC_ARRAY(uint32, (n+31)/32); if (!bm->b) { SAFE_FREE(bm); return NULL; } memset(bm->b, 0, sizeof(uint32)*((n+31)/32)); return bm; }
bool push_sec_ctx(void) { struct sec_ctx *ctx_p; /* Check we don't overflow our stack */ if (sec_ctx_stack_ndx == MAX_SEC_CTX_DEPTH) { DEBUG(0, ("Security context stack overflow!\n")); smb_panic("Security context stack overflow!"); } /* Store previous user context */ sec_ctx_stack_ndx++; ctx_p = &sec_ctx_stack[sec_ctx_stack_ndx]; ctx_p->ut.uid = geteuid(); ctx_p->ut.gid = getegid(); DEBUG(4, ("push_sec_ctx(%u, %u) : sec_ctx_stack_ndx = %d\n", (unsigned int)ctx_p->ut.uid, (unsigned int)ctx_p->ut.gid, sec_ctx_stack_ndx )); ctx_p->token = dup_nt_token(NULL, sec_ctx_stack[sec_ctx_stack_ndx-1].token); ctx_p->ut.ngroups = sys_getgroups(0, NULL); if (ctx_p->ut.ngroups != 0) { if (!(ctx_p->ut.groups = SMB_MALLOC_ARRAY(gid_t, ctx_p->ut.ngroups))) { DEBUG(0, ("Out of memory in push_sec_ctx()\n")); TALLOC_FREE(ctx_p->token); return False; } sys_getgroups(ctx_p->ut.ngroups, ctx_p->ut.groups); } else { ctx_p->ut.groups = NULL; } return True; }
static void nss_test_initgroups(char *name, gid_t gid) { long int size = 16; long int start = 1; gid_t *groups = NULL; int i; NSS_STATUS status; groups = SMB_MALLOC_ARRAY(gid_t, size); groups[0] = gid; status = nss_initgroups(name, gid, &groups, &start, &size); if (status == NSS_STATUS_UNAVAIL) { printf("No initgroups fn\n"); return; } for (i=0; i<start-1; i++) { printf("%lu, ", (unsigned long)groups[i]); } printf("%lu\n", (unsigned long)groups[i]); }
NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, struct cli_state *cli, const char *path, struct client_dfs_referral **refs, size_t *num_refs, size_t *consumed) { unsigned int data_len = 0; unsigned int param_len = 0; uint16_t setup[1]; uint16_t recv_flags2; uint8_t *param = NULL; uint8_t *rdata = NULL; char *p; char *endp; size_t pathlen = 2*(strlen(path)+1); smb_ucs2_t *path_ucs; char *consumed_path = NULL; uint16_t consumed_ucs; uint16 num_referrals; struct client_dfs_referral *referrals = NULL; NTSTATUS status; *num_refs = 0; *refs = NULL; SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL); param = SMB_MALLOC_ARRAY(uint8_t, 2+pathlen+2); if (!param) { status = NT_STATUS_NO_MEMORY; goto out; } SSVAL(param, 0, 0x03); /* max referral level */ p = (char *)(¶m[2]); path_ucs = (smb_ucs2_t *)p; p += clistr_push(cli, p, path, pathlen, STR_TERMINATE); param_len = PTR_DIFF(p, param); status = cli_trans(talloc_tos(), cli, SMBtrans2, NULL, 0xffff, 0, 0, setup, 1, 0, param, param_len, 2, NULL, 0, cli->max_xmit, &recv_flags2, NULL, 0, NULL, /* rsetup */ NULL, 0, NULL, &rdata, 4, &data_len); if (!NT_STATUS_IS_OK(status)) { goto out; } endp = (char *)rdata + data_len; consumed_ucs = SVAL(rdata, 0); num_referrals = SVAL(rdata, 2); /* consumed_ucs is the number of bytes * of the UCS2 path consumed not counting any * terminating null. We need to convert * back to unix charset and count again * to get the number of bytes consumed from * the incoming path. */ errno = 0; if (pull_string_talloc(talloc_tos(), NULL, 0, &consumed_path, path_ucs, consumed_ucs, STR_UNICODE) == 0) { if (errno != 0) { status = map_nt_error_from_unix(errno); } else { status = NT_STATUS_INVALID_NETWORK_RESPONSE; } goto out; } if (consumed_path == NULL) { status = map_nt_error_from_unix(errno); goto out; } *consumed = strlen(consumed_path); if (num_referrals != 0) { uint16 ref_version; uint16 ref_size; int i; uint16 node_offset; referrals = talloc_array(ctx, struct client_dfs_referral, num_referrals); if (!referrals) { status = NT_STATUS_NO_MEMORY; goto out; } /* start at the referrals array */ p = (char *)rdata+8; for (i=0; i<num_referrals && p < endp; i++) { if (p + 18 > endp) { goto out; } ref_version = SVAL(p, 0); ref_size = SVAL(p, 2); node_offset = SVAL(p, 16); if (ref_version != 3) { p += ref_size; continue; } referrals[i].proximity = SVAL(p, 8); referrals[i].ttl = SVAL(p, 10); if (p + node_offset > endp) { status = NT_STATUS_INVALID_NETWORK_RESPONSE; goto out; } clistr_pull_talloc(referrals, (const char *)rdata, recv_flags2, &referrals[i].dfspath, p+node_offset, PTR_DIFF(endp, p+node_offset), STR_TERMINATE|STR_UNICODE); if (!referrals[i].dfspath) { status = map_nt_error_from_unix(errno); goto out; } p += ref_size; } if (i < num_referrals) { status = NT_STATUS_INVALID_NETWORK_RESPONSE; goto out; } }
static bool do_winbind_offline(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { TDB_CONTEXT *tdb; bool ret = False; int retry = 0; char *db_path; if (argc != 1) { fprintf(stderr, "Usage: smbcontrol winbindd offline\n"); return False; } db_path = state_path("winbindd_cache.tdb"); if (db_path == NULL) { return false; } /* Create an entry in the winbindd_cache tdb to tell a later starting winbindd that we're offline. We may actually create it here... */ tdb = tdb_open_log(db_path, WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH /* TDB_CLEAR_IF_FIRST */, O_RDWR|O_CREAT, 0600); if (!tdb) { fprintf(stderr, "Cannot open the tdb %s for writing.\n", db_path); TALLOC_FREE(db_path); return False; } TALLOC_FREE(db_path); /* There's a potential race condition that if a child winbindd detects a domain is online at the same time we're trying to tell it to go offline that it might delete the record we add between us adding it and sending the message. Minimize this by retrying up to 5 times. */ for (retry = 0; retry < 5; retry++) { uint8_t buf[4]; TDB_DATA d = { .dptr = buf, .dsize = sizeof(buf) }; SIVAL(buf, 0, time(NULL)); tdb_store_bystring(tdb, "WINBINDD_OFFLINE", d, TDB_INSERT); ret = send_message(msg_ctx, pid, MSG_WINBIND_OFFLINE, NULL, 0); /* Check that the entry "WINBINDD_OFFLINE" still exists. */ d = tdb_fetch_bystring( tdb, "WINBINDD_OFFLINE" ); if (!d.dptr || d.dsize != 4) { SAFE_FREE(d.dptr); DEBUG(10,("do_winbind_offline: offline state not set - retrying.\n")); } else { SAFE_FREE(d.dptr); break; } } tdb_close(tdb); return ret; } static bool do_winbind_onlinestatus(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { struct server_id myid; myid = messaging_server_id(msg_ctx); if (argc != 1) { fprintf(stderr, "Usage: smbcontrol winbindd onlinestatus\n"); return False; } messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS, print_pid_string_cb); if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid, sizeof(myid))) return False; wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0); /* No replies were received within the timeout period */ if (num_replies == 0) printf("No replies received\n"); messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL); return num_replies; } static bool do_dump_event_list(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { if (argc != 1) { fprintf(stderr, "Usage: smbcontrol <dest> dump-event-list\n"); return False; } return send_message(msg_ctx, pid, MSG_DUMP_EVENT_LIST, NULL, 0); } static bool do_winbind_dump_domain_list(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { const char *domain = NULL; int domain_len = 0; struct server_id myid; uint8_t *buf = NULL; int buf_len = 0; myid = messaging_server_id(msg_ctx); if (argc < 1 || argc > 2) { fprintf(stderr, "Usage: smbcontrol <dest> dump-domain-list " "<domain>\n"); return false; } if (argc == 2) { domain = argv[1]; domain_len = strlen(argv[1]) + 1; } messaging_register(msg_ctx, NULL, MSG_WINBIND_DUMP_DOMAIN_LIST, print_pid_string_cb); buf_len = sizeof(myid)+domain_len; buf = SMB_MALLOC_ARRAY(uint8_t, buf_len); if (!buf) { return false; } memcpy(buf, &myid, sizeof(myid)); memcpy(&buf[sizeof(myid)], domain, domain_len); if (!send_message(msg_ctx, pid, MSG_WINBIND_DUMP_DOMAIN_LIST, buf, buf_len)) { SAFE_FREE(buf); return false; } wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0); /* No replies were received within the timeout period */ SAFE_FREE(buf); if (num_replies == 0) { printf("No replies received\n"); } messaging_deregister(msg_ctx, MSG_WINBIND_DUMP_DOMAIN_LIST, NULL); return num_replies; } static void winbind_validate_cache_cb(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id pid, DATA_BLOB *data) { struct server_id_buf src_string; printf("Winbindd cache is %svalid. (answer from pid %s)\n", (*(data->data) == 0 ? "" : "NOT "), server_id_str_buf(pid, &src_string)); num_replies++; } static bool do_winbind_validate_cache(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { struct server_id myid; myid = messaging_server_id(msg_ctx); if (argc != 1) { fprintf(stderr, "Usage: smbcontrol winbindd validate-cache\n"); return False; } messaging_register(msg_ctx, NULL, MSG_WINBIND_VALIDATE_CACHE, winbind_validate_cache_cb); if (!send_message(msg_ctx, pid, MSG_WINBIND_VALIDATE_CACHE, &myid, sizeof(myid))) { return False; } wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0); if (num_replies == 0) { printf("No replies received\n"); } messaging_deregister(msg_ctx, MSG_WINBIND_VALIDATE_CACHE, NULL); return num_replies; } static bool do_reload_config(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { if (argc != 1) { fprintf(stderr, "Usage: smbcontrol <dest> reload-config\n"); return False; } return send_message(msg_ctx, pid, MSG_SMB_CONF_UPDATED, NULL, 0); } static bool do_reload_printers(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { if (argc != 1) { fprintf(stderr, "Usage: smbcontrol <dest> reload-printers\n"); return False; } return send_message(msg_ctx, pid, MSG_PRINTER_PCAP, NULL, 0); } static void my_make_nmb_name( struct nmb_name *n, const char *name, int type) { fstring unix_name; memset( (char *)n, '\0', sizeof(struct nmb_name) ); fstrcpy(unix_name, name); (void)strupper_m(unix_name); push_ascii(n->name, unix_name, sizeof(n->name), STR_TERMINATE); n->name_type = (unsigned int)type & 0xFF; push_ascii(n->scope, lp_netbios_scope(), 64, STR_TERMINATE); }
static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, int *grpcnt) { gid_t *gids_saved; int ret, ngrp_saved, num_gids; if (non_root_mode()) { *grpcnt = 0; return 0; } /* work out how many groups we need to save */ ngrp_saved = getgroups(0, NULL); if (ngrp_saved == -1) { /* this shouldn't happen */ return -1; } gids_saved = SMB_MALLOC_ARRAY(gid_t, ngrp_saved+1); if (!gids_saved) { errno = ENOMEM; return -1; } ngrp_saved = getgroups(ngrp_saved, gids_saved); if (ngrp_saved == -1) { SAFE_FREE(gids_saved); /* very strange! */ return -1; } if (initgroups(user, gid) == -1) { DEBUG(0, ("getgrouplist_internals: initgroups() failed!\n")); SAFE_FREE(gids_saved); return -1; } /* this must be done to cope with systems that put the current egid in the return from getgroups() */ save_re_gid(); set_effective_gid(gid); samba_setgid(gid); num_gids = getgroups(0, NULL); if (num_gids == -1) { SAFE_FREE(gids_saved); /* very strange! */ return -1; } if (num_gids + 1 > *grpcnt) { *grpcnt = num_gids + 1; ret = -1; } else { ret = getgroups(*grpcnt - 1, &groups[1]); if (ret < 0) { SAFE_FREE(gids_saved); /* very strange! */ return -1; } groups[0] = gid; *grpcnt = ret + 1; } restore_re_gid(); if (sys_setgroups(gid, ngrp_saved, gids_saved) != 0) { /* yikes! */ DEBUG(0,("ERROR: getgrouplist: failed to reset group list!\n")); smb_panic("getgrouplist: failed to reset group list!"); } free(gids_saved); return ret; }