if (*workstation_list) {
bool invalid_ws = True;
- fstring tok;
+ char *tok;
const char *s = workstation_list;
const char *machine_name = talloc_asprintf(mem_ctx, "%s$", user_info->wksta_name);
if (machine_name == NULL)
return NT_STATUS_NO_MEMORY;
-
-
- while (next_token(&s, tok, ",", sizeof(tok))) {
+
+ while (next_token_talloc(mem_ctx, &s, &tok, ",")) {
DEBUG(10,("sam_account_ok: checking for workstation match %s and %s\n",
tok, user_info->wksta_name));
if(strequal(tok, user_info->wksta_name)) {
break;
}
}
+ TALLOC_FREE(tok);
}
-
- if (invalid_ws)
+ TALLOC_FREE(tok);
+
+ if (invalid_ws)
return NT_STATUS_INVALID_WORKSTATION;
}
DEBUG(2,("sam_account_ok: Domain trust account %s denied by server\n", pdb_get_username(sampass)));
return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT;
}
-
+
if (acct_ctrl & ACB_SVRTRUST) {
if (!(user_info->logon_parameters & MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT)) {
DEBUG(2,("sam_account_ok: Server trust account %s denied by server\n", pdb_get_username(sampass)));
static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
{
struct cli_state *cli = NULL;
- fstring desthost;
+ char *desthost = NULL;
struct sockaddr_storage dest_ss;
const char *p;
- char *pserver;
+ char *pserver = NULL;
bool connected_ok = False;
if (!(cli = cli_initialise()))
pserver = talloc_strdup(mem_ctx, lp_passwordserver());
p = pserver;
- while(next_token( &p, desthost, LIST_SEP, sizeof(desthost))) {
+ while(next_token_talloc(mem_ctx, &p, &desthost, LIST_SEP)) {
NTSTATUS status;
- standard_sub_basic(current_user_info.smb_name, current_user_info.domain,
- desthost, sizeof(desthost));
+ desthost = talloc_sub_basic(mem_ctx,
+ current_user_info.smb_name,
+ current_user_info.domain,
+ desthost);
+ if (!desthost) {
+ return NULL;
+ }
strupper_m(desthost);
if(!resolve_name( desthost, &dest_ss, 0x20)) {
continue;
}
- /* we use a mutex to prevent two connections at once - when a
- Win2k PDC get two connections where one hasn't completed a
- session setup yet it will send a TCP reset to the first
+ /* we use a mutex to prevent two connections at once - when a
+ Win2k PDC get two connections where one hasn't completed a
+ session setup yet it will send a TCP reset to the first
connection (tridge) */
if (!grab_server_mutex(desthost)) {
}
DEBUG(10,("server_cryptkey: failed to connect to server %s. Error %s\n",
desthost, nt_errstr(status) ));
+ release_server_mutex();
}
if (!connected_ok) {
- release_server_mutex();
DEBUG(0,("password server not available\n"));
cli_shutdown(cli);
return NULL;
}
-
- if (!attempt_netbios_session_request(&cli, global_myname(),
+
+ if (!attempt_netbios_session_request(&cli, global_myname(),
desthost, &dest_ss)) {
release_server_mutex();
DEBUG(1,("password server fails session request\n"));
cli_shutdown(cli);
return NULL;
}
-
+
if (strequal(desthost,myhostname())) {
exit_server_cleanly("Password server loop!");
}
-
+
DEBUG(3,("got session\n"));
if (!cli_negprot(cli)) {
return NULL;
}
- /* Get the first session setup done quickly, to avoid silly
+ /* Get the first session setup done quickly, to avoid silly
Win2k bugs. (The next connection to the server will kill
- this one...
+ this one...
*/
if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 0, "", 0,
cli_shutdown(cli);
return NULL;
}
-
+
release_server_mutex();
DEBUG(3,("password server OK\n"));
-
+
return cli;
}
static struct chat_struct *make_pw_chat(const char *p)
{
- fstring prompt;
- fstring reply;
+ char *prompt;
+ char *reply;
struct chat_struct *list = NULL;
struct chat_struct *t;
+ TALLOC_CTX *frame = talloc_stackframe();
while (1) {
t = SMB_MALLOC_P(struct chat_struct);
if (!t) {
DEBUG(0,("make_pw_chat: malloc failed!\n"));
+ TALLOC_FREE(frame);
return NULL;
}
DLIST_ADD_END(list, t, struct chat_struct*);
- if (!next_token(&p, prompt, NULL, sizeof(fstring)))
+ if (!next_token_talloc(frame, &p, &prompt, NULL)) {
break;
+ }
- if (strequal(prompt,"."))
+ if (strequal(prompt,".")) {
fstrcpy(prompt,"*");
+ }
special_char_sub(prompt);
fstrcpy(t->prompt, prompt);
strlower_m(t->prompt);
trim_char(t->prompt, ' ', ' ');
- if (!next_token(&p, reply, NULL, sizeof(fstring)))
+ if (!next_token_talloc(frame, &p, reply, NULL)) {
break;
+ }
- if (strequal(reply,"."))
- fstrcpy(reply,"");
+ if (strequal(reply,".")) {
+ fstrcpy(reply,"");
+ }
special_char_sub(reply);
fstrcpy(t->reply, reply);
trim_char(t->reply, ' ', ' ');
}
+ TALLOC_FREE(frame);
return list;
}
TDB_DATA data, void *state)
{
const char *p = (const char *)data.dptr;
- fstring string_sid;
+ char *string_sid;
DOM_SID member;
+ TALLOC_CTX *frame;
if (strncmp((char *)key.dptr, MEMBEROF_PREFIX,
MIN(key.dsize, strlen(MEMBEROF_PREFIX))) != 0) {
*(int *)state = -1;
}
- while (next_token(&p, string_sid, " ", sizeof(string_sid))) {
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame,&p, &string_sid, " ")) {
DOM_SID alias;
NTSTATUS status;
string_to_sid(&alias, string_sid);
DEBUG(0,("Failed to add alias member during upgrade - %s\n",
nt_errstr(status)));
*(int *)state = -1;
+ TALLOC_FREE(frame);
return -1;
}
}
-
+ TALLOC_FREE(frame);
return 0;
}
static NTSTATUS one_alias_membership(const DOM_SID *member,
DOM_SID **sids, size_t *num)
{
- fstring key, string_sid;
+ fstring key;
+ char *string_sid;
TDB_DATA dbuf;
const char *p;
+ TALLOC_CTX *frame;
sid_to_string(string_sid, member);
slprintf(key, sizeof(key), "%s%s", MEMBEROF_PREFIX, string_sid);
}
p = (const char *)dbuf.dptr;
-
- while (next_token(&p, string_sid, " ", sizeof(string_sid))) {
-
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame, &p, &string_sid, " ")) {
DOM_SID alias;
if (!string_to_sid(&alias, string_sid))
continue;
if (!add_sid_to_array_unique(NULL, &alias, sids, num)) {
+ TALLOC_FREE(frame);
return NT_STATUS_NO_MEMORY;
}
}
+ TALLOC_FREE(frame);
SAFE_FREE(dbuf.dptr);
return NT_STATUS_OK;
}
{
struct aliasmem_closure *closure = (struct aliasmem_closure *)state;
const char *p;
- fstring alias_string;
+ char *alias_string;
+ TALLOC_CTX *frame;
if (strncmp((const char *)key.dptr, MEMBEROF_PREFIX,
strlen(MEMBEROF_PREFIX)) != 0)
p = (const char *)data.dptr;
- while (next_token(&p, alias_string, " ", sizeof(alias_string))) {
-
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame, &p, &alias_string, " ")) {
DOM_SID alias, member;
const char *member_string;
-
if (!string_to_sid(&alias, alias_string))
continue;
if (!string_to_sid(&member, member_string))
continue;
-
+
if (!add_sid_to_array(NULL, &member, closure->sids, closure->num)) {
/* talloc fail. */
break;
}
}
+ TALLOC_FREE(frame);
return 0;
}
uint32 g_access;
uint32 s_access;
DOM_SID sid;
- fstring sidstr;
+ char *sidstr;
uint8 type = SEC_ACE_TYPE_ACCESS_ALLOWED;
- if (!next_token(&pacl, sidstr, ":", sizeof(sidstr))) {
+ if (!next_token_talloc(ctx, &pacl, &sidstr, ":")) {
DEBUG(0,("parse_usershare_acl: malformed usershare acl looking "
"for ':' in string '%s'\n", pacl));
return False;
void set_socket_options(int fd, const char *options)
{
- fstring tok;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ char *tok;
- while (next_token(&options,tok," \t,", sizeof(tok))) {
+ while (next_token_talloc(ctx, &options, &tok," \t,")) {
int ret=0,i;
int value = 1;
char *p;
}
}
+ TALLOC_FREE(ctx);
print_socket_options(fd);
}
* @brief String utilities.
**/
-/**
- * Internal function to get the next token from a string, return false if none
- * found. Handles double-quotes. This is the work horse function called by
- * next_token() and next_token_no_ltrim().
- *
- * Based on a routine by GJC@VILLAGE.COM.
- * Extensively modified by Andrew.Tridgell@anu.edu.au
- */
-static bool next_token_internal(const char **ptr,
- char *buff,
- const char *sep,
- size_t bufsize,
- bool ltrim)
-{
- char *s;
- char *pbuf;
- bool quoted;
- size_t len=1;
-
- if (!ptr)
- return(false);
-
- s = (char *)*ptr;
-
- /* default to simple separators */
- if (!sep)
- sep = " \t\n\r";
-
- /* find the first non sep char, if left-trimming is requested */
- if (ltrim) {
- while (*s && strchr_m(sep,*s))
- s++;
- }
-
- /* nothing left? */
- if (! *s)
- return(false);
-
- /* copy over the token */
- pbuf = buff;
- for (quoted = false; len < bufsize && *s &&
- (quoted || !strchr_m(sep,*s)); s++) {
- if ( *s == '\"' ) {
- quoted = !quoted;
- } else {
- len++;
- *pbuf++ = *s;
- }
- }
-
- *ptr = (*s) ? s+1 : s;
- *pbuf = 0;
-
- return(true);
-}
-
static bool next_token_internal_talloc(TALLOC_CTX *ctx,
const char **ptr,
char **pp_buff,
/* find the first non sep char, if left-trimming is requested */
if (ltrim) {
- while (*s && strchr_m(sep,*s))
+ while (*s && strchr_m(sep,*s)) {
s++;
+ }
}
/* nothing left? */
return true;
}
+#if 0
/*
* Get the next token from a string, return false if none found. Handles
* double-quotes. This version trims leading separator characters before
{
return next_token_internal(ptr, buff, sep, bufsize, true);
}
+#endif
bool next_token_talloc(TALLOC_CTX *ctx,
const char **ptr,
* double-quotes. This version does not trim leading separator characters
* before looking for a token.
*/
-bool next_token_no_ltrim(const char **ptr,
- char *buff,
- const char *sep,
- size_t bufsize)
-{
- return next_token_internal(ptr, buff, sep, bufsize, false);
-}
bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
const char **ptr,
static const char *last_ptr=NULL;
-bool next_token_nr(const char **ptr,char *buff, const char *sep, size_t bufsize)
-{
- bool ret;
- if (!ptr) {
- ptr = &last_ptr;
- }
-
- ret = next_token(ptr, buff, sep, bufsize);
- last_ptr = *ptr;
- return ret;
-}
-
bool next_token_nr_talloc(TALLOC_CTX *ctx,
const char **ptr,
char **pp_buff,
bool in_list(const char *s, const char *list, bool casesensitive)
{
- char *tok;
- const char *p=list;
- size_t bufsize = strlen(list);
+ char *tok = NULL;
bool ret = false;
+ TALLOC_CTX *frame;
- if (!list)
- return(false);
-
- /* We know a token can't be larger
- * than the entire list. */
-
- tok = SMB_MALLOC_ARRAY(char, bufsize+1);
- if (!tok) {
+ if (!list) {
return false;
}
- while (next_token(&p,tok,LIST_SEP,bufsize+1)) {
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame, &list, &tok,LIST_SEP)) {
if (casesensitive) {
if (strcmp(tok,s) == 0) {
ret = true;
}
}
}
-
- SAFE_FREE(tok);
+ TALLOC_FREE(frame);
return ret;
}
int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list)
{
- fstring token_str;
+ TALLOC_CTX *frame;
+ char *token_str = NULL;
size_t count;
int i;
return 0;
}
- for ( i=0; next_token(&ipstr_list, token_str,
- IPSTR_LIST_SEP, FSTRING_LEN) && i<count; i++ ) {
+ frame = talloc_stackframe();
+ for ( i=0; next_token_talloc(frame, &ipstr_list, &token_str,
+ IPSTR_LIST_SEP) && i<count; i++ ) {
char *s = token_str;
char *p = strrchr(token_str, ':');
continue;
}
}
-
+ TALLOC_FREE(frame);
return count;
}
char **nt_path,
char **unix_path)
{
- fstring tok;
char *path = NULL;
*server = NULL;
return NT_STATUS_OK;
}
- if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
+ if (!next_token_talloc(mem_ctx, &file_sys_path, server, "\\")) {
return NT_STATUS_INVALID_PARAMETER;
}
- if ((*server = talloc_strdup(mem_ctx, tok)) == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
+ if (!next_token_talloc(mem_ctx, &file_sys_path, service, "\\")) {
return NT_STATUS_INVALID_PARAMETER;
}
- if ((*service = talloc_strdup(mem_ctx, tok)) == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
if ((*nt_path = talloc_asprintf(mem_ctx, "\\%s", file_sys_path))
== NULL) {
return NT_STATUS_NO_MEMORY;
{
const char *top_dir = lock_path(GPO_CACHE_DIR);
char *current_dir;
- fstring tok;
+ char *tok;
current_dir = talloc_strdup(mem_ctx, top_dir);
NT_STATUS_HAVE_NO_MEMORY(current_dir);
return NT_STATUS_ACCESS_DENIED;
}
- while (next_token(&unix_path, tok, "/", sizeof(tok))) {
-
+ while (next_token_talloc(mem_ctx, &unix_path, &tok, "/")) {
if (strequal(tok, GPO_CACHE_DIR)) {
break;
}
}
- while (next_token(&unix_path, tok, "/", sizeof(tok))) {
-
+ while (next_token_talloc(mem_ctx, &unix_path, &tok, "/")) {
current_dir = talloc_asprintf_append_buffer(current_dir, "/%s", tok);
NT_STATUS_HAVE_NO_MEMORY(current_dir);
krb5_error_code ret = 0;
TALLOC_CTX *mem_ctx;
char keytab_string[MAX_KEYTAB_NAME_LEN];
+ char *kt_str = NULL;
bool found_valid_name = False;
const char *pragma = "FILE";
const char *tmp = NULL;
ret = ENOMEM;
goto out;
}
-
+
if (strncmp(tmp, "ANY:", 4) == 0) {
tmp += 4;
}
memset(&keytab_string, '\0', sizeof(keytab_string));
- while (next_token(&tmp, keytab_string, ",", sizeof(keytab_string))) {
-
- if (strncmp(keytab_string, "WRFILE:", 7) == 0) {
+ while (next_token_talloc(mem_ctx, &tmp, &kt_str, ",")) {
+ if (strncmp(kt_str, "WRFILE:", 7) == 0) {
found_valid_name = True;
- tmp = keytab_string;
+ tmp = kt_str;
tmp += 7;
}
- if (strncmp(keytab_string, "FILE:", 5) == 0) {
+ if (strncmp(kt_str, "FILE:", 5) == 0) {
found_valid_name = True;
- tmp = keytab_string;
+ tmp = kt_str;
tmp += 5;
}
if (found_valid_name) {
-
if (tmp[0] != '/') {
ret = KRB5_KT_BADNAME;
goto out;
break;
}
}
-
+
if (!found_valid_name) {
ret = KRB5_KT_UNKNOWN_TYPE;
goto out;
{
char *p;
const char *cp;
- fstring tok;
+ char *tok;
unsigned int atype;
unsigned int aflags;
unsigned int amask;
const char *perm;
uint32 mask;
};
+ TALLOC_CTX *frame = talloc_stackframe();
/* These values discovered by inspection */
static const struct perm_value special_values[] = {
ZERO_STRUCTP(ace);
p = strchr_m(str,':');
- if (!p) return False;
+ if (!p) {
+ TALLOC_FREE(frame);
+ return False;
+ }
*p = '\0';
p++;
/* Try to parse numeric form */
/* Try to parse text form */
if (!convert_string_to_sid(ipc_cli, pol, numeric, &sid, str)) {
- return False;
+ TALLOC_FREE(frame);
+ return false;
}
cp = p;
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
- return False;
+ if (!next_token_talloc(frame, &cp, &tok, "/")) {
+ TALLOC_FREE(frame);
+ return false;
}
if (StrnCaseCmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
} else if (StrnCaseCmp(tok, "DENIED", strlen("DENIED")) == 0) {
atype = SEC_ACE_TYPE_ACCESS_DENIED;
} else {
- return False;
+ TALLOC_FREE(frame);
+ return false;
}
/* Only numeric form accepted for flags at present */
- if (!(next_token(&cp, tok, "/", sizeof(fstring)) &&
+ if (!(next_token_talloc(frame, &cp, &tok, "/") &&
sscanf(tok, "%i", &aflags))) {
- return False;
+ TALLOC_FREE(frame);
+ return false;
}
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
- return False;
+ if (!next_token_talloc(frame, &cp, &tok, "/")) {
+ TALLOC_FREE(frame);
+ return false;
}
if (strncmp(tok, "0x", 2) == 0) {
if (sscanf(tok, "%i", &amask) != 1) {
- return False;
+ TALLOC_FREE(frame);
+ return false;
}
goto done;
}
}
}
- if (!found) return False;
+ if (!found) {
+ TALLOC_FREE(frame);
+ return false;
+ }
p++;
}
if (*p) {
- return False;
+ TALLOC_FREE(frame);
+ return false;
}
done:
mask = amask;
init_sec_ace(ace, &sid, atype, mask, aflags);
- return True;
+ TALLOC_FREE(frame);
+ return true;
}
/* add an ACE to a list of ACEs in a SEC_ACL */
char *str)
{
const char *p = str;
- fstring tok;
+ char *tok;
SEC_DESC *ret = NULL;
size_t sd_size;
DOM_SID *group_sid=NULL;
SEC_ACL *dacl=NULL;
int revision=1;
- while (next_token(&p, tok, "\t,\r\n", sizeof(tok))) {
+ while (next_token_talloc(ctx, &p, &tok, "\t,\r\n")) {
if (StrnCaseCmp(tok,"REVISION:", 9) == 0) {
revision = strtol(tok+9, NULL, 16);
{
int n;
const char *p = str;
- fstring tok;
+ char *tok = NULL;
+ TALLOC_CTX *frame = NULL;
struct {
const char * create_time_attr;
const char * access_time_attr;
}
}
- while (next_token(&p, tok, "\t,\r\n", sizeof(tok))) {
-
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame, &p, &tok, "\t,\r\n")) {
if (StrnCaseCmp(tok, "MODE:", 5) == 0) {
dad->mode = strtol(tok+5, NULL, 16);
continue;
continue;
}
}
+ TALLOC_FREE(frame);
}
/*****************************************************
*pp_name = NULL;
while(!x_feof(fp) && !x_ferror(fp)) {
- char ip[INET6_ADDRSTRLEN];
- fstring flags;
- fstring extra;
- fstring name;
+ char *ip;
+ char *flags;
+ char *extra;
+ char *name;
const char *ptr;
char *ptr1;
int count = 0;
ptr = line;
- if (next_token(&ptr,ip ,NULL,sizeof(ip)))
+ if (next_token_talloc(ctx, &ptr, &ip, NULL))
++count;
- if (next_token(&ptr,name ,NULL, sizeof(name)))
+ if (next_token_talloc(ctx, &ptr, &name, NULL))
++count;
- if (next_token(&ptr,flags,NULL, sizeof(flags)))
+ if (next_token_talloc(ctx, &ptr, &flags, NULL))
++count;
- if (next_token(&ptr,extra,NULL, sizeof(extra)))
+ if (next_token_talloc(ctx, &ptr, &extra, NULL))
++count;
if (count <= 0)
const char *resolve_order)
{
const char *name_resolve_list;
- fstring tok;
+ char *tok;
const char *ptr;
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
int i;
+ TALLOC_CTX *frame = NULL;
*return_iplist = NULL;
*return_count = 0;
/* iterate through the name resolution backends */
- while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) {
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame, &ptr, &tok, LIST_SEP)) {
if((strequal(tok, "host") || strequal(tok, "hosts"))) {
status = resolve_hosts(name, name_type, return_iplist,
return_count);
/* All of the resolve_* functions above have returned false. */
+ TALLOC_FREE(frame);
SAFE_FREE(*return_iplist);
*return_count = 0;
DEBUG(10, ("\n"));
}
+ TALLOC_FREE(frame);
return status;
}
const char *p;
char *port_str = NULL;
int port;
- fstring name;
+ char *name;
int num_addresses = 0;
int local_count, i, j;
struct ip_service *return_iplist = NULL;
*/
p = pserver;
- while (next_token(&p,name,LIST_SEP,sizeof(name))) {
+ while (next_token_talloc(ctx, &p, &name, LIST_SEP)) {
if (strequal(name, "*")) {
status = internal_resolve_name(domain, 0x1C, sitename,
&auto_ip_list,
/* fill in the return list now with real IP's */
while ((local_count<num_addresses) &&
- next_token(&p,name,LIST_SEP,sizeof(name))) {
+ next_token_talloc(ctx, &p, &name, LIST_SEP)) {
struct sockaddr_storage name_ss;
/* copy any addersses from the auto lookup */
char *s;
const char *ptr;
static time_t last_time = 0;
- fstring s2;
+ char *s2;
struct in_addr addr;
char *comment;
int stype = lp_default_server_announce();
+ TALLOC_CTX *frame = NULL;
if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
return;
comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH);
- for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
+ frame = talloc_stackframe();
+ for (ptr=s; next_token_talloc(frame,&ptr,&s2,NULL); ) {
/* The entries are of the form a.b.c.d/WORKGROUP with
WORKGROUP being optional */
const char *wgroup;
comment);
}
}
+ TALLOC_FREE(frame);
}
/****************************************************************************
char *s;
const char *ptr;
static time_t last_time = 0;
- fstring s2;
+ char *s2;
struct in_addr addr;
struct work_record *work;
char outbuf[1024];
char *p;
unstring myname;
+ TALLOC_CTX *frame = NULL;
if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
return;
p = skip_string(outbuf,sizeof(outbuf),p);
- for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
+ frame = talloc_stackframe();
+ for (ptr=s; next_token_talloc(frame,&ptr,&s2,NULL); ) {
/* The entries are of the form a.b.c.d */
(void)interpret_addr2(&addr,s2);
send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT);
}
+ TALLOC_FREE(frame);
}
Handle one line from a completed sync file.
**********************************************************************/
-static void complete_one(struct sync_record *s,
+static void complete_one(struct sync_record *s,
char *sname, uint32 stype, char *comment)
{
struct work_record *work;
static void complete_sync(struct sync_record *s)
{
XFILE *f;
- unstring server, type_str;
+ char *server;
+ char *type_str;
unsigned type;
- fstring comment;
+ char *comment;
char line[1024];
const char *ptr;
int count=0;
return;
while (!x_feof(f)) {
+ TALLOC_CTX *frame = NULL;
if (!fgets_slash(line,sizeof(line),f))
continue;
ptr = line;
- if (!next_token(&ptr,server,NULL,sizeof(server)) ||
- !next_token(&ptr,type_str,NULL, sizeof(type_str)) ||
- !next_token(&ptr,comment,NULL, sizeof(comment))) {
+ frame = talloc_stackframe();
+ if (!next_token_talloc(frame,&ptr,&server,NULL) ||
+ !next_token_talloc(frame,&ptr,&type_str,NULL) ||
+ !next_token_talloc(frame,&ptr,&comment,NULL)) {
+ TALLOC_FREE(frame);
continue;
}
complete_one(s, server, type, comment);
count++;
+ TALLOC_FREE(frame);
}
-
x_fclose(f);
unlink(s->fname);
}
while (!x_feof(fp)) {
- fstring name_str;
- char ip_str[1024];
- fstring ttl_str, nb_flags_str;
+ char *name_str = NULL;
+ char *ip_str = NULL;
+ char *ttl_str = NULL, *nb_flags_str = NULL;
unsigned int num_ips;
- char *name;
- struct in_addr *ip_list;
+ char *name = NULL;
+ struct in_addr *ip_list = NULL;
int type = 0;
int nb_flags;
int ttl;
const char *ptr;
- char *p;
+ char *p = NULL;
bool got_token;
bool was_ip;
int i;
unsigned int hash;
int version;
+ TALLOC_CTX *frame = NULL;
/* Read a line from the wins.dat file. Strips whitespace
from the beginning and end of the line. */
- if (!fgets_slash(line,sizeof(line),fp))
+ if (!fgets_slash(line,sizeof(line),fp)) {
continue;
+ }
- if (*line == '#')
+ if (*line == '#') {
continue;
+ }
if (strncmp(line,"VERSION ", 8) == 0) {
if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 ||
* time to actually parse them into the ip_list array.
*/
- if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) {
+ frame = talloc_stackframe();
+ if (!next_token_talloc(frame,&ptr,&name_str,NULL)) {
DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
- if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) {
+ if (!next_token_talloc(frame,&ptr,ttl_str,NULL)) {
DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
*/
num_ips = 0;
do {
- got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str));
+ got_token = next_token_talloc(frame,&ptr,&ip_str,NULL);
was_ip = False;
if(got_token && strchr(ip_str, '.')) {
num_ips++;
was_ip = True;
}
- } while( got_token && was_ip);
+ } while(got_token && was_ip);
if(num_ips == 0) {
DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
if(!got_token) {
DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) {
DEBUG(0,("initialise_wins: Malloc fail !\n"));
x_fclose(fp);
+ TALLOC_FREE(frame);
return False;
}
/* Reset and re-parse the line. */
ptr = line;
- next_token(&ptr,name_str,NULL,sizeof(name_str));
- next_token(&ptr,ttl_str,NULL,sizeof(ttl_str));
+ next_token_talloc(frame,&ptr,&name_str,NULL);
+ next_token_talloc(frame,&ptr,&ttl_str,NULL);
for(i = 0; i < num_ips; i++) {
- next_token(&ptr, ip_str, NULL, sizeof(ip_str));
+ next_token_talloc(frame,&ptr, &ip_str, NULL);
(void)interpret_addr2(&ip_list[i], ip_str);
}
- next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str));
+ next_token_talloc(frame,&ptr,&nb_flags_str,NULL);
- /*
+ /*
* Deal with SELF or REGISTER name encoding. Default is REGISTER
* for compatibility with old nmbds.
*/
if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') {
DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line));
SAFE_FREE(ip_list);
+ TALLOC_FREE(frame);
continue;
}
name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
}
+ TALLOC_FREE(frame);
SAFE_FREE(ip_list);
- }
-
+ }
+
x_fclose(fp);
return True;
}
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);
}
int num_rids;
uint32 *rids;
const char *p;
- char ridstr[32];
+ char *ridstr;
const char **names;
enum lsa_SidType *types;
const char *domain_name;
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);
}
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, ".") )
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;
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);
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;
}
/* 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;
}
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. */
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;
get_static(buffer, buflen, strlen(gr->gr_passwd) + 1)) == NULL) {
/* Out of memory */
-
return NSS_STATUS_TRYAGAIN;
}
/* 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 */
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++;
}
char **values = NULL;
int rc, num_result, num_values, rid;
char *suffix = NULL;
- fstring tok;
+ char *tok;
const char *p;
const char **attrs;
}
p = values[0];
- if (!next_token(&p, tok, "#", sizeof(tok))) {
+ if (!next_token_talloc(mem_ctx, &p, &tok, "#")) {
DEBUG(0,("ldapsam_get_seq_num: failed to parse sequence number\n"));
goto done;
}
Process time fields
********************************************************************/
-static time_t EntryTime(fstring tok[], int ptr, int count, int minimum)
+static time_t EntryTime(char *tok[], int ptr, int count, int minimum)
{
time_t jobtime,jobtime1;
if (count >= minimum) {
struct tm *t;
int i, day, hour, min, sec;
- char *c;
for (i=0; i<13; i++) {
if (!strncmp(tok[ptr], Months[i],3)) {
}
if (i<12) {
+ fstring c;
t = localtime(&jobtime);
if (!t) {
return (time_t)-1;
}
day = atoi(tok[ptr+1]);
- c=(char *)(tok[ptr+2]);
+ fstrcpy(c,tok[ptr+2]);
*(c+2)=0;
hour = atoi(c);
*(c+5)=0;
}
#endif /* OSF1 */
- /* FIXME: Use next_token rather than strtok! */
+ /* FIXME: Use next_token_talloc rather than strtok! */
tok[0] = strtok(line2," \t");
count++;
#define LPRNG_NTOK 7
#define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
- fstring tokarr[LPRNG_MAXTOK];
+ char *tokarr[LPRNG_MAXTOK];
const char *cptr;
char *ptr;
int num_tok = 0;
+ TALLOC_CTX *frame = talloc_stackframe();
cptr = line;
- while((num_tok < LPRNG_MAXTOK) && next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring))) {
+ while((num_tok < LPRNG_MAXTOK) && next_token_talloc(frame, &cptr,
+ &tokarr[num_tok], " \t")) {
num_tok++;
}
/* We must get at least LPRNG_NTOK tokens. */
if (num_tok < LPRNG_NTOK) {
+ TALLOC_FREE(frame);
return False;
}
if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
+ TALLOC_FREE(frame);
return False;
}
buf->fs_file[sizeof(buf->fs_file)-1] = '\0';
}
+ TALLOC_FREE(frame);
return True;
}
static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first)
{
- fstring tok[11];
+ char *tok[11];
int count=0;
const char *cline = line;
+ TALLOC_CTX *frame = talloc_stackframe();
/* handle the case of "(standard input)" as a filename */
string_sub(line,"standard input","STDIN",0);
all_string_sub(line,"(","\"",0);
all_string_sub(line,")","\"",0);
- for (count=0; count<10 && next_token(&cline,tok[count],NULL, sizeof(tok[count])); count++) {
+ for (count=0; count<10 &&
+ next_token_talloc(frame,&cline,&tok[count],NULL); count++) {
;
}
if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) {
/* the 2nd and 5th columns must be integer */
if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) {
+ TALLOC_FREE(frame);
return False;
}
buf->size = atoi(tok[4]) * 1024;
/* if the fname contains a space then use STDIN */
if (strchr_m(tok[2],' ')) {
- fstrcpy(tok[2],"STDIN");
+ tok[2] = talloc_strdup(frame,"STDIN");
+ if (!tok[2]) {
+ TALLOC_FREE(frame);
+ return false;
+ }
}
/* only take the last part of the filename */
{
- fstring tmp;
char *p = strrchr_m(tok[2],'/');
if (p) {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[2],tmp);
+ tok[2] = p+1;
}
}
fstrcpy(buf->fs_file,tok[2]);
} else {
DEBUG(6,("parse_lpq_aix count=%d\n", count));
+ TALLOC_FREE(frame);
return False;
}
} else {
/* the 4th and 9th columns must be integer */
if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) {
+ TALLOC_FREE(frame);
return False;
}
buf->size = atoi(tok[8]) * 1024;
/* if the fname contains a space then use STDIN */
if (strchr_m(tok[4],' ')) {
- fstrcpy(tok[4],"STDIN");
+ tok[4] = talloc_strdup(frame,"STDIN");
+ if (!tok[4]) {
+ TALLOC_FREE(frame);
+ return false;
+ }
}
/* only take the last part of the filename */
{
- fstring tmp;
char *p = strrchr_m(tok[4],'/');
if (p) {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[4],tmp);
+ tok[4] = p+1;
}
}
fstrcpy(buf->fs_file,tok[4]);
}
+ TALLOC_FREE(frame);
return True;
}
with -p option first, to work */
static int base_prio;
int count;
- char htab = '\011';
+ char htab = '\011';
const char *cline = line;
- fstring tok[12];
+ char *tok[12];
+ TALLOC_CTX *frame = talloc_stackframe();
/* If a line begins with a horizontal TAB, it is a subline type */
-
+
if (line[0] == htab) { /* subline */
/* check if it contains the base priority */
if (!strncmp(line,"\tfence priority : ",18)) {
}
if (!header_line_ok) {
+ TALLOC_FREE(frame);
return False; /* incorrect header line */
}
string_sub(line,"standard input","STDIN",0);
all_string_sub(line,"(","\"",0);
all_string_sub(line,")","\"",0);
-
- for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
+
+ for (count=0; count<2 &&
+ next_token_talloc(frame, &cline, &tok[count],NULL);
+ count++) {
;
}
/* we must get 2 tokens */
if (count < 2) {
+ TALLOC_FREE(frame);
return False;
}
-
+
/* the 2nd column must be integer */
if (!isdigit((int)*tok[1])) {
+ TALLOC_FREE(frame);
return False;
}
-
+
/* if the fname contains a space then use STDIN */
if (strchr_m(tok[0],' ')) {
- fstrcpy(tok[0],"STDIN");
+ tok[0] = talloc_strdup(frame, "STDIN");
+ if (!tok[0]) {
+ TALLOC_FREE(frame);
+ return false;
+ }
}
-
+
buf->size = atoi(tok[1]);
fstrcpy(buf->fs_file,tok[0]);
-
+
/* fill things from header line */
buf->time = jobtime;
buf->job = jobid;
buf->status = jobstat;
buf->priority = jobprio;
fstrcpy(buf->fs_user,jobuser);
-
+
+ TALLOC_FREE(frame);
return True;
} else { /* header line */
header_line_ok=False; /* reset it */
} else if (base_prio) {
base_prio_reset=False;
}
-
+
/* handle the dash in the job id */
string_sub(line,"-"," ",0);
-
- for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
+
+ for (count=0; count<12 &&
+ next_token_talloc(frame, &cline, &tok[count],NULL);
+ count++) {
;
}
-
+
/* we must get 8 tokens */
if (count < 8) {
+ TALLOC_FREE(frame);
return False;
}
-
+
/* first token must be printer name (cannot check ?) */
/* the 2nd, 5th & 7th column must be integer */
if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) {
+ TALLOC_FREE(frame);
return False;
}
jobid = atoi(tok[1]);
fstrcpy(jobuser,tok[2]);
jobprio = atoi(tok[4]);
-
+
/* process time */
jobtime=EntryTime(tok, 5, count, 8);
if (jobprio < base_prio) {
jobstat = LPQ_PRINTING;
}
}
-
+
header_line_ok=True; /* information is correct */
+ TALLOC_FREE(frame);
return False; /* need subline info to include into queuelist */
}
}
static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first)
{
- fstring tok[9];
+ char *tok[9];
int count=0;
char *p;
const char *cline = line;
+ TALLOC_CTX *frame = NULL;
- /*
+ /*
* Handle the dash in the job id, but make sure that we skip over
* the printer name in case we have a dash in that.
* Patch from Dom.Mitchell@palmerharvey.co.uk.
*p = ' ';
}
- for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
+ frame = talloc_stackframe();
+ for (count=0; count<9 &&
+ next_token_talloc(frame, &cline, &tok[count],NULL);
+ count++) {
;
}
/* we must get 7 tokens */
if (count < 7) {
+ TALLOC_FREE(frame);
return False;
}
/* the 2nd and 4th, 6th columns must be integer */
if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) {
+ TALLOC_FREE(frame);
return False;
}
if (!isdigit((int)*tok[5])) {
+ TALLOC_FREE(frame);
return False;
}
- /* if the user contains a ! then trim the first part of it */
+ /* if the user contains a ! then trim the first part of it */
if ((p=strchr_m(tok[2],'!'))) {
- fstring tmp;
- fstrcpy(tmp,p+1);
- fstrcpy(tok[2],tmp);
+ tok[2] = p+1;
}
buf->job = atoi(tok[1]);
buf->time = EntryTime(tok, 4, count, 7);
fstrcpy(buf->fs_user,tok[2]);
fstrcpy(buf->fs_file,tok[2]);
+ TALLOC_FREE(frame);
return True;
}
here is an example of lpq output under qnx
Spooler: /qnx/spooler, on node 1
-Printer: txt (ready)
+Printer: txt (ready)
0000: root [job #1 ] active 1146 bytes /etc/profile
0001: root [job #2 ] ready 2378 bytes /etc/install
0002: root [job #3 ] ready 1146 bytes -- standard input --
static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first)
{
- fstring tok[7];
+ char *tok[7];
int count=0;
const char *cline = line;
+ TALLOC_CTX *frame = NULL;
DEBUG(4,("antes [%s]\n", line));
string_sub(line,"]","",0);
DEBUG(4,("despues 2 [%s]\n", line));
- for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
+ frame = talloc_stackframe();
+ for (count=0; count<7 &&
+ next_token_talloc(frame,&cline,&tok[count],NULL);
+ count++) {
;
}
/* we must get 7 tokens */
if (count < 7) {
+ TALLOC_FREE(frame);
return False;
}
/* the 3rd and 5th columns must be integer */
if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) {
+ TALLOC_FREE(frame);
return False;
}
/* only take the last part of the filename */
{
- fstring tmp;
char *p = strrchr_m(tok[6],'/');
if (p) {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[6],tmp);
+ tok[6] = p+1;
}
}
-
+
buf->job = atoi(tok[2]);
buf->size = atoi(tok[4]);
buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
buf->time = time(NULL);
fstrcpy(buf->fs_user,tok[1]);
fstrcpy(buf->fs_file,tok[6]);
+ TALLOC_FREE(frame);
return True;
}
static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first)
{
- fstring tok[11];
+ char *tok[11];
int count=0;
const char *cline = line;
+ TALLOC_CTX *frame = talloc_stackframe();
/* handle the case of "(standard input)" as a filename */
string_sub(line,"stdin","STDIN",0);
all_string_sub(line,"(","\"",0);
all_string_sub(line,")","\"",0);
-
- for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
+
+ for (count=0; count<11 &&
+ next_token_talloc(frame,&cline,&tok[count],NULL);
+ count++) {
;
}
/* we must get 11 tokens */
if (count < 11) {
+ TALLOC_FREE(frame);
return False;
}
/* the first must be "active" or begin with an integer */
if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) {
+ TALLOC_FREE(frame);
return False;
}
/* the 5th and 8th must be integer */
if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) {
+ TALLOC_FREE(frame);
return False;
}
/* if the fname contains a space then use STDIN */
if (strchr_m(tok[6],' ')) {
- fstrcpy(tok[6],"STDIN");
+ tok[6] = talloc_strdup(frame, "STDIN");
+ if (!tok[6]) {
+ TALLOC_FREE(frame);
+ return false;
+ }
}
/* only take the last part of the filename */
buf->time = time(NULL);
fstrcpy(buf->fs_user,tok[1]);
fstrcpy(buf->fs_file,tok[6]);
+ TALLOC_FREE(frame);
return True;
}
static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first)
{
int toknum = 0;
- fstring tok;
+ char *tok;
+ TALLOC_CTX *frame = talloc_stackframe();
const char *cline = line;
/* First line is printer status */
- if (!isdigit(line[0])) return False;
+ if (!isdigit(line[0])) {
+ TALLOC_FREE(frame);
+ return False;
+ }
/* Parse a print job entry */
- while(next_token(&cline, tok, NULL, sizeof(fstring))) {
+ while(next_token_talloc(frame, &cline, &tok, NULL)) {
switch (toknum) {
case 0:
buf->job = atoi(tok);
toknum++;
}
+ TALLOC_FREE(frame);
return True;
}
char *base = NULL;
char *remaining = NULL;
TALLOC_CTX *ctx = talloc_tos();
- fstring keyname, subkeyname;
+ char *keyname;
+ char *subkeyname;
REGSUBKEY_CTR *subkeys;
REGVAL_CTR *values;
int i;
}
p = path;
- while (next_token(&p, keyname, "\\", sizeof(keyname))) {
+ while (next_token_talloc(ctx, &p, &keyname, "\\")) {
/* build up the registry path from the components */
/* get the immediate subkeyname (if we have one ) */
- *subkeyname = '\0';
+ subkeyname = talloc_strdup(ctx, "");
+ if (!subkeyname) {
+ goto fail;
+ }
if (*p) {
TALLOC_FREE(remaining);
remaining = talloc_strdup(ctx, p);
}
p2 = remaining;
- if (!next_token(&p2, subkeyname, "\\",
- sizeof(subkeyname))) {
- fstrcpy( subkeyname, p2 );
+ if (!next_token_talloc(ctx, &p2,
+ &subkeyname, "\\")) {
+ subkeyname = talloc_strdup(ctx,p2);
+ if (!subkeyname) {
+ goto fail;
+ }
}
}
static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids)
{
const char *ptr;
- fstring s2;
+ char *s2;
int count = 0;
DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
if(sids_str) {
int number;
DOM_SID2 *sids;
+ TALLOC_CTX *frame = talloc_stackframe();
/* Count the number of valid SIDs. */
- for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
+ for (count = 0, ptr = sids_str;
+ next_token_talloc(frame,&ptr, &s2, NULL); ) {
DOM_SID tmpsid;
if (string_to_sid(&tmpsid, s2))
count++;
/* Now allocate space for them. */
if (count) {
*ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
- if (*ppsids == NULL)
+ if (*ppsids == NULL) {
+ TALLOC_FREE(frame);
return 0;
+ }
} else {
*ppsids = NULL;
}
sids = *ppsids;
- for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
+ for (number = 0, ptr = sids_str;
+ next_token_talloc(frame, &ptr, &s2, NULL); ) {
DOM_SID tmpsid;
if (string_to_sid(&tmpsid, s2)) {
/* count only valid sids */
number++;
}
}
+ TALLOC_FREE(frame);
}
return count;
static int talktochild(int master, const char *seq)
{
+ TALLOC_CTX *frame = talloc_stackframe();
int count = 0;
- fstring issue, expected;
+ char *issue;
+ char *expected;
- fstrcpy(issue, ".");
+ issue = talloc_strdup(frame, ".");
+ if (!issue) {
+ TALLOC_FREE(frame);
+ return false;
+ }
- while (next_token(&seq, expected, NULL, sizeof(expected)))
- {
+ while (next_token_talloc(frame, &seq, &expected, NULL)) {
pwd_sub(expected);
count++;
- if (!expect(master, issue, expected))
- {
+ if (!expect(master, issue, expected)) {
DEBUG(3, ("Response %d incorrect\n", count));
- return False;
+ TALLOC_FREE(frame);
+ return false;
}
- if (!next_token(&seq, issue, NULL, sizeof(issue)))
- fstrcpy(issue, ".");
-
+ if (!next_token_talloc(frame, &seq, &issue, NULL)) {
+ issue = talloc_strdup(frame, ".");
+ if (!issue) {
+ TALLOC_FREE(frame);
+ return false;
+ }
+ }
pwd_sub(issue);
}
+
if (!strequal(issue, ".")) {
/* we have one final issue to send */
- fstrcpy(expected, ".");
- if (!expect(master, issue, expected))
+ expected = talloc_strdup(frame, ".");
+ if (!expected) {
+ TALLOC_FREE(frame);
+ return false;
+ }
+ if (!expect(master, issue, expected)) {
+ TALLOC_FREE(frame);
return False;
+ }
}
-
+ TALLOC_FREE(frame);
return (count > 0);
}
struct srv_info_struct *s;
const char *ptr = lines[i];
bool ok = True;
+ TALLOC_CTX *frame = NULL;
+ char *p;
if (!*ptr) {
continue;
}
-
+
if (count == alloced) {
alloced += 10;
*servers = SMB_REALLOC_ARRAY(*servers,struct srv_info_struct, alloced);
memset((char *)((*servers)+count),'\0',sizeof(**servers)*(alloced-count));
}
s = &(*servers)[count];
-
- if (!next_token(&ptr,s->name, NULL, sizeof(s->name))) {
+
+ frame = talloc_stackframe();
+ s->name[0] = '\0';
+ if (!next_token_talloc(frame,&ptr,&p, NULL)) {
+ TALLOC_FREE(frame);
continue;
}
- if (!next_token(&ptr,stype, NULL, sizeof(stype))) {
+ fstrcpy(s->name, p);
+
+ stype[0] = '\0';
+ if (!next_token_talloc(frame,&ptr, &p, NULL)) {
+ TALLOC_FREE(frame);
continue;
}
- if (!next_token(&ptr,s->comment, NULL, sizeof(s->comment))) {
+ fstrcpy(stype, p);
+
+ s->comment[0] = '\0';
+ if (!next_token_talloc(frame,&ptr, &p, NULL)) {
+ TALLOC_FREE(frame);
continue;
}
- if (!next_token(&ptr,s->domain, NULL, sizeof(s->domain))) {
+ fstrcpy(s->comment, p);
+
+ s->domain[0] = '\0';
+ if (!next_token_talloc(frame,&ptr,&p, NULL)) {
/* this allows us to cope with an old nmbd */
- fstrcpy(s->domain,lp_workgroup());
+ fstrcpy(s->domain,lp_workgroup());
+ } else {
+ fstrcpy(s->domain, p);
}
-
- if (sscanf(stype,"%X",&s->type) != 1) {
- DEBUG(4,("r:host file "));
- ok = False;
+ TALLOC_FREE(frame);
+
+ if (sscanf(stype,"%X",&s->type) != 1) {
+ DEBUG(4,("r:host file "));
+ ok = False;
}
-
+
/* Filter the servers/domains we return based on what was asked for. */
/* Check to see if we are being asked for a local list only. */
}
/* doesn't match up: don't want it */
- if (!(servertype & s->type)) {
- DEBUG(4,("r:serv type "));
- ok = False;
+ if (!(servertype & s->type)) {
+ DEBUG(4,("r:serv type "));
+ ok = False;
}
-
+
if ((servertype & SV_TYPE_DOMAIN_ENUM) !=
(s->type & SV_TYPE_DOMAIN_ENUM)) {
DEBUG(4,("s: dom mismatch "));
/* Now open a listen socket for each of the
interfaces. */
for(i = 0; i < num_interfaces; i++) {
+ TALLOC_CTX *frame = NULL;
const struct sockaddr_storage *ifss =
iface_n_sockaddr_storage(i);
- fstring tok;
+ char *tok;
const char *ptr;
if (ifss == NULL) {
continue;
}
- for (ptr=ports; next_token(&ptr, tok, " \t,",
- sizeof(tok)); ) {
+ frame = talloc_stackframe();
+ for (ptr=ports;
+ next_token_talloc(frame,&ptr, &tok, " \t,");) {
unsigned port = atoi(tok);
if (port == 0 || port > 0xffff) {
continue;
DEBUG(0,("open_sockets_smbd: listen: "
"%s\n", strerror(errno)));
close(s);
+ TALLOC_FREE(frame);
return False;
}
FD_SET(s,&listen_set);
if (num_sockets >= FD_SETSIZE) {
DEBUG(0,("open_sockets_smbd: Too "
"many sockets to bind to\n"));
+ TALLOC_FREE(frame);
return False;
}
}
+ TALLOC_FREE(frame);
}
} else {
/* Just bind to 0.0.0.0 - accept connections
from anywhere. */
- fstring tok;
+ TALLOC_CTX *frame = talloc_stackframe();
+ char *tok;
const char *ptr;
const char *sock_addr = lp_socket_address();
- fstring sock_tok;
+ char *sock_tok;
const char *sock_ptr;
if (strequal(sock_addr, "0.0.0.0") ||
#endif
}
- for (sock_ptr=sock_addr; next_token(&sock_ptr, sock_tok, " \t,",
- sizeof(sock_tok)); ) {
- for (ptr=ports; next_token(&ptr, tok, " \t,",
- sizeof(tok)); ) {
+ for (sock_ptr=sock_addr;
+ next_token_talloc(frame, &sock_ptr, &sock_tok, " \t,"); ) {
+ for (ptr=ports; next_token_talloc(frame, &ptr, &tok, " \t,"); ) {
struct sockaddr_storage ss;
unsigned port = atoi(tok);
"listen: %s\n",
strerror(errno)));
close(s);
+ TALLOC_FREE(frame);
return False;
}
if (num_sockets >= FD_SETSIZE) {
DEBUG(0,("open_sockets_smbd: Too "
"many sockets to bind to\n"));
+ TALLOC_FREE(frame);
return False;
}
}
}
+ TALLOC_FREE(frame);
}
SAFE_FREE(ports);
struct winbindd_request request;
struct winbindd_response response;
const char *extra_data;
- fstring name;
+ char *name;
int i;
struct user_token *result;
+ TALLOC_CTX *frame = NULL;
if (lp_winbind_use_default_domain() &&
(opt_target_workgroup == NULL)) {
ZERO_STRUCT(request);
ZERO_STRUCT(response);
-
+
if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) !=
NSS_STATUS_SUCCESS)
return False;
extra_data = (const char *)response.extra_data.data;
*num_tokens = 0;
- while(next_token(&extra_data, name, ",", sizeof(fstring))) {
+ frame = talloc_stackframe();
+ while(next_token_talloc(frame, &extra_data, &name, ",")) {
*num_tokens += 1;
}
if (result == NULL) {
DEBUG(1, ("Could not malloc sid array\n"));
+ TALLOC_FREE(frame);
return False;
}
extra_data = (const char *)response.extra_data.data;
i=0;
- while(next_token(&extra_data, name, ",", sizeof(fstring))) {
-
+ while(next_token_talloc(frame, &extra_data, &name, ",")) {
fstring domain, user;
char *p;
get_user_sids(domain, user, &(result[i].token));
i+=1;
}
-
+ TALLOC_FREE(frame);
SAFE_FREE(response.extra_data.data);
*user_tokens = result;
const char *p;
char *src_name;
char *dst_name;
- fstring version;
- fstring filename;
- fstring tok;
+ char *version;
+ char *filename;
+ char *tok;
/* scroll through the file until we have the part
beyond archi_table.short_archi */
p = file;
- while (next_token(&p, tok, "\\", sizeof(tok))) {
+ while (next_token_talloc(mem_ctx, &p, &tok, "\\")) {
if (strequal(tok, short_archi)) {
- next_token(&p, version, "\\", sizeof(version));
- next_token(&p, filename, "\\", sizeof(filename));
+ next_token_talloc(mem_ctx, &p, &version, "\\");
+ next_token_talloc(mem_ctx, &p, &filename, "\\");
}
}
{
char *p;
const char *cp;
- fstring tok;
+ char *tok;
unsigned int atype = 0;
unsigned int aflags = 0;
unsigned int amask = 0;
SEC_ACCESS mask;
const struct perm_value *v;
char *str = SMB_STRDUP(orig_str);
+ TALLOC_CTX *frame = talloc_stackframe();
if (!str) {
+ TALLOC_FREE(frame);
return False;
}
if (!p) {
printf("ACE '%s': missing ':'.\n", orig_str);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
*p = '\0';
printf("ACE '%s': failed to convert '%s' to SID\n",
orig_str, str);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
cp = p;
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
+ if (!next_token_talloc(frame, &cp, &tok, "/")) {
printf("ACE '%s': failed to find '/' character.\n",
orig_str);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
printf("ACE '%s': missing 'ALLOWED' or 'DENIED' entry at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
/* Only numeric form accepted for flags at present */
/* no flags on share permissions */
- if (!(next_token(&cp, tok, "/", sizeof(fstring)) &&
+ if (!(next_token_talloc(frame, &cp, &tok, "/") &&
sscanf(tok, "%i", &aflags) && aflags == 0)) {
printf("ACE '%s': bad integer flags entry at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
+ if (!next_token_talloc(frame, &cp, &tok, "/")) {
printf("ACE '%s': missing / at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
if (sscanf(tok, "%i", &amask) != 1) {
printf("ACE '%s': bad hex number at '%s'\n",
orig_str, tok);
+ TALLOC_FREE(frame);
SAFE_FREE(str);
return False;
}
if (!found) {
printf("ACE '%s': bad permission value at '%s'\n",
orig_str, p);
+ TALLOC_FREE(frame);
SAFE_FREE(str);
return False;
}
}
if (*p) {
+ TALLOC_FREE(frame);
SAFE_FREE(str);
return False;
}
mask = amask;
init_sec_ace(ace, &sid, atype, mask, aflags);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return True;
}
{
char *p;
const char *cp;
- fstring tok;
+ char *tok;
unsigned int atype = 0;
unsigned int aflags = 0;
unsigned int amask = 0;
SEC_ACCESS mask;
const struct perm_value *v;
char *str = SMB_STRDUP(orig_str);
+ TALLOC_CTX *frame = talloc_stackframe();
if (!str) {
+ TALLOC_FREE(frame);
return False;
}
if (!p) {
printf("ACE '%s': missing ':'.\n", orig_str);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
*p = '\0';
printf("ACE '%s': failed to convert '%s' to SID\n",
orig_str, str);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
cp = p;
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
+ if (!next_token_talloc(frame, &cp, &tok, "/")) {
printf("ACE '%s': failed to find '/' character.\n",
orig_str);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
printf("ACE '%s': missing 'ALLOWED' or 'DENIED' entry at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
/* Only numeric form accepted for flags at present */
- if (!(next_token(&cp, tok, "/", sizeof(fstring)) &&
+ if (!(next_token_talloc(frame, &cp, &tok, "/") &&
sscanf(tok, "%i", &aflags))) {
printf("ACE '%s': bad integer flags entry at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
+ if (!next_token_talloc(frame, &cp, &tok, "/")) {
printf("ACE '%s': missing / at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
printf("ACE '%s': bad hex number at '%s'\n",
orig_str, tok);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
goto done;
printf("ACE '%s': bad permission value at '%s'\n",
orig_str, p);
SAFE_FREE(str);
+ TALLOC_FREE(frame);
return False;
}
p++;
}
if (*p) {
+ TALLOC_FREE(frame);
SAFE_FREE(str);
return False;
}
done:
mask = amask;
init_sec_ace(ace, &sid, atype, mask, aflags);
+ TALLOC_FREE(frame);
SAFE_FREE(str);
return True;
}
}
/* parse a ascii version of a security descriptor */
-static SEC_DESC *sec_desc_parse(struct cli_state *cli, char *str)
+static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx, struct cli_state *cli, char *str)
{
const char *p = str;
- fstring tok;
+ char *tok;
SEC_DESC *ret = NULL;
size_t sd_size;
DOM_SID *grp_sid=NULL, *owner_sid=NULL;
SEC_ACL *dacl=NULL;
int revision=1;
- while (next_token(&p, tok, "\t,\r\n", sizeof(tok))) {
-
+ while (next_token_talloc(ctx, &p, &tok, "\t,\r\n")) {
if (strncmp(tok,"REVISION:", 9) == 0) {
revision = strtol(tok+9, NULL, 16);
continue;
goto done;
}
- ret = make_sec_desc(talloc_tos(),revision, SEC_DESC_SELF_RELATIVE, owner_sid, grp_sid,
+ ret = make_sec_desc(ctx,revision, SEC_DESC_SELF_RELATIVE, owner_sid, grp_sid,
NULL, dacl, &sd_size);
done:
size_t sd_size;
int result = EXIT_OK;
- sd = sec_desc_parse(cli, the_acl);
+ sd = sec_desc_parse(talloc_tos(), cli, the_acl);
if (!sd) return EXIT_PARSE_ERROR;
if (test_args) return EXIT_OK;
return NT_STATUS_OK;
}
-static NTSTATUS check_info3_in_group(TALLOC_CTX *mem_ctx,
+static NTSTATUS check_info3_in_group(TALLOC_CTX *mem_ctx,
NET_USER_INFO_3 *info3,
- const char *group_sid)
+ const char *group_sid)
/**
* Check whether a user belongs to a group or list of groups.
*
{
DOM_SID *require_membership_of_sid;
size_t num_require_membership_of_sid;
- fstring req_sid;
+ char *req_sid;
const char *p;
DOM_SID sid;
size_t i;
struct nt_user_token *token;
+ TALLOC_CTX *frame = NULL;
NTSTATUS status;
/* Parse the 'required group' SID */
-
+
if (!group_sid || !group_sid[0]) {
/* NO sid supplied, all users may access */
return NT_STATUS_OK;
p = group_sid;
- while (next_token(&p, req_sid, ",", sizeof(req_sid))) {
+ frame = talloc_stackframe();
+ while (next_token_talloc(frame, &p, &req_sid, ",")) {
if (!string_to_sid(&sid, req_sid)) {
DEBUG(0, ("check_info3_in_group: could not parse %s "
"as a SID!", req_sid));
+ TALLOC_FREE(frame);
return NT_STATUS_INVALID_PARAMETER;
}
&require_membership_of_sid,
&num_require_membership_of_sid)) {
DEBUG(0, ("add_sid_to_array failed\n"));
+ TALLOC_FREE(frame);
return NT_STATUS_NO_MEMORY;
}
}
+ TALLOC_FREE(frame);
+
status = sid_array_from_info3(mem_ctx, info3,
&token->user_sids,
&token->num_sids,