summaryrefslogtreecommitdiff
path: root/source3/nmbd
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2016-11-26 09:50:33 +0100
committerVolker Lendecke <vl@samba.org>2016-12-11 11:17:24 +0100
commit8a0174dca503a6c290c7d565a6bf2c10363964a4 (patch)
treeb41c8e374f173216c027da219102abe6ec25e1c8 /source3/nmbd
parent899b0883c8d500545133b0bf85743525fb1452bf (diff)
downloadsamba-8a0174dca503a6c290c7d565a6bf2c10363964a4.tar.gz
nmbd: xfile->stdio
Unfortunately this is a larger patch. Doing it in small pieces would have been pretty difficult, as everybody calls everybody else. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/nmbd')
-rw-r--r--source3/nmbd/nmbd.h1
-rw-r--r--source3/nmbd/nmbd_namelistdb.c45
-rw-r--r--source3/nmbd/nmbd_proto.h8
-rw-r--r--source3/nmbd/nmbd_serverlistdb.c32
-rw-r--r--source3/nmbd/nmbd_synclists.c25
-rw-r--r--source3/nmbd/nmbd_winsserver.c49
6 files changed, 98 insertions, 62 deletions
diff --git a/source3/nmbd/nmbd.h b/source3/nmbd/nmbd.h
index f2086a51639..47940e19401 100644
--- a/source3/nmbd/nmbd.h
+++ b/source3/nmbd/nmbd.h
@@ -25,7 +25,6 @@
#define SYNC_DNS 1
#endif
-#include "lib/util/xfile.h"
#include "libsmb/nmblib.h"
#include "nmbd/nmbd_proto.h"
diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c
index c7bcb6a90f1..af1f9b743ba 100644
--- a/source3/nmbd/nmbd_namelistdb.c
+++ b/source3/nmbd/nmbd_namelistdb.c
@@ -546,13 +546,13 @@ void add_samba_names_to_subnet( struct subnet_record *subrec )
Dump a name_record struct.
**************************************************************************/
-void dump_name_record( struct name_record *namerec, XFILE *fp)
+void dump_name_record( struct name_record *namerec, FILE *fp)
{
const char *src_type;
struct tm *tm;
int i;
- x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
+ fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
switch(namerec->data.source) {
case LMHOSTS_NAME:
src_type = "LMHOSTS_NAME";
@@ -580,7 +580,8 @@ void dump_name_record( struct name_record *namerec, XFILE *fp)
break;
}
- x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
+ fprintf(fp, "Source = %s\nb_flags = %x\t", src_type,
+ namerec->data.nb_flags);
if(namerec->data.death_time != PERMANENT_TTL) {
const char *asct;
@@ -592,9 +593,9 @@ void dump_name_record( struct name_record *namerec, XFILE *fp)
if (!asct) {
return;
}
- x_fprintf(fp, "death_time = %s\t", asct);
+ fprintf(fp, "death_time = %s\t", asct);
} else {
- x_fprintf(fp, "death_time = PERMANENT\t");
+ fprintf(fp, "death_time = PERMANENT\t");
}
if(namerec->data.refresh_time != PERMANENT_TTL) {
@@ -607,18 +608,17 @@ void dump_name_record( struct name_record *namerec, XFILE *fp)
if (!asct) {
return;
}
- x_fprintf(fp, "refresh_time = %s\n", asct);
+ fprintf(fp, "refresh_time = %s\n", asct);
} else {
- x_fprintf(fp, "refresh_time = PERMANENT\n");
+ fprintf(fp, "refresh_time = PERMANENT\n");
}
- x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
+ fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
for(i = 0; i < namerec->data.num_ips; i++) {
- x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
+ fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
}
- x_fprintf(fp, "\n\n");
-
+ fprintf(fp, "\n\n");
}
/****************************************************************************
@@ -626,10 +626,10 @@ void dump_name_record( struct name_record *namerec, XFILE *fp)
into a file. Initiated by SIGHUP - used to debug the state of the namelists.
**************************************************************************/
-static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
+static void dump_subnet_namelist(struct subnet_record *subrec, FILE *fp)
{
struct name_record *namerec;
- x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
+ fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
for( namerec = subrec->namelist; namerec; namerec = namerec->next) {
dump_name_record(namerec, fp);
}
@@ -642,7 +642,8 @@ static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
void dump_all_namelists(void)
{
- XFILE *fp;
+ int fd;
+ FILE *fp;
struct subnet_record *subrec;
char *dump_path;
@@ -652,13 +653,21 @@ void dump_all_namelists(void)
return;
}
- fp = x_fopen(dump_path, (O_WRONLY | O_CREAT | O_TRUNC), 0644);
+ fd = open(dump_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd == -1) {
+ DBG_ERR("Can't open file %s: %s\n", dump_path,
+ strerror(errno));
+ return;
+ }
TALLOC_FREE(dump_path);
+
+ fp = fdopen(fd, "w");
if (!fp) {
- DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n",
- "namelist.debug",strerror(errno)));
+ DBG_ERR("fdopen failed: %s\n", strerror(errno));
+ close(fd);
return;
}
+ fd = -1;
for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
dump_subnet_namelist( subrec, fp );
@@ -676,5 +685,5 @@ void dump_all_namelists(void)
dump_wins_subnet_namelist(fp );
}
- x_fclose( fp );
+ fclose( fp );
}
diff --git a/source3/nmbd/nmbd_proto.h b/source3/nmbd/nmbd_proto.h
index 812234d4e1d..4ff5de0fbb3 100644
--- a/source3/nmbd/nmbd_proto.h
+++ b/source3/nmbd/nmbd_proto.h
@@ -158,7 +158,7 @@ void standard_success_release( struct subnet_record *subrec,
struct in_addr released_ip );
void expire_names(time_t t);
void add_samba_names_to_subnet( struct subnet_record *subrec );
-void dump_name_record( struct name_record *namerec, XFILE *fp);
+void dump_name_record(struct name_record *namerec, FILE *fp);
void dump_all_namelists(void);
/* The following definitions come from nmbd/nmbd_namequery.c */
@@ -314,7 +314,7 @@ struct server_record *create_server_on_workgroup(struct work_record *work,
int ttl, const char *comment);
void update_server_ttl(struct server_record *servrec, int ttl);
void expire_servers(struct work_record *work, time_t t);
-void write_browse_list_entry(XFILE *fp, const char *name, uint32_t rec_type,
+void write_browse_list_entry(FILE *fp, const char *name, uint32_t rec_type,
const char *local_master_browser_name, const char *description);
void write_browse_list(time_t t, bool force_write);
@@ -346,7 +346,7 @@ struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, boo
bool wins_store_changed_namerec(const struct name_record *namerec);
bool add_name_to_wins_subnet(const struct name_record *namerec);
bool remove_name_from_wins_namelist(struct name_record *namerec);
-void dump_wins_subnet_namelist(XFILE *fp);
+void dump_wins_subnet_namelist(FILE *fp);
bool packet_is_for_wins_server(struct packet_struct *packet);
bool initialise_wins(void);
void wins_process_name_refresh_request( struct subnet_record *subrec,
@@ -363,7 +363,7 @@ void wins_process_name_query_request(struct subnet_record *subrec,
void wins_process_name_release_request(struct subnet_record *subrec,
struct packet_struct *p);
void initiate_wins_processing(time_t t);
-void wins_write_name_record(struct name_record *namerec, XFILE *fp);
+void wins_write_name_record(struct name_record *namerec, FILE *fp);
void wins_write_database(time_t t, bool background);
void nmbd_wins_new_entry(struct messaging_context *msg,
void *private_data,
diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c
index 43471d69e45..05dcb6c7482 100644
--- a/source3/nmbd/nmbd_serverlistdb.c
+++ b/source3/nmbd/nmbd_serverlistdb.c
@@ -248,17 +248,17 @@ static uint32_t write_this_workgroup_name( struct subnet_record *subrec,
Write out the browse.dat file.
******************************************************************/
-void write_browse_list_entry(XFILE *fp, const char *name, uint32_t rec_type,
+void write_browse_list_entry(FILE *fp, const char *name, uint32_t rec_type,
const char *local_master_browser_name, const char *description)
{
fstring tmp;
slprintf(tmp,sizeof(tmp)-1, "\"%s\"", name);
- x_fprintf(fp, "%-25s ", tmp);
- x_fprintf(fp, "%08x ", rec_type);
+ fprintf(fp, "%-25s ", tmp);
+ fprintf(fp, "%08x ", rec_type);
slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", local_master_browser_name);
- x_fprintf(fp, "%-30s", tmp);
- x_fprintf(fp, "\"%s\"\n", description);
+ fprintf(fp, "%-30s", tmp);
+ fprintf(fp, "\"%s\"\n", description);
}
void write_browse_list(time_t t, bool force_write)
@@ -270,7 +270,8 @@ void write_browse_list(time_t t, bool force_write)
char *fnamenew;
uint32_t stype;
int i;
- XFILE *fp;
+ int fd;
+ FILE *fp;
bool list_changed = force_write;
static time_t lasttime = 0;
TALLOC_CTX *ctx = talloc_tos();
@@ -310,15 +311,24 @@ void write_browse_list(time_t t, bool force_write)
return;
}
- fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ fd = open(fnamenew, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ if (fd == -1) {
+ DBG_ERR("Can't open file %s: %s\n", fnamenew,
+ strerror(errno));
+ talloc_free(fnamenew);
+ talloc_free(fname);
+ return;
+ }
+ fp = fdopen(fd, "w");
if (!fp) {
- DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n",
- fnamenew,strerror(errno)));
+ DBG_ERR("fdopen failed: %s\n", strerror(errno));
+ close(fd);
talloc_free(fnamenew);
talloc_free(fname);
return;
}
+ fd = -1;
/*
* Write out a record for our workgroup. Use the record from the first
@@ -328,7 +338,7 @@ void write_browse_list(time_t t, bool force_write)
if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) {
DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n",
lp_workgroup()));
- x_fclose(fp);
+ fclose(fp);
talloc_free(fnamenew);
talloc_free(fname);
return;
@@ -394,7 +404,7 @@ void write_browse_list(time_t t, bool force_write)
}
}
- x_fclose(fp);
+ fclose(fp);
unlink(fname);
chmod(fnamenew,0644);
rename(fnamenew,fname);
diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c
index d69d6f9d104..53b4f129038 100644
--- a/source3/nmbd/nmbd_synclists.c
+++ b/source3/nmbd/nmbd_synclists.c
@@ -45,7 +45,7 @@ struct sync_record {
/* a linked list of current sync connections */
static struct sync_record *syncs;
-static XFILE *fp;
+static FILE *fp;
/*******************************************************************
This is the NetServerEnum callback.
@@ -55,7 +55,7 @@ static XFILE *fp;
static void callback(const char *sname, uint32_t stype,
const char *comment, void *state)
{
- x_fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment);
+ fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment);
}
/*******************************************************************
@@ -137,6 +137,7 @@ void sync_browse_lists(struct work_record *work,
{
struct sync_record *s;
static int counter;
+ int fd;
/* Check we're not trying to sync with ourselves. This can
happen if we are a domain *and* a local master browser. */
@@ -173,15 +174,21 @@ done:
DEBUG(2,("Initiating browse sync for %s to %s(%s)\n",
work->work_group, name, inet_ntoa(ip)));
- fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ fd = open(s->fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ if (fd == -1) {
+ _exit(1);
+ }
+
+ fp = fdopen(fd, "w");
if (!fp) {
_exit(1);
}
+ fd = -1;
sync_child(name, nm_type, work->work_group, ip, local, servers,
s->fname);
- x_fclose(fp);
+ fclose(fp);
_exit(0);
}
@@ -245,7 +252,7 @@ static void complete_one(struct sync_record *s,
static void complete_sync(struct sync_record *s)
{
- XFILE *f;
+ FILE *f;
char *server;
char *type_str;
unsigned type;
@@ -254,15 +261,15 @@ static void complete_sync(struct sync_record *s)
const char *ptr;
int count=0;
- f = x_fopen(s->fname,O_RDONLY, 0);
+ f = fopen(s->fname, "r");
if (!f)
return;
- while (!x_feof(f)) {
+ while (!feof(f)) {
TALLOC_CTX *frame = NULL;
- if (!x_fgets_slash(line,sizeof(line),f))
+ if (!fgets_slash(NULL, line, sizeof(line), f))
continue;
ptr = line;
@@ -282,7 +289,7 @@ static void complete_sync(struct sync_record *s)
count++;
TALLOC_FREE(frame);
}
- x_fclose(f);
+ fclose(f);
unlink(s->fname);
diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c
index cd4ff421860..7723b743c30 100644
--- a/source3/nmbd/nmbd_winsserver.c
+++ b/source3/nmbd/nmbd_winsserver.c
@@ -350,7 +350,7 @@ bool remove_name_from_wins_namelist(struct name_record *namerec)
static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
struct name_record *namerec = NULL;
- XFILE *fp = (XFILE *)state;
+ FILE *fp = (FILE *)state;
if (kbuf.dsize != sizeof(unstring) + 1) {
return 0;
@@ -368,7 +368,7 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *sta
return 0;
}
-void dump_wins_subnet_namelist(XFILE *fp)
+void dump_wins_subnet_namelist(FILE *fp)
{
tdb_traverse(wins_tdb, traverse_fn, (void *)fp);
}
@@ -592,7 +592,7 @@ Load or create the WINS database.
bool initialise_wins(void)
{
time_t time_now = time(NULL);
- XFILE *fp;
+ FILE *fp;
char line[1024];
char *db_path;
char *list_path;
@@ -626,7 +626,7 @@ bool initialise_wins(void)
return false;
}
- fp = x_fopen(list_path, O_RDONLY, 0);
+ fp = fopen(list_path, "r");
TALLOC_FREE(list_path);
if (fp == NULL) {
DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
@@ -634,7 +634,7 @@ bool initialise_wins(void)
return True;
}
- while (!x_feof(fp)) {
+ while (!feof(fp)) {
char *name_str = NULL;
char *ip_str = NULL;
char *ttl_str = NULL, *nb_flags_str = NULL;
@@ -655,7 +655,7 @@ bool initialise_wins(void)
/* Read a line from the wins.dat file. Strips whitespace
from the beginning and end of the line. */
- if (!x_fgets_slash(line,sizeof(line),fp)) {
+ if (!fgets_slash(NULL, line, sizeof(line), fp)) {
continue;
}
@@ -667,7 +667,7 @@ bool initialise_wins(void)
if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 ||
version != WINS_VERSION) {
DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line));
- x_fclose(fp);
+ fclose(fp);
return True;
}
continue;
@@ -724,7 +724,7 @@ bool initialise_wins(void)
/* Allocate the space for the ip_list. */
if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) {
DEBUG(0,("initialise_wins: Malloc fail !\n"));
- x_fclose(fp);
+ fclose(fp);
TALLOC_FREE(frame);
return False;
}
@@ -788,7 +788,7 @@ bool initialise_wins(void)
SAFE_FREE(ip_list);
}
- x_fclose(fp);
+ fclose(fp);
return True;
}
@@ -2385,7 +2385,7 @@ void initiate_wins_processing(time_t t)
Write out one record.
******************************************************************/
-void wins_write_name_record(struct name_record *namerec, XFILE *fp)
+void wins_write_name_record(struct name_record *namerec, FILE *fp)
{
int i;
struct tm *tm;
@@ -2420,12 +2420,13 @@ void wins_write_name_record(struct name_record *namerec, XFILE *fp)
if( namerec->data.source == REGISTER_NAME ) {
unstring name;
pull_ascii_nstring(name, sizeof(name), namerec->name.name);
- x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */
+ fprintf(fp, "\"%s#%02x\" %d ", name,
+ namerec->name.name_type, /* Ignore scope. */
(int)namerec->data.death_time);
for (i = 0; i < namerec->data.num_ips; i++)
- x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) );
- x_fprintf( fp, "%2xR\n", namerec->data.nb_flags );
+ fprintf(fp, "%s ", inet_ntoa(namerec->data.ip[i]));
+ fprintf(fp, "%2xR\n", namerec->data.nb_flags);
}
}
@@ -2436,7 +2437,7 @@ void wins_write_name_record(struct name_record *namerec, XFILE *fp)
static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
struct name_record *namerec = NULL;
- XFILE *fp = (XFILE *)state;
+ FILE *fp = (FILE *)state;
if (kbuf.dsize != sizeof(unstring) + 1) {
return 0;
@@ -2461,7 +2462,8 @@ void wins_write_database(time_t t, bool background)
char *fname = NULL;
char *fnamenew = NULL;
- XFILE *fp;
+ int fd;
+ FILE *fp;
if (background) {
if (!last_write_time) {
@@ -2501,18 +2503,27 @@ void wins_write_database(time_t t, bool background)
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)));
+ fd = open(fnamenew, O_WRONLY|O_CREAT, 0644);
+ if (fd == -1) {
+ DBG_ERR("Can't open %s: %s\n", fnamenew, strerror(errno));
goto err_exit;
}
+ fp = fdopen(fd, "w");
+ if (fp == NULL) {
+ DBG_ERR("fdopen failed: %s\n", strerror(errno));
+ close(fd);
+ goto err_exit;
+ }
+ fd = -1;
+
DEBUG(4,("wins_write_database: Dump of WINS name list.\n"));
- x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0);
+ fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0);
tdb_traverse(wins_tdb, wins_writedb_traverse_fn, fp);
- x_fclose(fp);
+ fclose(fp);
chmod(fnamenew,0644);
unlink(fname);
rename(fnamenew,fname);