lib/interfaces.o lib/pidfile.o lib/replace.o \
lib/signal.o lib/system.o lib/time.o \
lib/ufc.o lib/genrand.o lib/username.o lib/access.o lib/smbrun.o \
- lib/bitmap.o lib/crc32.o lib/snprintf.o lib/dprintf.o lib/wins_srv.o \
+ lib/bitmap.o lib/crc32.o lib/snprintf.o lib/dprintf.o lib/xfile.o lib/wins_srv.o \
lib/util_array.o lib/util_str.o lib/util_sid.o \
lib/util_unistr.o lib/util_file.o lib/sysacls.o \
lib/util.o lib/util_sock.o lib/util_sec.o smbd/ssl.o \
#define True 1
/* zero a structure given a pointer to the structure */
-#define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
+#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
#define MAX_UNISTRLEN 256
#define MAX_STRINGLEN 256
read from a file with LF->CR/LF translation if appropriate. return the
number read. read approx n bytes.
****************************************************************************/
-static int readfile(char *b, int n, FILE *f)
+static int readfile(char *b, int n, XFILE *f)
{
int i;
int c;
if (!translation)
- return fread(b,1,n,f);
+ return x_fread(b,1,n,f);
i = 0;
while (i < (n - 1) && (i < BUFFER_SIZE)) {
- if ((c = getc(f)) == EOF) {
+ if ((c = x_getc(f)) == EOF) {
break;
}
static void do_put(char *rname,char *lname)
{
int fnum;
- FILE *f;
+ XFILE *f;
int nread=0;
char *buf=NULL;
int maxwrite=io_bufsize;
/* allow files to be piped into smbclient
jdblair 24.jun.98 */
if (!strcmp(lname, "-")) {
- f = stdin;
+ f = x_stdin;
/* size of file is not known */
} else {
- f = sys_fopen(lname,"r");
+ f = x_fopen(lname,O_RDONLY, 0);
}
if (!f) {
d_printf("ERROR: Not enough memory!\n");
return;
}
- while (!feof(f)) {
+ while (!x_feof(f)) {
int n = maxwrite;
int ret;
if ((n = readfile(buf,n,f)) < 1) {
- if((n == 0) && feof(f))
+ if((n == 0) && x_feof(f))
break; /* Empty local file. */
d_printf("Error reading local file: %s\n", strerror(errno));
if (!cli_close(cli, fnum)) {
d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
- fclose(f);
+ x_fclose(f);
if (buf) free(buf);
return;
}
- fclose(f);
+ x_fclose(f);
if (buf) free(buf);
{
put_total_size / (1.024*put_total_time_ms)));
}
- if (f == stdin) {
+ if (f == x_stdin) {
cli_shutdown(cli);
exit(0);
}
fstring base_directory;
char *pname = argv[0];
int opt;
- extern FILE *dbf;
+ extern XFILE *dbf;
extern char *optarg;
extern int optind;
int old_debug;
for (opt = 1; opt < argc; opt++) {
if (strcmp(argv[opt], "-E") == 0)
- dbf = stderr;
+ dbf = x_stderr;
else if(strncmp(argv[opt], "-s", 2) == 0) {
if(argv[opt][2] != '\0')
pstrcpy(servicesf, &argv[opt][2]);
break;
case 'E':
display_set_stderr();
- dbf = stderr;
+ dbf = x_stderr;
break;
case 'U':
{
case 'A':
{
- FILE *auth;
+ XFILE *auth;
fstring buf;
uint16 len = 0;
char *ptr, *val, *param;
- if ((auth=sys_fopen(optarg, "r")) == NULL)
+ if ((auth=x_fopen(optarg, O_RDONLY, 0)) == NULL)
{
/* fail if we can't open the credentials file */
d_printf("ERROR: Unable to open credentials file!\n");
exit (-1);
}
- while (!feof(auth))
+ while (!x_feof(auth))
{
/* get a line from the file */
- if (!fgets (buf, sizeof(buf), auth))
+ if (!x_fgets(buf, sizeof(buf), auth))
continue;
len = strlen(buf);
memset(buf, 0, sizeof(buf));
}
- fclose(auth);
+ x_fclose(auth);
}
break;
#define SEPARATORS " \t\n\r"
extern int DEBUGLEVEL;
extern struct cli_state *cli;
-extern FILE *dbf;
+extern XFILE *dbf;
/* These defines are for the do_setrattr routine, to indicate
* setting and reseting of file attributes in the function call */
***************************************************************************/
static int read_inclusion_file(char *filename)
{
- FILE *inclusion = NULL;
+ XFILE *inclusion = NULL;
char buf[MAXPATHLEN + 1];
char *inclusion_buffer = NULL;
int inclusion_buffer_size = 0;
clipn = 0;
buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */
- if ((inclusion = sys_fopen(filename, "r")) == NULL) {
+ if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) {
/* XXX It would be better to include a reason for failure, but without
* autoconf, it's hard to use strerror, sys_errlist, etc.
*/
return 0;
}
- while ((! error) && (fgets(buf, sizeof(buf)-1, inclusion))) {
+ while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) {
if (inclusion_buffer == NULL) {
inclusion_buffer_size = 1024;
if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) {
inclusion_buffer_sofar += strlen(buf) + 1;
clipn++;
}
- fclose(inclusion);
+ x_fclose(inclusion);
if (! error) {
/* Allocate an array of clipn + 1 char*'s for cliplist */
* tar output
*/
if (tarhandle == 1)
- dbf = stderr;
+ dbf = x_stderr;
} else {
if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0))
{
if (have_ip) ip = dest_ip;
/* have to open a new connection */
- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) != port) ||
+ if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) != smb_port) ||
!cli_connect(c, server_n, &ip)) {
DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n));
if (c) {
#include "messages.h"
#include "util_list.h"
#include "charset.h"
+#include "xfile.h"
#include "util_getent.h"
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
/* zero a structure given a pointer to the structure */
-#define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
+#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
/* zero a structure given a pointer to the structure - no zero check */
#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
****************************************************************************/
static uint32 cmd_quit(struct client_info *info, int argc, char *argv[])
{
-#ifdef MEM_MAN
- {
- extern FILE *dbf;
- smb_mem_write_status(dbf);
- smb_mem_write_errors(dbf);
- smb_mem_write_verbose(dbf);
- dbgflush();
- }
-#endif
-
free_connections();
exit(0);
BOOL interactive = True;
char *cmd_str = NULL;
int opt;
- extern FILE *dbf;
+ extern XFILE *dbf;
extern char *optarg;
static pstring servicesf = CONFIGFILE;
pstring term_code;
case 'E':
{
cmd_set_options |= CMD_DBG;
- dbf = stderr;
+ dbf = x_stderr;
break;
}
* levels higher than DEBUGLEVEL will not be processed.
*/
-FILE *dbf = NULL;
+XFILE *dbf = NULL;
pstring debugf = "";
BOOL append_log = False;
if (interactive) {
stdout_logging = True;
- dbf = stdout;
+ dbf = x_stdout;
}
#ifdef WITH_SYSLOG
else {
{
pstring fname;
mode_t oldumask;
- FILE *new_dbf = NULL;
+ XFILE *new_dbf = NULL;
BOOL ret = True;
if (stdout_logging)
pstrcpy( debugf, fname );
if (append_log)
- new_dbf = sys_fopen( debugf, "a" );
+ new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644);
else
- new_dbf = sys_fopen( debugf, "w" );
+ new_dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 );
if (!new_dbf) {
log_overflow = True;
DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno)));
log_overflow = False;
- fflush(dbf);
+ x_fflush(dbf);
ret = False;
} else {
- setbuf(new_dbf, NULL);
+ x_setbuf(new_dbf, NULL);
if (dbf)
- (void) fclose(dbf);
+ (void) x_fclose(dbf);
dbf = new_dbf;
}
maxlog = lp_max_log_size() * 1024;
- if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) {
+ if( sys_fstat( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) {
(void)reopen_logs();
if( dbf && get_file_size( debugf ) > maxlog ) {
pstring name;
startup or when the log level is increased from zero.
-dwg 6 June 2000
*/
- dbf = sys_fopen( "/dev/console", "w" );
+ dbf = x_fopen( "/dev/console", O_WRONLY, 0);
if(dbf) {
DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n",
debugf ));
{
va_start( ap, format_str );
if(dbf)
- (void)vfprintf( dbf, format_str, ap );
+ (void)x_vfprintf( dbf, format_str, ap );
va_end( ap );
errno = old_errno;
return( 0 );
mode_t oldumask = umask( 022 );
if( append_log )
- dbf = sys_fopen( debugf, "a" );
+ dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 );
else
- dbf = sys_fopen( debugf, "w" );
+ dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 );
(void)umask( oldumask );
if( dbf )
{
- setbuf( dbf, NULL );
+ x_setbuf( dbf, NULL );
}
else
{
{
va_start( ap, format_str );
if(dbf)
- (void)vfprintf( dbf, format_str, ap );
+ (void)x_vfprintf( dbf, format_str, ap );
va_end( ap );
if(dbf)
- (void)fflush( dbf );
+ (void)x_fflush( dbf );
}
errno = old_errno;
{
bufr_print();
if(dbf)
- (void)fflush( dbf );
+ (void)x_fflush( dbf );
} /* dbgflush */
/* ************************************************************************** **
int end))
{
fd_set fds;
- extern FILE *dbf;
+ extern XFILE *dbf;
static pstring line;
struct timeval timeout;
int fd = fileno(stdin);
char *ret;
- fprintf(dbf, "%s", prompt);
- fflush(dbf);
+ x_fprintf(dbf, "%s", prompt);
+ x_fflush(dbf);
while (1) {
timeout.tv_sec = 5;
return(False);
}
-#ifdef HPUX
-/****************************************************************************
-this is a version of setbuffer() for those machines that only have setvbuf
-****************************************************************************/
- void setbuffer(FILE *f,char *buf,int bufsize)
-{
- setvbuf(f,buf,_IOFBF,bufsize);
-}
-#endif
-
/****************************************************************************
expand a pointer to be a particular size
****************************************************************************/
int main(int argc,char *argv[])
{
int opt;
- extern FILE *dbf;
+ extern XFILE *dbf;
extern char *optarg;
extern BOOL append_log;
process();
if (dbf)
- fclose(dbf);
+ x_fclose(dbf);
return(0);
} /* main */
gotstart = 1;
}
- if( $0 ~ /^smb_iconv_t|^long|^char|^uint|^NTSTATUS|^WERROR|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^FILE|^SMB_OFF_T|^size_t|^ssize_t|^SMB_BIG_UINT/ ) {
+ if( $0 ~ /^smb_iconv_t|^long|^char|^uint|^NTSTATUS|^WERROR|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^FILE|^XFILE|^SMB_OFF_T|^size_t|^ssize_t|^SMB_BIG_UINT/ ) {
gotstart = 1;
}
/* Setup the main smbd so that we can get messages. */
claim_connection(NULL,"",MAXSTATUS,True);
- /* Attempt to migrate from an old 2.0.x machine account file. */
- if (!migrate_from_old_password_file(global_myworkgroup)) {
- DEBUG(0,("Failed to migrate from old MAC file.\n"));
- }
-
if (!open_sockets(is_daemon,port))
exit(1);
int opt;
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
- dbf = stdout;
+ dbf = x_stdout;
smbw_setup_shared();
while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) {
extern BOOL in_client;
static int initialised;
static pstring servicesf = CONFIGFILE;
- extern FILE *dbf;
+ extern XFILE *dbf;
char *p;
int eno;
pstring line;
DEBUGLEVEL = 0;
setup_logging("smbsh",True);
- dbf = stderr;
+ dbf = x_stderr;
if ((p=smbw_getshared("LOGFILE"))) {
dbf = sys_fopen(p, "a");
char *share[NSERVERS];
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
int opt;
char *p;
int seed, server;
setlinebuf(stdout);
- dbf = stderr;
+ dbf = x_stderr;
if (argc < 3 || argv[1][0] == '-') {
usage();
char *share1, *share2, *nfspath1, *nfspath2;
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
int opt;
char *p;
int seed;
setlinebuf(stdout);
- dbf = stderr;
+ dbf = x_stderr;
if (argc < 5 || argv[1][0] == '-') {
usage();
struct cli_state *cli;
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
int opt;
char *p;
int seed;
setlinebuf(stdout);
- dbf = stderr;
+ dbf = x_stderr;
if (argv[1][0] == '-' || argc < 2) {
usage();
{
char *pname = argv[0];
int opt;
- extern FILE *dbf;
+ extern XFILE *dbf;
extern char *optarg;
extern int optind;
static pstring servicesf = CONFIGFILE;
case 'E':
{
- dbf = stderr;
+ dbf = x_stderr;
break;
}
int gotpass = 0;
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
static pstring servicesf = CONFIGFILE;
BOOL correct = True;
- dbf = stdout;
+ dbf = x_stdout;
#ifdef HAVE_SETBUFFER
setbuffer(stdout, NULL, 0);
pstring filename;
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
int opt;
char *p;
static pstring servicesf = CONFIGFILE;
setlinebuf(stdout);
- dbf = stderr;
+ dbf = x_stderr;
if (argc < 3 || argv[1][0] == '-') {
usage();
{
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
int opt;
char *p;
pstring servicesf = CONFIGFILE;
setlinebuf(stdout);
- dbf = stderr;
+ dbf = x_stderr;
setup_logging(argv[0],True);
} *srecs;
extern int DEBUGLEVEL;
-extern FILE *dbf;
+extern XFILE *dbf;
static pstring Ucrit_username = ""; /* added by OH */
static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */
setup_logging(argv[0],True);
DEBUGLEVEL = 0;
- dbf = stderr;
+ dbf = x_stderr;
if (getuid() != geteuid()) {
d_printf("smbstatus should not be run setuid\n");
#include "smb.h"
/* these live in util.c */
-extern FILE *dbf;
+extern XFILE *dbf;
extern int DEBUGLEVEL;
/***********************************************
else if ((argc == 2) || (argc == 4))
pstrcpy(configfile,argv[optind]);
- dbf = stdout;
+ dbf = x_stdout;
DEBUGLEVEL = 2;
printf("Load smb config files from %s\n",configfile);
#include "smb.h"
/* these live in util.c */
-extern FILE *dbf;
+extern XFILE *dbf;
extern int DEBUGLEVEL;
int main(int argc, char *argv[])
printf("Usage: testprns printername [printcapfile]\n");
else
{
- dbf = sys_fopen("test.log", "w");
+ dbf = x_fopen("test.log", O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (dbf == NULL) {
printf("Unable to open logfile.\n");
} else {
printf("Printer name %s is not valid.\n", argv[1]);
else
printf("Printer name %s is valid.\n", argv[1]);
- fclose(dbf);
+ x_fclose(dbf);
}
}
return (0);
len = content_length;
}
} else {
- fseek(f, 0, SEEK_END);
- len = ftell(f);
- fseek(f, 0, SEEK_SET);
+ struct stat st;
+ fstat(fileno(f), &st);
+ len = st.st_size;
}
{
extern char *optarg;
extern int optind;
- extern FILE *dbf;
+ extern XFILE *dbf;
int opt;
char *page;
/* we don't want any SIGPIPE messages */
BlockSignals(True,SIGPIPE);
- dbf = sys_fopen("/dev/null", "w");
- if (!dbf) dbf = stderr;
+ dbf = x_fopen("/dev/null", O_WRONLY, 0);
+ if (!dbf) dbf = x_stderr;
/* we don't want stderr screwing us up */
close(2);