summaryrefslogtreecommitdiff
path: root/source3/nsswitch
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-12-07 17:32:32 -0800
committerJeremy Allison <jra@samba.org>2007-12-07 17:32:32 -0800
commit42cfffae80480eae4381902fff3f7c61f858a933 (patch)
tree2fc1bc486fa988a4f2854310bcf91943db1aa566 /source3/nsswitch
parent25288b0e4472c728fc5a3a70c6c3e1f621ffae5f (diff)
downloadsamba-42cfffae80480eae4381902fff3f7c61f858a933.tar.gz
samba-42cfffae80480eae4381902fff3f7c61f858a933.tar.bz2
samba-42cfffae80480eae4381902fff3f7c61f858a933.zip
Remove next_token - all uses must now be next_token_talloc.
No more temptations to use static length strings. Jeremy. (This used to be commit ec003f39369910dee852b7cafb883ddaa321c2de)
Diffstat (limited to 'source3/nsswitch')
-rw-r--r--source3/nsswitch/wbinfo.c33
-rw-r--r--source3/nsswitch/winbind_nss_linux.c89
2 files changed, 80 insertions, 42 deletions
diff --git a/source3/nsswitch/wbinfo.c b/source3/nsswitch/wbinfo.c
index 488a080287..481f51779f 100644
--- a/source3/nsswitch/wbinfo.c
+++ b/source3/nsswitch/wbinfo.c
@@ -374,20 +374,23 @@ static bool wbinfo_list_domains(bool list_all_domains)
if (response.extra_data.data) {
const char *extra_data = (char *)response.extra_data.data;
- fstring name;
+ char *name;
char *p;
+ TALLOC_CTX *frame = talloc_stackframe();
- while(next_token(&extra_data, name, "\n", sizeof(fstring))) {
+ while(next_token_talloc(frame,&extra_data,&name,"\n")) {
p = strchr(name, '\\');
if (p == 0) {
d_fprintf(stderr, "Got invalid response: %s\n",
extra_data);
+ TALLOC_FREE(frame);
+ SAFE_FREE(response.extra_data.data);
return False;
}
*p = 0;
d_printf("%s\n", name);
}
-
+ TALLOC_FREE(frame);
SAFE_FREE(response.extra_data.data);
}
@@ -713,7 +716,7 @@ static bool wbinfo_lookuprids(char *domain, char *arg)
int num_rids;
uint32 *rids;
const char *p;
- char ridstr[32];
+ char *ridstr;
const char **names;
enum lsa_SidType *types;
const char *domain_name;
@@ -752,7 +755,7 @@ static bool wbinfo_lookuprids(char *domain, char *arg)
rids = NULL;
p = arg;
- while (next_token(&p, ridstr, " ,\n", sizeof(ridstr))) {
+ while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
uint32 rid = strtoul(ridstr, NULL, 10);
ADD_TO_ARRAY(mem_ctx, uint32, rid, &rids, &num_rids);
}
@@ -1072,13 +1075,14 @@ static bool print_domain_users(const char *domain)
struct winbindd_request request;
struct winbindd_response response;
const char *extra_data;
- fstring name;
+ char *name;
+ TALLOC_CTX *frame = NULL;
/* Send request to winbind daemon */
ZERO_STRUCT(request);
ZERO_STRUCT(response);
-
+
if (domain) {
/* '.' is the special sign for our own domain */
if ( strequal(domain, ".") )
@@ -1098,9 +1102,11 @@ static bool print_domain_users(const char *domain)
extra_data = (const char *)response.extra_data.data;
- while(next_token(&extra_data, name, ",", sizeof(fstring)))
+ frame = talloc_stackframe();
+ while(next_token_talloc(frame,&extra_data,&name, ","))
d_printf("%s\n", name);
-
+ TALLOC_FREE(frame);
+
SAFE_FREE(response.extra_data.data);
return True;
@@ -1113,7 +1119,8 @@ static bool print_domain_groups(const char *domain)
struct winbindd_request request;
struct winbindd_response response;
const char *extra_data;
- fstring name;
+ TALLOC_CTX *frame = NULL;
+ char *name;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
@@ -1136,11 +1143,13 @@ static bool print_domain_groups(const char *domain)
extra_data = (const char *)response.extra_data.data;
- while(next_token(&extra_data, name, ",", sizeof(fstring)))
+ frame = talloc_stackframe();
+ while(next_token_talloc(frame,&extra_data,&name, ","))
d_printf("%s\n", name);
+ TALLOC_FREE(frame);
SAFE_FREE(response.extra_data.data);
-
+
return True;
}
diff --git a/source3/nsswitch/winbind_nss_linux.c b/source3/nsswitch/winbind_nss_linux.c
index 7322da0001..bfac2ecdd1 100644
--- a/source3/nsswitch/winbind_nss_linux.c
+++ b/source3/nsswitch/winbind_nss_linux.c
@@ -85,7 +85,7 @@ static char *get_static(char **buffer, size_t *buflen, size_t len)
/* Error check. We return false if things aren't set up right, or
there isn't enough buffer space left. */
-
+
if ((buffer == NULL) || (buflen == NULL) || (*buflen < len)) {
return NULL;
}
@@ -99,46 +99,79 @@ static char *get_static(char **buffer, size_t *buflen, size_t len)
return result;
}
-/* I've copied the strtok() replacement function next_token() from
+/* I've copied the strtok() replacement function next_token_Xalloc() from
lib/util_str.c as I really don't want to have to link in any other
objects if I can possibly avoid it. */
-static bool next_token(char **ptr,char *buff,const char *sep, size_t bufsize)
+static bool next_token_alloc(const char **ptr,
+ char **pp_buff,
+ const char *sep)
{
char *s;
+ char *saved_s;
+ char *pbuf;
bool quoted;
size_t len=1;
- if (!ptr) return false;
+ *pp_buff = NULL;
+ if (!ptr) {
+ return(false);
+ }
- s = *ptr;
+ s = (char *)*ptr;
/* default to simple separators */
- if (!sep) sep = " \t\n\r";
+ if (!sep) {
+ sep = " \t\n\r";
+ }
/* find the first non sep char */
- while (*s && strchr(sep,*s)) s++;
-
+ while (*s && strchr(sep,*s)) {
+ s++;
+ }
+
/* nothing left? */
- if (! *s) return false;
-
- /* copy over the token */
- for (quoted = false; len < bufsize && *s && (quoted || !strchr(sep,*s)); s++) {
+ if (!*s) {
+ return false;
+ }
+
+ /* When restarting we need to go from here. */
+ saved_s = s;
+
+ /* Work out the length needed. */
+ for (quoted = false; *s &&
+ (quoted || !strchr(sep,*s)); s++) {
if (*s == '\"') {
quoted = !quoted;
} else {
len++;
- *buff++ = *s;
}
}
-
- *ptr = (*s) ? s+1 : s;
- *buff = 0;
-
+
+ /* We started with len = 1 so we have space for the nul. */
+ *pp_buff = malloc(len);
+ if (!*pp_buff) {
+ return false;
+ }
+
+ /* copy over the token */
+ pbuf = *pp_buff;
+ s = saved_s;
+ for (quoted = false; *s &&
+ (quoted || !strchr(sep,*s)); s++) {
+ if ( *s == '\"' ) {
+ quoted = !quoted;
+ } else {
+ *pbuf++ = *s;
+ }
+ }
+
+ *ptr = (*s) ? s+1 : s;
+ *pbuf = 0;
+
return true;
}
-
/* Fill a pwent structure from a winbindd_response structure. We use
the static data passed to us by libc to put strings and stuff in.
Return NSS_STATUS_TRYAGAIN if we run out of memory. */
@@ -233,7 +266,7 @@ static NSS_STATUS fill_pwent(struct passwd *result,
static NSS_STATUS fill_grent(struct group *result, struct winbindd_gr *gr,
char *gr_mem, char **buffer, size_t *buflen)
{
- fstring name;
+ char *name;
int i;
char *tst;
@@ -255,7 +288,6 @@ static NSS_STATUS fill_grent(struct group *result, struct winbindd_gr *gr,
get_static(buffer, buflen, strlen(gr->gr_passwd) + 1)) == NULL) {
/* Out of memory */
-
return NSS_STATUS_TRYAGAIN;
}
@@ -276,8 +308,8 @@ static NSS_STATUS fill_grent(struct group *result, struct winbindd_gr *gr,
/* Calculate number of extra bytes needed to align on pointer size boundry */
if ((i = (unsigned long)(*buffer) % sizeof(char*)) != 0)
i = sizeof(char*) - i;
-
- if ((tst = get_static(buffer, buflen, ((gr->num_gr_mem + 1) *
+
+ if ((tst = get_static(buffer, buflen, ((gr->num_gr_mem + 1) *
sizeof(char *)+i))) == NULL) {
/* Out of memory */
@@ -298,19 +330,16 @@ static NSS_STATUS fill_grent(struct group *result, struct winbindd_gr *gr,
i = 0;
- while(next_token((char **)&gr_mem, name, ",", sizeof(fstring))) {
-
+ while(next_token_alloc((const char **)&gr_mem, &name, ",")) {
/* Allocate space for member */
-
- if (((result->gr_mem)[i] =
+ if (((result->gr_mem)[i] =
get_static(buffer, buflen, strlen(name) + 1)) == NULL) {
-
+ free(name);
/* Out of memory */
-
return NSS_STATUS_TRYAGAIN;
- }
-
+ }
strcpy((result->gr_mem)[i], name);
+ free(name);
i++;
}