1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

Remove pstring from nmbd.

Jeremy.
This commit is contained in:
Jeremy Allison 2007-11-19 15:15:09 -08:00
parent 759d6bcbec
commit a317f70c22
11 changed files with 189 additions and 124 deletions

View File

@ -783,20 +783,25 @@ XFILE *startlmhosts(const char *fname)
Parse the next line in the lmhosts file.
*********************************************************/
bool getlmhostsent(XFILE *fp, pstring name, int *name_type,
bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
struct sockaddr_storage *pss)
{
pstring line;
char line[1024];
*pp_name = NULL;
while(!x_feof(fp) && !x_ferror(fp)) {
pstring ip,flags,extra;
char ip[INET6_ADDRSTRLEN];
fstring flags;
fstring extra;
fstring name;
const char *ptr;
char *ptr1;
int count = 0;
*name_type = -1;
if (!fgets_slash(line,sizeof(pstring),fp)) {
if (!fgets_slash(line,sizeof(line),fp)) {
continue;
}
@ -804,15 +809,15 @@ bool getlmhostsent(XFILE *fp, pstring name, int *name_type,
continue;
}
pstrcpy(ip,"");
pstrcpy(name,"");
pstrcpy(flags,"");
ip[0] = '\0';
name[0] = '\0';
flags[0] = '\0';
ptr = line;
if (next_token(&ptr,ip ,NULL,sizeof(ip)))
++count;
if (next_token(&ptr,name ,NULL, sizeof(pstring)))
if (next_token(&ptr,name ,NULL, sizeof(name)))
++count;
if (next_token(&ptr,flags,NULL, sizeof(flags)))
++count;
@ -864,6 +869,10 @@ bool getlmhostsent(XFILE *fp, pstring name, int *name_type,
*(--ptr1) = '\0'; /* Truncate at the '#' */
}
*pp_name = talloc_strdup(ctx, name);
if (!*pp_name) {
return false;
}
return true;
}
@ -1135,10 +1144,11 @@ static NTSTATUS resolve_lmhosts(const char *name, int name_type,
*/
XFILE *fp;
pstring lmhost_name;
char *lmhost_name = NULL;
int name_type2;
struct sockaddr_storage return_ss;
NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
TALLOC_CTX *ctx = NULL;
*return_iplist = NULL;
*return_count = 0;
@ -1152,19 +1162,30 @@ static NTSTATUS resolve_lmhosts(const char *name, int name_type,
if ( fp == NULL )
return NT_STATUS_NO_SUCH_FILE;
while (getlmhostsent(fp, lmhost_name, &name_type2, &return_ss)) {
ctx = talloc_init("resolve_lmhosts");
if (!ctx) {
endlmhosts(fp);
return NT_STATUS_NO_MEMORY;
}
if (!strequal(name, lmhost_name))
continue;
while (getlmhostsent(ctx, fp, &lmhost_name, &name_type2, &return_ss)) {
if ((name_type2 != -1) && (name_type != name_type2))
if (!strequal(name, lmhost_name)) {
TALLOC_FREE(lmhost_name);
continue;
}
if ((name_type2 != -1) && (name_type != name_type2)) {
TALLOC_FREE(lmhost_name);
continue;
}
*return_iplist = SMB_REALLOC_ARRAY((*return_iplist),
struct ip_service,
(*return_count)+1);
if ((*return_iplist) == NULL) {
TALLOC_FREE(ctx);
endlmhosts(fp);
DEBUG(3,("resolve_lmhosts: malloc fail !\n"));
return NT_STATUS_NO_MEMORY;
@ -1182,6 +1203,7 @@ static NTSTATUS resolve_lmhosts(const char *name, int name_type,
break;
}
TALLOC_FREE(ctx);
endlmhosts(fp);
return status;
}

View File

@ -287,8 +287,7 @@ static bool reload_nmbd_services(bool test)
set_remote_machine_name("nmbd", False);
if ( lp_loaded() ) {
pstring fname;
pstrcpy( fname,lp_configfile());
const char *fname = lp_configfile();
if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
pstrcpy(dyn_CONFIGFILE,fname);
test = False;
@ -710,7 +709,6 @@ static bool open_sockets(bool isdaemon, int port)
static bool Fork = true;
static bool no_process_group;
static bool log_stdout;
pstring logfile;
poptContext pc;
static char *p_lmhosts = dyn_LMHOSTSFILE;
int opt;
@ -773,8 +771,12 @@ static bool open_sockets(bool isdaemon, int port)
sys_srandom(time(NULL) ^ sys_getpid());
if (!override_logfile) {
slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE);
char *logfile = NULL;
if (asprintf(&logfile, "%s/log.nmbd", dyn_LOGFILEBASE) < 0) {
exit(1);
}
lp_set_logfile(logfile);
SAFE_FREE(logfile);
}
fault_setup((void (*)(void *))fault_continue );

View File

@ -98,7 +98,7 @@ As a local master browser, send an announce packet to the domain master browser.
static void announce_local_master_browser_to_domain_master_browser( struct work_record *work)
{
pstring outbuf;
char outbuf[1024];
unstring myname;
unstring dmb_name;
char *p;
@ -122,7 +122,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_
strupper_m(myname);
myname[15]='\0';
/* The call below does CH_UNIX -> CH_DOS conversion. JRA */
push_pstring_base(p, myname, outbuf);
push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
p = skip_string(outbuf,sizeof(outbuf),p);

View File

@ -32,7 +32,7 @@ extern time_t StartupTime;
static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name,
uint32 criterion, int timeup,const char *server_name)
{
pstring outbuf;
char outbuf[1024];
unstring srv_name;
char *p;
@ -51,7 +51,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr
unstrcpy(srv_name, server_name);
strupper_m(srv_name);
/* The following call does UNIX -> DOS charset conversion. */
pstrcpy_base(p, srv_name, outbuf);
push_ascii(p, srv_name, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
p = skip_string(outbuf,sizeof(outbuf),p);
send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),

View File

@ -571,7 +571,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
unstrcpy(myname, global_myname());
strupper_m(myname);
myname[15]='\0';
push_pstring_base(p, myname, outbuf);
push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
p = skip_string(outbuf,sizeof(outbuf),p);

View File

@ -30,23 +30,26 @@ Load a lmhosts file.
void load_lmhosts_file(const char *fname)
{
pstring name;
char *name = NULL;
int name_type;
struct sockaddr_storage ss;
TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
XFILE *fp = startlmhosts( fname );
if (!fp) {
DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
fname, strerror(errno)));
TALLOC_FREE(ctx);
return;
}
while (getlmhostsent(fp, name, &name_type, &ss) ) {
while (getlmhostsent(ctx, fp, &name, &name_type, &ss) ) {
struct in_addr ipaddr;
struct subnet_record *subrec = NULL;
enum name_source source = LMHOSTS_NAME;
if (ss.ss_family != AF_INET) {
TALLOC_FREE(name);
continue;
}
@ -73,6 +76,7 @@ void load_lmhosts_file(const char *fname)
}
}
TALLOC_FREE(ctx);
endlmhosts(fp);
}

View File

@ -39,9 +39,9 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len,
const char *mailslot)
{
struct dgram_packet *dgram = &p->packet.dgram;
pstring my_name;
fstring my_name;
fstring reply_name;
pstring outbuf;
char outbuf[1024];
int code;
uint16 token = 0;
uint32 ntversion = 0;
@ -51,7 +51,7 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len,
bool short_request = False;
char *getdc;
char *uniuser; /* Unicode user name. */
pstring ascuser;
fstring ascuser;
char *unicomp; /* Unicode computer name. */
size_t size;
struct sockaddr_storage ss;
@ -76,7 +76,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
return;
}
pstrcpy(my_name, global_myname());
fstrcpy(my_name, global_myname());
code = get_safe_SVAL(buf,len,buf,0,-1);
DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code));
@ -237,12 +237,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
q = ALIGN2(q, outbuf);
q += dos_PutUniCode(q, my_name,
sizeof(pstring) - PTR_DIFF(q, outbuf),
sizeof(outbuf) - PTR_DIFF(q, outbuf),
True); /* PDC name */
q += dos_PutUniCode(q, lp_workgroup(),
sizeof(pstring) - PTR_DIFF(q, outbuf),
sizeof(outbuf) - PTR_DIFF(q, outbuf),
True); /* Domain name*/
if (sizeof(pstring) - PTR_DIFF(q, outbuf) < 8) {
if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) {
return;
}
SIVAL(q, 0, 1); /* our nt version */
@ -355,7 +355,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
* database. If it isn't then we let smbd send an appropriate error.
* Let's ignore the SID.
*/
pull_ucs2_pstring(ascuser, uniuser);
pull_ucs2_fstring(ascuser, uniuser);
pull_ucs2_fstring(asccomp, unicomp);
DEBUG(5,("process_logon_packet: SAMLOGON user %s\n", ascuser));
@ -381,13 +381,13 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
q += 2;
q += dos_PutUniCode(q, reply_name,
sizeof(pstring) - PTR_DIFF(q, outbuf),
sizeof(outbuf) - PTR_DIFF(q, outbuf),
True);
q += dos_PutUniCode(q, ascuser,
sizeof(pstring) - PTR_DIFF(q, outbuf),
sizeof(outbuf) - PTR_DIFF(q, outbuf),
True);
q += dos_PutUniCode(q, lp_workgroup(),
sizeof(pstring) - PTR_DIFF(q, outbuf),
sizeof(outbuf) - PTR_DIFF(q, outbuf),
True);
}
#ifdef HAVE_ADS

View File

@ -457,7 +457,7 @@ void announce_remote(time_t t)
char *s;
const char *ptr;
static time_t last_time = 0;
pstring s2;
fstring s2;
struct in_addr addr;
char *comment;
int stype = lp_default_server_announce();
@ -522,10 +522,10 @@ void browse_sync_remote(time_t t)
char *s;
const char *ptr;
static time_t last_time = 0;
pstring s2;
fstring s2;
struct in_addr addr;
struct work_record *work;
pstring outbuf;
char outbuf[1024];
char *p;
unstring myname;
@ -563,7 +563,7 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name ));
unstrcpy(myname, global_myname());
strupper_m(myname);
myname[15]='\0';
push_pstring_base(p, myname, outbuf);
push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
p = skip_string(outbuf,sizeof(outbuf),p);

View File

@ -293,12 +293,14 @@ void write_browse_list(time_t t, bool force_write)
struct subnet_record *subrec;
struct work_record *work;
struct server_record *servrec;
pstring fname,fnamenew;
char *fname;
char *fnamenew;
uint32 stype;
int i;
XFILE *fp;
bool list_changed = force_write;
static time_t lasttime = 0;
TALLOC_CTX *ctx = talloc_tos();
/* Always dump if we're being told to by a signal. */
if(force_write == False) {
@ -324,12 +326,22 @@ void write_browse_list(time_t t, bool force_write)
updatecount++;
pstrcpy(fname,lp_lockdir());
fname = talloc_strdup(ctx, lp_lockdir());
if (!fname) {
return;
}
trim_char(fname,'\0' ,'/');
pstrcat(fname,"/");
pstrcat(fname,SERVER_LIST);
pstrcpy(fnamenew,fname);
pstrcat(fnamenew,".");
fname = talloc_asprintf_append(fname,
"/%s",
SERVER_LIST);
if (!fname) {
return;
}
fnamenew = talloc_asprintf(ctx, "%s.",
fname);
if (!fnamenew) {
return;
}
fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);

View File

@ -32,7 +32,7 @@ struct sync_record {
struct sync_record *next, *prev;
unstring workgroup;
unstring server;
pstring fname;
char *fname;
struct in_addr ip;
pid_t pid;
};
@ -164,8 +164,11 @@ done:
unstrcpy(s->server, name);
s->ip = ip;
slprintf(s->fname, sizeof(pstring)-1,
"%s/sync.%d", lp_lockdir(), counter++);
if (asprintf(&s->fname, "%s/sync.%d", lp_lockdir(), counter++) < 0) {
SAFE_FREE(s);
goto done;
}
/* Safe to use as 0 means no size change. */
all_string_sub(s->fname,"//", "/", 0);
DLIST_ADD(syncs, s);
@ -257,8 +260,8 @@ static void complete_sync(struct sync_record *s)
XFILE *f;
unstring server, type_str;
unsigned type;
pstring comment;
pstring line;
fstring comment;
char line[1024];
const char *ptr;
int count=0;
@ -269,7 +272,7 @@ static void complete_sync(struct sync_record *s)
while (!x_feof(f)) {
if (!fgets_slash(line,sizeof(pstring),f))
if (!fgets_slash(line,sizeof(line),f))
continue;
ptr = line;
@ -309,7 +312,7 @@ void sync_check_completion(void)
/* it has completed - grab the info */
complete_sync(s);
DLIST_REMOVE(syncs, s);
ZERO_STRUCTP(s);
SAFE_FREE(s->fname);
SAFE_FREE(s);
}
}

View File

@ -437,10 +437,11 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, bool update)
static void wins_hook(const char *operation, struct name_record *namerec, int ttl)
{
pstring command;
char *command = NULL;
char *cmd = lp_wins_hook();
char *p, *namestr;
int i;
TALLOC_CTX *ctx = talloc_tos();
wins_store_changed_namerec(namerec);
@ -462,20 +463,29 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt
*p = 0;
}
p = command;
p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d",
cmd,
operation,
namestr,
namerec->name.name_type,
ttl);
command = talloc_asprintf(ctx,
"%s %s %s %02x %d",
cmd,
operation,
namestr,
namerec->name.name_type,
ttl);
if (!command) {
return;
}
for (i=0;i<namerec->data.num_ips;i++) {
p += slprintf(p, sizeof(command) - (p-command) -1, " %s", inet_ntoa(namerec->data.ip[i]));
command = talloc_asprintf_append(command,
" %s",
inet_ntoa(namerec->data.ip[i]));
if (!command) {
return;
}
}
DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name)));
smbrun(command, NULL);
TALLOC_FREE(command);
}
/****************************************************************************
@ -566,7 +576,7 @@ bool initialise_wins(void)
{
time_t time_now = time(NULL);
XFILE *fp;
pstring line;
char line[1024];
if(!lp_we_are_a_wins_server()) {
return True;
@ -591,9 +601,11 @@ bool initialise_wins(void)
}
while (!x_feof(fp)) {
pstring name_str, ip_str, ttl_str, nb_flags_str;
fstring name_str;
char ip_str[1024];
fstring ttl_str, nb_flags_str;
unsigned int num_ips;
pstring name;
char *name;
struct in_addr *ip_list;
int type = 0;
int nb_flags;
@ -608,7 +620,7 @@ bool initialise_wins(void)
/* Read a line from the wins.dat file. Strips whitespace
from the beginning and end of the line. */
if (!fgets_slash(line,sizeof(pstring),fp))
if (!fgets_slash(line,sizeof(line),fp))
continue;
if (*line == '#')
@ -700,7 +712,7 @@ bool initialise_wins(void)
}
/* Netbios name. # divides the name from the type (hex): netbios#xx */
pstrcpy(name,name_str);
name = name_str;
if((p = strchr(name,'#')) != NULL) {
*p = 0;
@ -2310,7 +2322,8 @@ static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA db
void wins_write_database(time_t t, bool background)
{
static time_t last_write_time = 0;
pstring fname, fnamenew;
char *fname = NULL;
char *fnamenew = NULL;
XFILE *fp;
@ -2342,16 +2355,19 @@ void wins_write_database(time_t t, bool background)
}
}
slprintf(fname,sizeof(fname)-1,"%s/%s", dyn_STATEDIR(), WINS_LIST);
if (asprintf(&fname, "%s/%s", dyn_STATEDIR(), WINS_LIST) < 0) {
goto err_exit;
}
/* This is safe as the 0 length means "don't expand". */
all_string_sub(fname,"//", "/", 0);
slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid());
if (asprintf(&fnamenew, "%s.%u", fname, (unsigned int)sys_getpid()) < 0) {
goto err_exit;
}
if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) {
DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno)));
if (background) {
_exit(0);
}
return;
goto err_exit;
}
DEBUG(4,("wins_write_database: Dump of WINS name list.\n"));
@ -2364,6 +2380,12 @@ void wins_write_database(time_t t, bool background)
chmod(fnamenew,0644);
unlink(fname);
rename(fnamenew,fname);
err_exit:
SAFE_FREE(fname);
SAFE_FREE(fnamenew);
if (background) {
_exit(0);
}