[SCM] Samba Shared Repository - branch v3-2-test updated -
initial-v3-2-unstable-336-ga317f70
Jeremy Allison
jra at samba.org
Mon Nov 19 23:15:46 GMT 2007
The branch, v3-2-test has been updated
via a317f70c229f7730279eaa323f7ebfd499257f76 (commit)
from 759d6bcbec07434667ab8dd9a09f37fbe243c208 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit a317f70c229f7730279eaa323f7ebfd499257f76
Author: Jeremy Allison <jra at samba.org>
Date: Mon Nov 19 15:15:09 2007 -0800
Remove pstring from nmbd.
Jeremy.
-----------------------------------------------------------------------
Summary of changes:
source/libsmb/namequery.c | 46 ++++++++++++++-----
source/nmbd/nmbd.c | 10 +++--
source/nmbd/nmbd_browsesync.c | 6 +-
source/nmbd/nmbd_elections.c | 6 +-
source/nmbd/nmbd_incomingdgrams.c | 12 +++---
source/nmbd/nmbd_lmhosts.c | 16 ++++---
source/nmbd/nmbd_processlogon.c | 24 +++++-----
source/nmbd/nmbd_sendannounce.c | 24 +++++-----
source/nmbd/nmbd_serverlistdb.c | 50 +++++++++++++--------
source/nmbd/nmbd_synclists.c | 31 +++++++------
source/nmbd/nmbd_winsserver.c | 86 +++++++++++++++++++++++--------------
11 files changed, 188 insertions(+), 123 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/libsmb/namequery.c b/source/libsmb/namequery.c
index dde758b..f4f9f84 100644
--- a/source/libsmb/namequery.c
+++ b/source/libsmb/namequery.c
@@ -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;
+ }
+
+ while (getlmhostsent(ctx, fp, &lmhost_name, &name_type2, &return_ss)) {
- if (!strequal(name, lmhost_name))
+ if (!strequal(name, lmhost_name)) {
+ TALLOC_FREE(lmhost_name);
continue;
+ }
- if ((name_type2 != -1) && (name_type != name_type2))
+ 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;
}
diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c
index beb178e..17e56b0 100644
--- a/source/nmbd/nmbd.c
+++ b/source/nmbd/nmbd.c
@@ -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 );
diff --git a/source/nmbd/nmbd_browsesync.c b/source/nmbd/nmbd_browsesync.c
index 4effce0..b630fd2 100644
--- a/source/nmbd/nmbd_browsesync.c
+++ b/source/nmbd/nmbd_browsesync.c
@@ -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);
@@ -136,7 +136,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_
/* Target name for send_mailslot must be in UNIX charset. */
pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name);
send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
- global_myname(), 0x0, dmb_name, 0x0,
+ global_myname(), 0x0, dmb_name, 0x0,
work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT);
}
diff --git a/source/nmbd/nmbd_elections.c b/source/nmbd/nmbd_elections.c
index db32461..bafe87c 100644
--- a/source/nmbd/nmbd_elections.c
+++ b/source/nmbd/nmbd_elections.c
@@ -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,9 +51,9 @@ 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),
global_myname(), 0,
workgroup_name, 0x1e,
diff --git a/source/nmbd/nmbd_incomingdgrams.c b/source/nmbd/nmbd_incomingdgrams.c
index 9fe344c..c0aa385 100644
--- a/source/nmbd/nmbd_incomingdgrams.c
+++ b/source/nmbd/nmbd_incomingdgrams.c
@@ -534,13 +534,13 @@ done:
Send a backup list response.
*****************************************************************************/
-static void send_backup_list_response(struct subnet_record *subrec,
+static void send_backup_list_response(struct subnet_record *subrec,
struct work_record *work,
struct nmb_name *send_to_name,
unsigned char max_number_requested,
uint32 token, struct in_addr sendto_ip,
int port)
-{
+{
char outbuf[1024];
char *p, *countptr;
unsigned int count = 0;
@@ -554,9 +554,9 @@ static void send_backup_list_response(struct subnet_record *subrec,
DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
-
+
p = outbuf;
-
+
SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
p++;
@@ -565,13 +565,13 @@ static void send_backup_list_response(struct subnet_record *subrec,
SIVAL(p,0,token); /* The sender's unique info. */
p += 4;
-
+
/* We always return at least one name - our own. */
count = 1;
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);
diff --git a/source/nmbd/nmbd_lmhosts.c b/source/nmbd/nmbd_lmhosts.c
index 51e4858..75c03bb 100644
--- a/source/nmbd/nmbd_lmhosts.c
+++ b/source/nmbd/nmbd_lmhosts.c
@@ -29,24 +29,27 @@ 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;
}
@@ -58,7 +61,7 @@ void load_lmhosts_file(const char *fname)
if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
break;
}
-
+
/* If none match add the name to the remote_broadcast_subnet. */
if(subrec == NULL)
subrec = remote_broadcast_subnet;
@@ -72,7 +75,8 @@ void load_lmhosts_file(const char *fname)
(void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
}
}
-
+
+ TALLOC_FREE(ctx);
endlmhosts(fp);
}
diff --git a/source/nmbd/nmbd_processlogon.c b/source/nmbd/nmbd_processlogon.c
index 8cbb873..0ff0afd 100644
--- a/source/nmbd/nmbd_processlogon.c
+++ b/source/nmbd/nmbd_processlogon.c
@@ -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));
@@ -107,7 +107,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
}
token = SVAL(q,3);
- fstrcpy(reply_name,my_name);
+ fstrcpy(reply_name,my_name);
pull_ascii_fstring(mach_str, machine);
pull_ascii_fstring(user_str, user);
@@ -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
diff --git a/source/nmbd/nmbd_sendannounce.c b/source/nmbd/nmbd_sendannounce.c
index 56cd497..73c875d 100644
--- a/source/nmbd/nmbd_sendannounce.c
+++ b/source/nmbd/nmbd_sendannounce.c
@@ -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();
@@ -474,7 +474,7 @@ void announce_remote(time_t t)
comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH);
for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
- /* The entries are of the form a.b.c.d/WORKGROUP with
+ /* The entries are of the form a.b.c.d/WORKGROUP with
WORKGROUP being optional */
const char *wgroup;
char *pwgroup;
@@ -489,7 +489,7 @@ void announce_remote(time_t t)
wgroup = pwgroup;
(void)interpret_addr2(&addr,s2);
-
+
/* Announce all our names including aliases */
/* Give the ip address as the address of our first
broadcast subnet. */
@@ -518,20 +518,20 @@ void announce_remote(time_t t)
**************************************************************************/
void browse_sync_remote(time_t t)
-{
+{
char *s;
const char *ptr;
- static time_t last_time = 0;
- pstring s2;
+ static time_t last_time = 0;
+ fstring s2;
struct in_addr addr;
struct work_record *work;
- pstring outbuf;
+ char outbuf[1024];
char *p;
unstring myname;
-
+
if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
return;
-
+
last_time = t;
s = lp_remote_browse_sync();
@@ -548,12 +548,12 @@ void browse_sync_remote(time_t t)
lp_workgroup(), FIRST_SUBNET->subnet_name ));
return;
}
-
+
if(!AM_LOCAL_MASTER_BROWSER(work)) {
DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \
for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name ));
return;
- }
+ }
memset(outbuf,'\0',sizeof(outbuf));
p = outbuf;
@@ -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);
diff --git a/source/nmbd/nmbd_serverlistdb.c b/source/nmbd/nmbd_serverlistdb.c
index 5ac4888..349c3f4 100644
--- a/source/nmbd/nmbd_serverlistdb.c
+++ b/source/nmbd/nmbd_serverlistdb.c
@@ -289,17 +289,19 @@ void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type,
}
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;
--
Samba Shared Repository
More information about the samba-cvs
mailing list