convert more code to use XFILE
authorAndrew Tridgell <tridge@samba.org>
Mon, 10 Sep 2001 13:09:54 +0000 (13:09 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 10 Sep 2001 13:09:54 +0000 (13:09 +0000)
source/nmbd/nmbd_namelistdb.c
source/nmbd/nmbd_serverlistdb.c
source/nmbd/nmbd_synclists.c
source/nmbd/nmbd_winsserver.c

index efac14c8c6aac9a2716dfce6baaabed4c352174c..281197df65bb58574b4d51d40fcfbfb19aae3ab0 100644 (file)
@@ -528,19 +528,19 @@ void add_samba_names_to_subnet( struct subnet_record *subrec )
  into a file. Initiated by SIGHUP - used to debug the state of the namelists.
 **************************************************************************/
 
-static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp)
+static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
 {
   struct name_record *namerec;
   char *src_type;
   struct tm *tm;
   int i;
 
-  fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
+  x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
   for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
        namerec;
        namerec = (struct name_record *)ubi_trNext( namerec ) )
   {
-    fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
+    x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
     switch(namerec->data.source)
     {
       case LMHOSTS_NAME:
@@ -568,29 +568,29 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp)
         src_type = "unknown!";
         break;
     }
-    fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
+    x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
 
     if(namerec->data.death_time != PERMANENT_TTL)
     {
       tm = LocalTime(&namerec->data.death_time);
-      fprintf(fp, "death_time = %s\t", asctime(tm));
+      x_fprintf(fp, "death_time = %s\t", asctime(tm));
     }
     else
-      fprintf(fp, "death_time = PERMANENT\t");
+      x_fprintf(fp, "death_time = PERMANENT\t");
 
     if(namerec->data.refresh_time != PERMANENT_TTL)
     {
       tm = LocalTime(&namerec->data.refresh_time);
-      fprintf(fp, "refresh_time = %s\n", asctime(tm));
+      x_fprintf(fp, "refresh_time = %s\n", asctime(tm));
     }
     else
-      fprintf(fp, "refresh_time = PERMANENT\n");
+      x_fprintf(fp, "refresh_time = PERMANENT\n");
 
-    fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
+    x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
     for(i = 0; i < namerec->data.num_ips; i++)
-      fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
+      x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
 
-    fprintf(fp, "\n\n");
+    x_fprintf(fp, "\n\n");
   }
 }
 
@@ -601,10 +601,10 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp)
 
 void dump_all_namelists(void)
 {
-  FILE *fp; 
+  XFILE *fp; 
   struct subnet_record *subrec;
 
-  fp = sys_fopen(lock_path("namelist.debug"),"w");
+  fp = x_fopen(lock_path("namelist.debug"),O_WRONLY|O_CREAT|O_TRUNC, 0644);
      
   if (!fp)
   { 
@@ -626,5 +626,5 @@ void dump_all_namelists(void)
 
   if( wins_server_subnet != NULL )
     dump_subnet_namelist( wins_server_subnet, fp );
-  fclose( fp );
+  x_fclose( fp );
 }
index 41009bc68f0016fbcf899a4ac5c49fb05138629b..711ddb2490a10627208c9d1a53fe2d02fd04286d 100644 (file)
@@ -307,7 +307,7 @@ void write_browse_list(time_t t, BOOL force_write)
   uint32 stype;
   fstring tmp;
   int i;
-  FILE *fp;
+  XFILE *fp;
   BOOL list_changed = force_write;
   static time_t lasttime = 0;
     
@@ -345,7 +345,7 @@ void write_browse_list(time_t t, BOOL force_write)
   pstrcpy(fnamenew,fname);
   pstrcat(fnamenew,".");
  
-  fp = sys_fopen(fnamenew,"w");
+  fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);
  
   if (!fp)
   {
@@ -363,16 +363,16 @@ void write_browse_list(time_t t, BOOL force_write)
   { 
     DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n",
              global_myworkgroup));
-    fclose(fp);
+    x_fclose(fp);
     return;
   }
 
   slprintf(tmp,sizeof(tmp)-1, "\"%s\"", work->work_group);
-  fprintf(fp, "%-25s ", tmp);
-  fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY);
+  x_fprintf(fp, "%-25s ", tmp);
+  x_fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY);
   slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name);
-  fprintf(fp, "%-30s", tmp);
-  fprintf(fp, "\"%s\"\n", work->work_group);
+  x_fprintf(fp, "%-30s", tmp);
+  x_fprintf(fp, "\"%s\"\n", work->work_group);
 
   /* 
    * We need to do something special for our own names.
@@ -397,12 +397,12 @@ void write_browse_list(time_t t, BOOL force_write)
 
     /* Output server details, plus what workgroup they're in. */
     slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]);
-    fprintf(fp, "%-25s ", tmp);
-    fprintf(fp, "%08x ", stype);
+    x_fprintf(fp, "%-25s ", tmp);
+    x_fprintf(fp, "%08x ", stype);
     slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", 
             string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
-    fprintf(fp, "%-30s", tmp);
-    fprintf(fp, "\"%s\"\n", global_myworkgroup);
+    x_fprintf(fp, "%-30s", tmp);
+    x_fprintf(fp, "\"%s\"\n", global_myworkgroup);
   }
       
   for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) 
@@ -417,12 +417,12 @@ void write_browse_list(time_t t, BOOL force_write)
       if(wg_type)
       {
         slprintf(tmp, sizeof(tmp)-1, "\"%s\"", work->work_group);
-        fprintf(fp, "%-25s ", tmp);
+        x_fprintf(fp, "%-25s ", tmp);
 
-        fprintf(fp, "%08x ", wg_type);
+        x_fprintf(fp, "%08x ", wg_type);
         slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name);
-        fprintf(fp, "%-30s", tmp);
-        fprintf(fp, "\"%s\"\n", work->work_group);
+        x_fprintf(fp, "%-30s", tmp);
+        x_fprintf(fp, "\"%s\"\n", work->work_group);
       }
 
       /* Now write out any server records a workgroup may have. */
@@ -441,17 +441,17 @@ void write_browse_list(time_t t, BOOL force_write)
         {
           /* Output server details, plus what workgroup they're in. */
           slprintf(tmp, sizeof(tmp)-1, "\"%s\"", servrec->serv.name);
-          fprintf(fp, "%-25s ", tmp);
-          fprintf(fp, "%08x ", serv_type);
+          x_fprintf(fp, "%-25s ", tmp);
+          x_fprintf(fp, "%08x ", serv_type);
           slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", servrec->serv.comment);
-          fprintf(fp, "%-30s", tmp);
-          fprintf(fp, "\"%s\"\n", work->work_group);
+          x_fprintf(fp, "%-30s", tmp);
+          x_fprintf(fp, "\"%s\"\n", work->work_group);
         }
       }
     }
   } 
   
-  fclose(fp);
+  x_fclose(fp);
   unlink(fname);
   chmod(fnamenew,0644);
   rename(fnamenew,fname);
index 51c9257f5a5640799974693dc548a30b8053c3a4..e3ea67f1351f586fbc7ab122fe84a668fd0dfd6d 100644 (file)
@@ -45,7 +45,7 @@ struct sync_record {
 /* a linked list of current sync connections */
 static struct sync_record *syncs;
 
-static FILE *fp;
+static XFILE *fp;
 
 /*******************************************************************
   This is the NetServerEnum callback.
@@ -54,7 +54,7 @@ static FILE *fp;
 static void callback(const char *sname, uint32 stype, 
                      const char *comment, void *state)
 {
-       fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment);
+       x_fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment);
 }
 
 /*******************************************************************
@@ -167,7 +167,7 @@ done:
        DEBUG(2,("Initiating browse sync for %s to %s(%s)\n",
                 work->work_group, name, inet_ntoa(ip)));
 
-       fp = sys_fopen(s->fname,"w");
+       fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
        if (!fp) {
                END_PROFILE(sync_browse_lists);
                _exit(1);       
@@ -176,7 +176,7 @@ done:
        sync_child(name, nm_type, work->work_group, ip, local, servers,
                   s->fname);
 
-       fclose(fp);
+       x_fclose(fp);
        END_PROFILE(sync_browse_lists);
        _exit(0);
 }
index 03d475133e1e0b79743b5a6c95ff416620564ee7..10eaf91e8aa5047f794d85394d5d83c028356a41 100644 (file)
@@ -1582,8 +1582,7 @@ void wins_write_database(BOOL background)
 {
   struct name_record *namerec;
   pstring fname, fnamenew;
-
-  FILE *fp;
+  XFILE *fp;
    
   if(!lp_we_are_a_wins_server())
     return;
@@ -1601,7 +1600,7 @@ void wins_write_database(BOOL background)
   all_string_sub(fname,"//", "/", 0);
   slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid());
 
-  if((fp = sys_fopen(fnamenew,"w")) == NULL)
+  if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644)) == NULL)
   {
     DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno)));
     if (background) {
@@ -1612,7 +1611,7 @@ void wins_write_database(BOOL background)
 
   DEBUG(4,("wins_write_database: Dump of WINS name list.\n"));
 
-  fprintf(fp,"VERSION %d %u\n", WINS_VERSION, wins_hash());
+  x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, wins_hash());
  
   for( namerec 
            = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist );
@@ -1644,17 +1643,17 @@ void wins_write_database(BOOL background)
 
     if( namerec->data.source == REGISTER_NAME )
     {
-      fprintf(fp, "\"%s#%02x\" %d ",
+      x_fprintf(fp, "\"%s#%02x\" %d ",
              namerec->name.name,namerec->name.name_type, /* Ignore scope. */
              (int)namerec->data.death_time);
 
       for (i = 0; i < namerec->data.num_ips; i++)
-        fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) );
-      fprintf( fp, "%2xR\n", namerec->data.nb_flags );
+        x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) );
+      x_fprintf( fp, "%2xR\n", namerec->data.nb_flags );
     }
   }
   
-  fclose(fp);
+  x_fclose(fp);
   chmod(fnamenew,0644);
   unlink(fname);
   rename(fnamenew,fname);