summaryrefslogtreecommitdiff
path: root/source3/nmbd/nmbd_winsserver.c
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/nmbd_winsserver.c
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/nmbd_winsserver.c')
-rw-r--r--source3/nmbd/nmbd_winsserver.c49
1 files changed, 30 insertions, 19 deletions
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);