diff options
author | Jeremy Allison <jra@samba.org> | 2005-10-18 03:24:00 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:05:02 -0500 |
commit | 8d7c88667190fe286971ac4fffb64ee5bd9eeeb0 (patch) | |
tree | d5b2f0850d63a07e051c03a7abe1f10884598161 /source3/lib | |
parent | afca439d19e3d9e67b127d7060df630e2218bcb2 (diff) | |
download | samba-8d7c88667190fe286971ac4fffb64ee5bd9eeeb0.tar.gz samba-8d7c88667190fe286971ac4fffb64ee5bd9eeeb0.tar.bz2 samba-8d7c88667190fe286971ac4fffb64ee5bd9eeeb0.zip |
r11137: Compile with only 2 warnings (I'm still working on that code) on a gcc4
x86_64 box.
Jeremy.
(This used to be commit d720867a788c735e56d53d63265255830ec21208)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/clobber.c | 2 | ||||
-rw-r--r-- | source3/lib/iconv.c | 16 | ||||
-rw-r--r-- | source3/lib/privileges.c | 2 | ||||
-rw-r--r-- | source3/lib/system_smbd.c | 105 | ||||
-rw-r--r-- | source3/lib/util.c | 14 | ||||
-rw-r--r-- | source3/lib/util_getent.c | 45 | ||||
-rw-r--r-- | source3/lib/util_sid.c | 11 |
7 files changed, 101 insertions, 94 deletions
diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index fb3a0dc281..f39b94538e 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -54,7 +54,9 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ +#if 0 VALGRIND_MAKE_WRITABLE(dest, len); +#endif #endif /* VALGRIND */ #endif /* DEVELOPER */ } diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index d58165fed0..f738f45efa 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -642,15 +642,15 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = c; - *outbuf = uc; + *inbuf = (char *)c; + *outbuf = (char *)uc; return 0; error: *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = c; - *outbuf = uc; + *inbuf = (char *)c; + *outbuf = (char *)uc; return -1; } @@ -755,16 +755,16 @@ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = uc; - *outbuf = c; + *inbuf = (char *)uc; + *outbuf = (char *)c; return 0; error: *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = uc; - *outbuf = c; + *inbuf = (char *)uc; + *outbuf = (char *)c; return -1; } diff --git a/source3/lib/privileges.c b/source3/lib/privileges.c index ff0631b82f..ee69613df0 100644 --- a/source3/lib/privileges.c +++ b/source3/lib/privileges.c @@ -104,7 +104,7 @@ PRIVS privs[] = { }; typedef struct { - int count; + size_t count; DOM_SID *list; } SID_LIST; diff --git a/source3/lib/system_smbd.c b/source3/lib/system_smbd.c index f124983006..1afd44b709 100644 --- a/source3/lib/system_smbd.c +++ b/source3/lib/system_smbd.c @@ -27,15 +27,58 @@ #include "includes.h" #ifndef HAVE_GETGROUPLIST + +static int int_compare( int *a, int *b ) +{ + if ( *a == *b ) + return 0; + else if ( *a < *b ) + return -1; + else + return 1; +} + +void remove_duplicate_gids( int *num_groups, gid_t *groups ) +{ + int i; + int count = *num_groups; + + if ( *num_groups <= 0 || !groups ) + return; + + DEBUG(8,("remove_duplicate_gids: Enter %d gids\n", *num_groups)); + + qsort( groups, *num_groups, sizeof(gid_t), QSORT_CAST int_compare ); + + for ( i=1; i<count; ) { + if ( groups[i-1] == groups[i] ) { + memmove( &groups[i-1], &groups[i], (count - i + 1)*sizeof(gid_t) ); + + /* decrement the total number of groups and do not increment + the loop counter */ + count--; + continue; + } + i++; + } + + *num_groups = count; + + DEBUG(8,("remove_duplicate_gids: Exit %d gids\n", *num_groups)); + + return; +} + /* This is a *much* faster way of getting the list of groups for a user - without changing the current supplemenrary group list. The old + without changing the current supplementary group list. The old method used getgrent() which could take 20 minutes on a really big network with hundeds of thousands of groups and users. The new method takes a couple of seconds. NOTE!! this function only works if it is called as root! */ + static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, int *grpcnt) { gid_t *gids_saved; @@ -52,7 +95,7 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in /* this shouldn't happen */ return -1; } - + gids_saved = SMB_MALLOC_ARRAY(gid_t, ngrp_saved+1); if (!gids_saved) { errno = ENOMEM; @@ -79,18 +122,26 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in 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) { - groups[0] = gid; - *grpcnt = ret + 1; + if (ret < 0) { + SAFE_FREE(gids_saved); + /* very strange! */ + return -1; } - - /* remove any duplicates gids in the list */ + groups[0] = gid; + *grpcnt = ret + 1; + /* remove any duplicates gids in the list */ remove_duplicate_gids( grpcnt, groups ); } @@ -103,7 +154,7 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in free(gids_saved); return -1; } - + free(gids_saved); return ret; } @@ -140,9 +191,10 @@ static int sys_getgrouplist(const char *user, gid_t gid, gid_t *groups, int *grp } BOOL getgroups_user(const char *user, gid_t primary_gid, - gid_t **ret_groups, int *ngroups) + gid_t **ret_groups, size_t *p_ngroups) { - int ngrp, max_grp; + size_t ngrp; + int max_grp; gid_t *temp_groups; gid_t *groups; int i; @@ -154,9 +206,8 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, } 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) { @@ -183,7 +234,7 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, for (i=0; i<max_grp; i++) add_gid_to_array_unique(NULL, temp_groups[i], &groups, &ngrp); - *ngroups = ngrp; + *p_ngroups = ngrp; *ret_groups = groups; SAFE_FREE(temp_groups); return True; @@ -192,34 +243,34 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, NTSTATUS pdb_default_enum_group_memberships(struct pdb_methods *methods, const char *username, gid_t primary_gid, - DOM_SID **sids, - gid_t **gids, - int *num_groups) + DOM_SID **pp_sids, + gid_t **pp_gids, + size_t *p_num_groups) { - int i; + size_t i; - if (!getgroups_user(username, primary_gid, gids, num_groups)) { + if (!getgroups_user(username, primary_gid, pp_gids, p_num_groups)) { return NT_STATUS_NO_SUCH_USER; } - if (*num_groups == 0) { + if (*p_num_groups == 0) { smb_panic("primary group missing"); } - *sids = SMB_MALLOC_ARRAY(DOM_SID, *num_groups); + *pp_sids = SMB_MALLOC_ARRAY(DOM_SID, *p_num_groups); - if (*sids == NULL) { - SAFE_FREE(gids); + if (*pp_sids == NULL) { + SAFE_FREE(pp_gids); return NT_STATUS_NO_MEMORY; } - for (i=0; i<*num_groups; i++) { - if (!NT_STATUS_IS_OK(gid_to_sid(&(*sids)[i], (*gids)[i]))) { + for (i=0; i<*p_num_groups; i++) { + if (!NT_STATUS_IS_OK(gid_to_sid(&(*pp_sids)[i], (*pp_gids)[i]))) { DEBUG(1, ("get_user_groups: failed to convert " "gid %ld to a sid!\n", - (long int)(*gids)[i+1])); - SAFE_FREE(*sids); - SAFE_FREE(*gids); + (long int)(*pp_gids)[i+1])); + SAFE_FREE(*pp_sids); + SAFE_FREE(*pp_gids); return NT_STATUS_NO_SUCH_USER; } } diff --git a/source3/lib/util.c b/source3/lib/util.c index a5cfe95b66..30886b0dd8 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -282,25 +282,25 @@ const char *tmpdir(void) ****************************************************************************/ void add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid, - gid_t **gids, int *num) + gid_t **gids, size_t *num_gids) { int i; - for (i=0; i<*num; i++) { + for (i=0; i<*num_gids; i++) { if ((*gids)[i] == gid) return; } if (mem_ctx != NULL) - *gids = TALLOC_REALLOC_ARRAY(mem_ctx, *gids, gid_t, *num+1); + *gids = TALLOC_REALLOC_ARRAY(mem_ctx, *gids, gid_t, *num_gids+1); else - *gids = SMB_REALLOC_ARRAY(*gids, gid_t, *num+1); + *gids = SMB_REALLOC_ARRAY(*gids, gid_t, *num_gids+1); if (*gids == NULL) return; - (*gids)[*num] = gid; - *num += 1; + (*gids)[*num_gids] = gid; + *num_gids += 1; } /**************************************************************************** @@ -2093,7 +2093,7 @@ void dump_data_pw(const char *msg, const uchar * data, size_t len) DEBUG(11, ("%s", msg)); if (data != NULL && len > 0) { - dump_data(11, data, len); + dump_data(11, (const char *)data, len); } #endif } diff --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c index 1b01cae5fa..475b0da87b 100644 --- a/source3/lib/util_getent.c +++ b/source3/lib/util_getent.c @@ -304,48 +304,3 @@ void free_userlist(struct sys_userlist *list_head) SAFE_FREE(old_head); } } - -/**************************************************************** -****************************************************************/ - -static int int_compare( int *a, int *b ) -{ - if ( *a == *b ) - return 0; - else if ( *a < *b ) - return -1; - else - return 1; -} - -void remove_duplicate_gids( int *num_groups, gid_t *groups ) -{ - int i; - int count = *num_groups; - - if ( *num_groups <= 0 || !groups ) - return; - - - DEBUG(8,("remove_duplicate_gids: Enter %d gids\n", *num_groups)); - - qsort( groups, *num_groups, sizeof(gid_t), QSORT_CAST int_compare ); - - for ( i=1; i<count; ) { - if ( groups[i-1] == groups[i] ) { - memmove( &groups[i-1], &groups[i], (count - i + 1)*sizeof(gid_t) ); - - /* decrement the total number of groups and do not increment - the loop counter */ - count--; - continue; - } - i++; - } - - *num_groups = count; - - DEBUG(8,("remove_duplicate_gids: Exit %d gids\n", *num_groups)); - - return; -} diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index b9b4aff420..f3f6c938ee 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -637,7 +637,7 @@ DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src) ********************************************************************/ void add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid, - DOM_SID **sids, int *num) + DOM_SID **sids, size_t *num) { if (mem_ctx != NULL) *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID, @@ -660,9 +660,9 @@ void add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid, ********************************************************************/ void add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid, - DOM_SID **sids, int *num_sids) + DOM_SID **sids, size_t *num_sids) { - int i; + size_t i; for (i=0; i<(*num_sids); i++) { if (sid_compare(sid, &(*sids)[i]) == 0) @@ -676,10 +676,10 @@ void add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid, Remove SID from an array ********************************************************************/ -void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, int *num) +void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, size_t *num) { DOM_SID *sid_list = *sids; - int i; + size_t i; for ( i=0; i<*num; i++ ) { @@ -700,4 +700,3 @@ void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, int *num) return; } - |