[PATCH] remove xfile.[ch]
Volker Lendecke
vl at samba.org
Fri Dec 9 13:27:01 UTC 2016
Hi!
The attached patchset removes our stdio replacement xfile.[ch]. I
haven't been able to test everything, for example I don't have AIX
available, but the small unit tests I've done looked promising.
Review appreciated!
Thanks, Volker
-------------- next part --------------
>From e981898f2e640e3c1393095d937cf43e0b0984b7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 23 Nov 2016 10:11:13 +0100
Subject: [PATCH 01/16] smbclient4: xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/client/client.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/source4/client/client.c b/source4/client/client.c
index cfc85cde2aa..9866444b006 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -139,18 +139,18 @@ static int writefile(int f, const void *_b, int n, bool translation)
read from a file with LF->CR/LF translation if appropriate. return the
number read. read approx n bytes.
****************************************************************************/
-static int readfile(void *_b, int n, XFILE *f, bool translation)
+static int readfile(void *_b, int n, FILE *f, bool translation)
{
uint8_t *b = (uint8_t *)_b;
int i;
int c;
if (!translation)
- return x_fread(b,1,n,f);
+ return fread(b,1,n,f);
i = 0;
while (i < (n - 1)) {
- if ((c = x_getc(f)) == EOF) {
+ if ((c = getc(f)) == EOF) {
break;
}
@@ -1117,7 +1117,7 @@ static int cmd_altname(struct smbclient_context *ctx, const char **args)
static int do_put(struct smbclient_context *ctx, char *rname, char *lname, bool reput)
{
int fnum;
- XFILE *f;
+ FILE *f;
size_t start = 0;
off_t nread = 0;
uint8_t *buf = NULL;
@@ -1152,14 +1152,14 @@ static int do_put(struct smbclient_context *ctx, char *rname, char *lname, bool
Note that in this case this function will exit(0) rather
than returning. */
if (!strcmp(lname, "-")) {
- f = x_stdin;
+ f = stdin;
/* size of file is not known */
} else {
- f = x_fopen(lname,O_RDONLY, 0);
+ f = fopen(lname, "r");
if (f && reput) {
- if (x_tseek(f, start, SEEK_SET) == -1) {
+ if (fseek(f, start, SEEK_SET) == -1) {
d_printf("Error seeking local file\n");
- x_fclose(f);
+ fclose(f);
return 1;
}
}
@@ -1177,15 +1177,15 @@ static int do_put(struct smbclient_context *ctx, char *rname, char *lname, bool
buf = (uint8_t *)malloc(maxwrite);
if (!buf) {
d_printf("ERROR: Not enough memory!\n");
- x_fclose(f);
+ fclose(f);
return 1;
}
- while (!x_feof(f)) {
+ while (!feof(f)) {
int n = maxwrite;
int ret;
if ((n = readfile(buf,n,f,ctx->translation)) < 1) {
- if((n == 0) && x_feof(f))
+ if((n == 0) && feof(f))
break; /* Empty local file. */
d_printf("Error reading local file: %s\n", strerror(errno));
@@ -1206,14 +1206,14 @@ static int do_put(struct smbclient_context *ctx, char *rname, char *lname, bool
if (NT_STATUS_IS_ERR(smbcli_close(ctx->cli->tree, fnum))) {
d_printf("%s closing remote file %s\n",smbcli_errstr(ctx->cli->tree),rname);
- x_fclose(f);
+ fclose(f);
SAFE_FREE(buf);
return 1;
}
- if (f != x_stdin) {
- x_fclose(f);
+ if (f != stdin) {
+ fclose(f);
}
SAFE_FREE(buf);
@@ -1234,7 +1234,7 @@ static int do_put(struct smbclient_context *ctx, char *rname, char *lname, bool
put_total_size / (1.024*put_total_time_ms)));
}
- if (f == x_stdin) {
+ if (f == stdin) {
talloc_free(ctx);
exit(0);
}
--
2.11.0
>From 77096279a429815e35a63b28a72601eb5581aeef Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Nov 2016 01:59:22 +0100
Subject: [PATCH 02/16] smbclient: xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/client/client.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/source3/client/client.c b/source3/client/client.c
index 65696f9704a..0df935376a0 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -39,7 +39,6 @@
#include "libsmb/nmblib.h"
#include "include/ntioctl.h"
#include "../libcli/smb/smbXcli_base.h"
-#include "lib/util/xfile.h"
#ifndef REGISTER
#define REGISTER 0
@@ -218,17 +217,17 @@ static int writefile(int f, char *b, int n)
number read. read approx n bytes.
****************************************************************************/
-static int readfile(uint8_t *b, int n, XFILE *f)
+static int readfile(uint8_t *b, int n, FILE *f)
{
int i;
int c;
if (!translation)
- return x_fread(b,1,n,f);
+ return fread(b,1,n,f);
i = 0;
while (i < (n - 1)) {
- if ((c = x_getc(f)) == EOF) {
+ if ((c = getc(f)) == EOF) {
break;
}
@@ -243,7 +242,7 @@ static int readfile(uint8_t *b, int n, XFILE *f)
}
struct push_state {
- XFILE *f;
+ FILE *f;
off_t nread;
};
@@ -252,7 +251,7 @@ static size_t push_source(uint8_t *buf, size_t n, void *priv)
struct push_state *state = (struct push_state *)priv;
int result;
- if (x_feof(state->f)) {
+ if (feof(state->f)) {
return 0;
}
@@ -1873,7 +1872,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
{
TALLOC_CTX *ctx = talloc_tos();
uint16_t fnum;
- XFILE *f;
+ FILE *f;
off_t start = 0;
int rc = 0;
struct timespec tp_start;
@@ -1922,14 +1921,14 @@ static int do_put(const char *rname, const char *lname, bool reput)
Note that in this case this function will exit(0) rather
than returning. */
if (!strcmp(lname, "-")) {
- f = x_stdin;
+ f = stdin;
/* size of file is not known */
} else {
- f = x_fopen(lname,O_RDONLY, 0);
+ f = fopen(lname, "r");
if (f && reput) {
- if (x_tseek(f, start, SEEK_SET) == -1) {
+ if (fseek(f, start, SEEK_SET) == -1) {
d_printf("Error seeking local file\n");
- x_fclose(f);
+ fclose(f);
return 1;
}
}
@@ -1943,7 +1942,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
DEBUG(1,("putting file %s as %s ",lname,
rname));
- x_setvbuf(f, NULL, X_IOFBF, io_bufsize);
+ setvbuf(f, NULL, _IOFBF, io_bufsize);
state.f = f;
state.nread = 0;
@@ -1959,14 +1958,14 @@ static int do_put(const char *rname, const char *lname, bool reput)
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s closing remote file %s\n", nt_errstr(status),
rname);
- if (f != x_stdin) {
- x_fclose(f);
+ if (f != stdin) {
+ fclose(f);
}
return 1;
}
- if (f != x_stdin) {
- x_fclose(f);
+ if (f != stdin) {
+ fclose(f);
}
{
@@ -1983,7 +1982,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
put_total_size / (1.024*put_total_time_ms)));
}
- if (f == x_stdin) {
+ if (f == stdin) {
cli_shutdown(cli);
exit(rc);
}
--
2.11.0
>From 7a418d36ffbdf64e2004d847ec8585c814c559e4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Nov 2016 01:30:29 +0100
Subject: [PATCH 03/16] idmap_hash: xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_hash/mapfile.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/source3/winbindd/idmap_hash/mapfile.c b/source3/winbindd/idmap_hash/mapfile.c
index 5821d60167f..82812a1a72d 100644
--- a/source3/winbindd/idmap_hash/mapfile.c
+++ b/source3/winbindd/idmap_hash/mapfile.c
@@ -23,9 +23,8 @@
#include "winbindd/winbindd.h"
#include "idmap.h"
#include "idmap_hash.h"
-#include "lib/util/xfile.h"
-static XFILE *lw_map_file = NULL;
+static FILE *lw_map_file = NULL;
/*********************************************************************
********************************************************************/
@@ -37,7 +36,7 @@ static bool mapfile_open(void)
/* If we have an open handle, just reset it */
if (lw_map_file) {
- return (x_tseek(lw_map_file, 0, SEEK_SET) == 0);
+ return (fseek(lw_map_file, 0, SEEK_SET) == 0);
}
mapfile_name = lp_parm_const_string(-1, "idmap_hash", "name_map", NULL);
@@ -45,7 +44,7 @@ static bool mapfile_open(void)
return false;
}
- lw_map_file = x_fopen(mapfile_name, O_RDONLY, 0);
+ lw_map_file = fopen(mapfile_name, "r");
if (!lw_map_file) {
DEBUG(0,("can't open idmap_hash:name_map (%s). Error %s\n",
mapfile_name, strerror(errno) ));
@@ -67,7 +66,7 @@ static bool mapfile_read_line(fstring key, fstring value)
if (!lw_map_file)
return false;
- p = x_fgets(buffer, sizeof(buffer)-1, lw_map_file);
+ p = fgets(buffer, sizeof(buffer)-1, lw_map_file);
if (p == NULL) {
return false;
}
@@ -114,7 +113,7 @@ static bool mapfile_close(void)
{
int ret = 0;
if (lw_map_file) {
- ret = x_fclose(lw_map_file);
+ ret = fclose(lw_map_file);
lw_map_file = NULL;
}
--
2.11.0
>From 0d25b8179a8a08055cf608c032333a5df362401e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Nov 2016 01:26:08 +0100
Subject: [PATCH 04/16] lib: popt_common xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/popt_common.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index f74543fa5ac..b2fd39c56b4 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -24,7 +24,6 @@
#include "system/filesys.h"
#include "popt_common.h"
#include "lib/param/param.h"
-#include "lib/util/xfile.h"
/* Handle command line options:
* -d,--debuglevel
@@ -285,22 +284,22 @@ static void get_password_file(struct user_auth_info *auth_info)
static void get_credentials_file(struct user_auth_info *auth_info,
const char *file)
{
- XFILE *auth;
+ FILE *auth;
fstring buf;
uint16_t len = 0;
char *ptr, *val, *param;
- if ((auth=x_fopen(file, O_RDONLY, 0)) == NULL)
- {
+ auth = fopen(file, "r");
+ if (auth == NULL) {
/* fail if we can't open the credentials file */
d_printf("ERROR: Unable to open credentials file!\n");
exit(-1);
}
- while (!x_feof(auth))
+ while (!feof(auth))
{
/* get a line from the file */
- if (!x_fgets(buf, sizeof(buf), auth))
+ if (!fgets(buf, sizeof(buf), auth))
continue;
len = strlen(buf);
@@ -334,7 +333,7 @@ static void get_credentials_file(struct user_auth_info *auth_info,
}
memset(buf, 0, sizeof(buf));
}
- x_fclose(auth);
+ fclose(auth);
}
/* Handle command line options:
--
2.11.0
>From 1d7865ab71d5288ab3df6413b7921028e466c720 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 21 Nov 2016 19:20:10 +0100
Subject: [PATCH 05/16] lib: Add fgets_slash
Copy x_fgets_slash with conversion to stdio and talloc.
Probably I'd do this functionality a bit differently, but for simplicity I
chose to make it the same as what is there.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/util/samba_util.h | 2 ++
lib/util/util_file.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 7863555e908..897e0f5923d 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -336,6 +336,8 @@ const char **str_list_make_v3_const(TALLOC_CTX *mem_ctx,
*/
_PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint);
+char *fgets_slash(TALLOC_CTX *mem_ctx, char *s2, int maxlen, FILE *f);
+
/**
load a file into memory from a fd.
**/
diff --git a/lib/util/util_file.c b/lib/util/util_file.c
index 4948afb16b6..ac8206008a3 100644
--- a/lib/util/util_file.c
+++ b/lib/util/util_file.c
@@ -79,6 +79,88 @@ _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint)
return data;
}
+char *fgets_slash(TALLOC_CTX *mem_ctx, char *s2, int maxlen, FILE *f)
+{
+ char *s = s2;
+ int len = 0;
+ int c;
+ bool start_of_line = true;
+
+ if (feof(f)) {
+ return NULL;
+ }
+
+ if (maxlen < 2) {
+ return NULL;
+ }
+
+ if (s2 == NULL) {
+ maxlen = MIN(maxlen,8);
+ s = talloc_array(mem_ctx, char, maxlen);
+ }
+
+ if (s == NULL) {
+ return NULL;
+ }
+
+ *s = 0;
+
+ while (len < maxlen-1) {
+ c = getc(f);
+ switch (c)
+ {
+ case '\r':
+ break;
+ case '\n':
+ while (len > 0 && s[len-1] == ' ') {
+ s[--len] = 0;
+ }
+ if (len > 0 && s[len-1] == '\\') {
+ s[--len] = 0;
+ start_of_line = true;
+ break;
+ }
+ return s;
+ case EOF:
+ if (len <= 0 && (s2 == NULL)) {
+ TALLOC_FREE(s);
+ }
+ return (len>0) ? s : NULL;
+ case ' ':
+ if (start_of_line) {
+ break;
+ }
+ /* fall through */
+ default:
+ start_of_line = false;
+ s[len++] = c;
+ s[len] = 0;
+ }
+ if ((s2 == NULL) && (len > maxlen-3)) {
+ int m;
+ char *t;
+
+ m = maxlen * 2;
+ if (m < maxlen) {
+ DBG_ERR("length overflow");
+ TALLOC_FREE(s);
+ return NULL;
+ }
+ maxlen = m;
+
+ t = talloc_realloc(mem_ctx, s, char, maxlen);
+ if (t == NULL) {
+ DBG_ERR("failed to expand buffer!\n");
+ TALLOC_FREE(s);
+ return NULL;
+ }
+
+ s = t;
+ }
+ }
+
+ return s;
+}
/**
load a file into memory from a fd.
--
2.11.0
>From 61b57a6ff95729e42c0f2bf1ef6eb9eca8246bec Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Nov 2016 01:38:16 +0100
Subject: [PATCH 06/16] smbd: username map file handling xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/auth/user_util.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/source3/auth/user_util.c b/source3/auth/user_util.c
index f3cf499f583..1ddb7387307 100644
--- a/source3/auth/user_util.c
+++ b/source3/auth/user_util.c
@@ -22,7 +22,6 @@
#include "includes.h"
#include "system/filesys.h"
#include "auth.h"
-#include "lib/util/xfile.h"
/*******************************************************************
Map a username from a dos name to a unix name by looking in the username
@@ -268,7 +267,7 @@ bool user_in_list(TALLOC_CTX *ctx, const char *user, const char * const *list)
bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out)
{
- XFILE *f;
+ FILE *f;
char *mapfile = lp_username_map(talloc_tos());
char *s;
char buf[512];
@@ -354,7 +353,7 @@ bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out)
if (!*mapfile)
return False;
- f = x_fopen(mapfile,O_RDONLY, 0);
+ f = fopen(mapfile, "r");
if (!f) {
DEBUG(0,("can't open username map %s. Error %s\n",mapfile, strerror(errno) ));
return False;
@@ -362,7 +361,7 @@ bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out)
DEBUG(4,("Scanning username map %s\n",mapfile));
- while((s=x_fgets_slash(buf,sizeof(buf),f))!=NULL) {
+ while((s=fgets_slash(NULL,buf,sizeof(buf),f))!=NULL) {
char *unixname = s;
char *dosname = strchr_m(unixname,'=');
char **dosuserlist;
@@ -410,13 +409,13 @@ bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out)
*p_user_out = talloc_strdup(ctx, unixname);
if (!*p_user_out) {
TALLOC_FREE(dosuserlist);
- x_fclose(f);
+ fclose(f);
return false;
}
if ( return_if_mapped ) {
TALLOC_FREE(dosuserlist);
- x_fclose(f);
+ fclose(f);
return True;
}
}
@@ -424,7 +423,7 @@ bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out)
TALLOC_FREE(dosuserlist);
}
- x_fclose(f);
+ fclose(f);
/*
* If we didn't successfully map a user in the loop above,
--
2.11.0
>From 80a08a23555924caee092df18242a1b66502025e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 25 Nov 2016 22:01:38 +0100
Subject: [PATCH 07/16] torture: upload_printer_driver_file xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/torture/rpc/spoolss.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/source4/torture/rpc/spoolss.c b/source4/torture/rpc/spoolss.c
index 81efff895c4..409ba5777b3 100644
--- a/source4/torture/rpc/spoolss.c
+++ b/source4/torture/rpc/spoolss.c
@@ -10420,7 +10420,7 @@ static bool upload_printer_driver_file(struct torture_context *tctx,
struct torture_driver_context *d,
const char *file_name)
{
- XFILE *f;
+ FILE *f;
int fnum;
uint8_t *buf;
int maxwrite = 64512;
@@ -10462,23 +10462,23 @@ static bool upload_printer_driver_file(struct torture_context *tctx,
torture_fail(tctx, talloc_asprintf(tctx, "failed to open remote file: %s\n", remote_name));
}
- f = x_fopen(local_name, O_RDONLY, 0);
+ f = fopen(local_name, "r");
if (f == NULL) {
torture_fail(tctx, talloc_asprintf(tctx, "failed to open local file: %s\n", local_name));
}
buf = talloc_array(tctx, uint8_t, maxwrite);
if (!buf) {
- x_fclose(f);
+ fclose(f);
return false;
}
- while (!x_feof(f)) {
+ while (!feof(f)) {
int n = maxwrite;
int ret;
- if ((n = x_fread(buf, 1, n, f)) < 1) {
- if((n == 0) && x_feof(f))
+ if ((n = fread(buf, 1, n, f)) < 1) {
+ if((n == 0) && feof(f))
break; /* Empty local file. */
torture_warning(tctx,
@@ -10497,7 +10497,7 @@ static bool upload_printer_driver_file(struct torture_context *tctx,
nread += n;
}
- x_fclose(f);
+ fclose(f);
torture_assert_ntstatus_ok(tctx,
smbcli_close(cli->tree, fnum),
--
2.11.0
>From 095fee16e033afab383a1278fef28a2ae7cd6f0d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 19 Nov 2016 09:25:12 +0000
Subject: [PATCH 08/16] ntlm_auth3: xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/utils/ntlm_auth.c | 231 ++++++++++++++++++++++++----------------------
1 file changed, 122 insertions(+), 109 deletions(-)
diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
index 9888dbc1791..cb9c466e0a5 100644
--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -47,7 +47,6 @@
#include "nsswitch/libwbclient/wbclient.h"
#include "lib/param/loadparm.h"
#include "lib/util/base64.h"
-#include "lib/util/xfile.h"
#if HAVE_KRB5
#include "auth/kerberos/pac_utils.h"
@@ -193,7 +192,7 @@ static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mod
DATA_BLOB in;
if (strlen(buf) < 2) {
DEBUG(1, ("query [%s] invalid", buf));
- x_fprintf(x_stdout, "BH Query invalid\n");
+ printf("BH Query invalid\n");
return;
}
@@ -210,17 +209,17 @@ static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mod
if (*password == NULL) {
DEBUG(1, ("Out of memory\n"));
- x_fprintf(x_stdout, "BH Out of memory\n");
+ printf("BH Out of memory\n");
data_blob_free(&in);
return;
}
- x_fprintf(x_stdout, "OK\n");
+ printf("OK\n");
data_blob_free(&in);
return;
}
DEBUG(1, ("Asked for (and expected) a password\n"));
- x_fprintf(x_stdout, "BH Expected a password\n");
+ printf("BH Expected a password\n");
data_blob_free(&in);
}
@@ -239,14 +238,14 @@ static const char *get_password(struct cli_credentials *credentials)
state = talloc_zero(frame, struct ntlm_auth_state);
if (state == NULL) {
DEBUG(0, ("squid_stream: Failed to talloc ntlm_auth_state\n"));
- x_fprintf(x_stderr, "ERR\n");
+ fprintf(stderr, "ERR\n");
exit(1);
}
state->mem_ctx = state;
/* Ask for a password */
- x_fprintf(x_stdout, "PW\n");
+ printf("PW\n");
manage_squid_request(NUM_HELPER_MODES /* bogus */, NULL, state, manage_gensec_get_pw_request, (void **)&password);
talloc_steal(credentials, password);
@@ -1246,7 +1245,7 @@ static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
pass=(char *)memchr(buf,' ',length);
if (!pass) {
DEBUG(2, ("Password not found. Denying access\n"));
- x_fprintf(x_stdout, "ERR\n");
+ printf("ERR\n");
return;
}
*pass='\0';
@@ -1258,9 +1257,9 @@ static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
}
if (check_plaintext_auth(user, pass, False)) {
- x_fprintf(x_stdout, "OK\n");
+ printf("OK\n");
} else {
- x_fprintf(x_stdout, "ERR\n");
+ printf("ERR\n");
}
}
@@ -1293,7 +1292,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
} else {
state = talloc_zero(NULL, struct gensec_ntlm_state);
if (!state) {
- x_fprintf(x_stdout, "BH No Memory\n");
+ printf("BH No Memory\n");
exit(1);
}
*private1 = state;
@@ -1304,7 +1303,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
if (strlen(buf) < 2) {
DEBUG(1, ("query [%s] invalid", buf));
- x_fprintf(x_stdout, "BH Query invalid\n");
+ printf("BH Query invalid\n");
return;
}
@@ -1313,7 +1312,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
DEBUG(10, ("Setting flags to negotiate\n"));
talloc_free(want_feature_list);
want_feature_list = talloc_strndup(state, buf+3, strlen(buf)-3);
- x_fprintf(x_stdout, "OK\n");
+ printf("OK\n");
return;
}
in = base64_decode_data_blob(buf + 3);
@@ -1328,7 +1327,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
}
} else if ( (strncmp(buf, "OK", 2) == 0)) {
/* Just return BH, like ntlm_auth from Samba 3 does. */
- x_fprintf(x_stdout, "BH Command expected\n");
+ printf("BH Command expected\n");
data_blob_free(&in);
return;
} else if ( (strncmp(buf, "TT ", 3) != 0) &&
@@ -1340,7 +1339,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
(strncmp(buf, "GK", 2) != 0) &&
(strncmp(buf, "GF", 2) != 0)) {
DEBUG(1, ("SPNEGO request [%s] invalid prefix\n", buf));
- x_fprintf(x_stdout, "BH SPNEGO request invalid prefix\n");
+ printf("BH SPNEGO request invalid prefix\n");
data_blob_free(&in);
return;
}
@@ -1388,7 +1387,8 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
nt_status = ntlm_auth_prepare_gensec_client(state, lp_ctx,
&state->gensec_state);
if (!NT_STATUS_IS_OK(nt_status)) {
- x_fprintf(x_stdout, "BH GENSEC mech failed to start: %s\n", nt_errstr(nt_status));
+ printf("BH GENSEC mech failed to start: %s\n",
+ nt_errstr(nt_status));
talloc_free(mem_ctx);
return;
}
@@ -1422,7 +1422,8 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
nt_status = ntlm_auth_prepare_gensec_server(state, lp_ctx,
&state->gensec_state);
if (!NT_STATUS_IS_OK(nt_status)) {
- x_fprintf(x_stdout, "BH GENSEC mech failed to start: %s\n", nt_errstr(nt_status));
+ printf("BH GENSEC mech failed to start: %s\n",
+ nt_errstr(nt_status));
talloc_free(mem_ctx);
return;
}
@@ -1458,7 +1459,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(1, ("GENSEC mech failed to start: %s\n", nt_errstr(nt_status)));
- x_fprintf(x_stdout, "BH GENSEC mech failed to start\n");
+ printf("BH GENSEC mech failed to start\n");
talloc_free(mem_ctx);
return;
}
@@ -1475,7 +1476,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
cli_credentials_set_password(gensec_get_credentials(state->gensec_state),
state->set_password,
CRED_SPECIFIED);
- x_fprintf(x_stdout, "OK\n");
+ printf("OK\n");
data_blob_free(&in);
talloc_free(mem_ctx);
return;
@@ -1487,13 +1488,13 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
nt_status = gensec_session_key(state->gensec_state, mem_ctx, &session_key);
if(!NT_STATUS_IS_OK(nt_status)) {
DEBUG(1, ("gensec_session_key failed: %s\n", nt_errstr(nt_status)));
- x_fprintf(x_stdout, "BH No session key\n");
+ printf("BH No session key\n");
talloc_free(mem_ctx);
return;
} else {
base64_key = base64_encode_data_blob(state, session_key);
SMB_ASSERT(base64_key != NULL);
- x_fprintf(x_stdout, "GK %s\n", base64_key);
+ printf("GK %s\n", base64_key);
talloc_free(base64_key);
}
talloc_free(mem_ctx);
@@ -1507,11 +1508,11 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
neg_flags = gensec_ntlmssp_neg_flags(state->gensec_state);
if (neg_flags == 0) {
- x_fprintf(x_stdout, "BH\n");
+ printf("BH\n");
return;
}
- x_fprintf(x_stdout, "GF 0x%08x\n", neg_flags);
+ printf("GF 0x%08x\n", neg_flags);
return;
}
@@ -1579,17 +1580,17 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
switch (stdio_helper_mode) {
case GSS_SPNEGO_SERVER:
- x_fprintf(x_stdout, "%s %s %s\n", reply_code,
- out_base64 ? out_base64 : "*",
- reply_arg ? reply_arg : "*");
+ printf("%s %s %s\n", reply_code,
+ out_base64 ? out_base64 : "*",
+ reply_arg ? reply_arg : "*");
break;
default:
if (out_base64) {
- x_fprintf(x_stdout, "%s %s\n", reply_code, out_base64);
+ printf("%s %s\n", reply_code, out_base64);
} else if (reply_arg) {
- x_fprintf(x_stdout, "%s %s\n", reply_code, reply_arg);
+ printf("%s %s\n", reply_code, reply_arg);
} else {
- x_fprintf(x_stdout, "%s\n", reply_code);
+ printf("%s\n", reply_code);
}
}
@@ -1642,24 +1643,25 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
if (strequal(buf, ".")) {
if (!full_username && !username) {
- x_fprintf(x_stdout, "Error: No username supplied!\n");
+ printf("Error: No username supplied!\n");
} else if (plaintext_password) {
/* handle this request as plaintext */
if (!full_username) {
if (asprintf(&full_username, "%s%c%s", domain, winbind_separator(), username) == -1) {
- x_fprintf(x_stdout, "Error: Out of memory in asprintf!\n.\n");
+ printf("Error: Out of memory in "
+ "asprintf!\n.\n");
return;
}
}
if (check_plaintext_auth(full_username, plaintext_password, False)) {
- x_fprintf(x_stdout, "Authenticated: Yes\n");
+ printf("Authenticated: Yes\n");
} else {
- x_fprintf(x_stdout, "Authenticated: No\n");
+ printf("Authenticated: No\n");
}
} else if (!lm_response.data && !nt_response.data) {
- x_fprintf(x_stdout, "Error: No password supplied!\n");
+ printf("Error: No password supplied!\n");
} else if (!challenge.data) {
- x_fprintf(x_stdout, "Error: No lanman-challenge supplied!\n");
+ printf("Error: No lanman-challenge supplied!\n");
} else {
char *error_string = NULL;
uchar lm_key[8];
@@ -1672,7 +1674,8 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
/* username might be 'tainted', don't print into our new-line deleimianted stream */
- x_fprintf(x_stdout, "Error: Could not parse into domain and username\n");
+ printf("Error: Could not parse into "
+ "domain and username\n");
}
SAFE_FREE(username);
SAFE_FREE(domain);
@@ -1741,14 +1744,15 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
}
if (!NT_STATUS_IS_OK(nt_status)) {
- x_fprintf(x_stdout, "Authenticated: No\n");
- x_fprintf(x_stdout, "Authentication-Error: %s\n.\n", error_string);
+ printf("Authenticated: No\n");
+ printf("Authentication-Error: %s\n.\n",
+ error_string);
} else {
static char zeros[16];
char *hex_lm_key;
char *hex_user_session_key;
- x_fprintf(x_stdout, "Authenticated: Yes\n");
+ printf("Authenticated: Yes\n");
if (ntlm_server_1_lm_session_key
&& (memcmp(zeros, lm_key,
@@ -1756,7 +1760,8 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
hex_lm_key = hex_encode_talloc(NULL,
(const unsigned char *)lm_key,
sizeof(lm_key));
- x_fprintf(x_stdout, "LANMAN-Session-Key: %s\n", hex_lm_key);
+ printf("LANMAN-Session-Key: %s\n",
+ hex_lm_key);
TALLOC_FREE(hex_lm_key);
}
@@ -1766,7 +1771,8 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
hex_user_session_key = hex_encode_talloc(NULL,
(const unsigned char *)user_session_key,
sizeof(user_session_key));
- x_fprintf(x_stdout, "User-Session-Key: %s\n", hex_user_session_key);
+ printf("User-Session-Key: %s\n",
+ hex_user_session_key);
TALLOC_FREE(hex_user_session_key);
}
}
@@ -1782,7 +1788,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
SAFE_FREE(plaintext_password);
ntlm_server_1_user_session_key = False;
ntlm_server_1_lm_session_key = False;
- x_fprintf(x_stdout, ".\n");
+ printf(".\n");
return;
}
@@ -1796,7 +1802,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
if (!parameter) {
DEBUG(0, ("Parameter not found!\n"));
- x_fprintf(x_stdout, "Error: Parameter not found!\n.\n");
+ printf("Error: Parameter not found!\n.\n");
return;
}
@@ -1819,25 +1825,28 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
if (strequal(request, "LANMAN-Challenge")) {
challenge = strhex_to_data_blob(NULL, parameter);
if (challenge.length != 8) {
- x_fprintf(x_stdout, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n",
- parameter,
- (int)challenge.length);
+ printf("Error: hex decode of %s failed! "
+ "(got %d bytes, expected 8)\n.\n",
+ parameter,
+ (int)challenge.length);
challenge = data_blob_null;
}
} else if (strequal(request, "NT-Response")) {
nt_response = strhex_to_data_blob(NULL, parameter);
if (nt_response.length < 24) {
- x_fprintf(x_stdout, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n",
- parameter,
- (int)nt_response.length);
+ printf("Error: hex decode of %s failed! "
+ "(only got %d bytes, needed at least 24)\n.\n",
+ parameter,
+ (int)nt_response.length);
nt_response = data_blob_null;
}
} else if (strequal(request, "LANMAN-Response")) {
lm_response = strhex_to_data_blob(NULL, parameter);
if (lm_response.length != 24) {
- x_fprintf(x_stdout, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n",
- parameter,
- (int)lm_response.length);
+ printf("Error: hex decode of %s failed! "
+ "(got %d bytes, expected 24)\n.\n",
+ parameter,
+ (int)lm_response.length);
lm_response = data_blob_null;
}
} else if (strequal(request, "Password")) {
@@ -1853,7 +1862,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
} else if (strequal(request, "Request-LanMan-Session-Key")) {
ntlm_server_1_lm_session_key = strequal(parameter, "Yes");
} else {
- x_fprintf(x_stdout, "Error: Unknown request %s\n.\n", request);
+ printf("Error: Unknown request %s\n.\n", request);
}
}
@@ -1926,11 +1935,11 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
}
if (!full_username && !username) {
- x_fprintf(x_stdout, "Error: No username supplied!\n");
+ printf("Error: No username supplied!\n");
} else if ((!new_nt_pswd.data || !old_nt_hash_enc.data) &&
(!new_lm_pswd.data || old_lm_hash_enc.data) ) {
- x_fprintf(x_stdout, "Error: No NT or LM password "
- "blobs supplied!\n");
+ printf("Error: No NT or LM password "
+ "blobs supplied!\n");
} else {
char *error_string = NULL;
@@ -1944,9 +1953,9 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
/* username might be 'tainted', don't
* print into our new-line
* deleimianted stream */
- x_fprintf(x_stdout, "Error: Could not "
- "parse into domain and "
- "username\n");
+ printf("Error: Could not "
+ "parse into domain and "
+ "username\n");
SAFE_FREE(username);
username = smb_xstrdup(full_username);
} else {
@@ -1965,11 +1974,11 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
new_lm_pswd,
old_lm_hash_enc,
&error_string))) {
- x_fprintf(x_stdout, "Password-Change: No\n");
- x_fprintf(x_stdout, "Password-Change-Error: "
- "%s\n.\n", error_string);
+ printf("Password-Change: No\n");
+ printf("Password-Change-Error: %s\n.\n",
+ error_string);
} else {
- x_fprintf(x_stdout, "Password-Change: Yes\n");
+ printf("Password-Change: Yes\n");
}
SAFE_FREE(error_string);
@@ -1984,7 +1993,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
SAFE_FREE(domain);
SAFE_FREE(newpswd);
SAFE_FREE(oldpswd);
- x_fprintf(x_stdout, ".\n");
+ printf(".\n");
return;
}
@@ -1998,7 +2007,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
if (!parameter) {
DEBUG(0, ("Parameter not found!\n"));
- x_fprintf(x_stdout, "Error: Parameter not found!\n.\n");
+ printf("Error: Parameter not found!\n.\n");
return;
}
@@ -2020,28 +2029,28 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
if (strequal(request, "new-nt-password-blob")) {
new_nt_pswd = strhex_to_data_blob(NULL, parameter);
if (new_nt_pswd.length != 516) {
- x_fprintf(x_stdout, "Error: hex decode of %s failed! "
- "(got %d bytes, expected 516)\n.\n",
- parameter,
- (int)new_nt_pswd.length);
+ printf("Error: hex decode of %s failed! "
+ "(got %d bytes, expected 516)\n.\n",
+ parameter,
+ (int)new_nt_pswd.length);
new_nt_pswd = data_blob_null;
}
} else if (strequal(request, "old-nt-hash-blob")) {
old_nt_hash_enc = strhex_to_data_blob(NULL, parameter);
if (old_nt_hash_enc.length != 16) {
- x_fprintf(x_stdout, "Error: hex decode of %s failed! "
- "(got %d bytes, expected 16)\n.\n",
- parameter,
- (int)old_nt_hash_enc.length);
+ printf("Error: hex decode of %s failed! "
+ "(got %d bytes, expected 16)\n.\n",
+ parameter,
+ (int)old_nt_hash_enc.length);
old_nt_hash_enc = data_blob_null;
}
} else if (strequal(request, "new-lm-password-blob")) {
new_lm_pswd = strhex_to_data_blob(NULL, parameter);
if (new_lm_pswd.length != 516) {
- x_fprintf(x_stdout, "Error: hex decode of %s failed! "
- "(got %d bytes, expected 516)\n.\n",
- parameter,
- (int)new_lm_pswd.length);
+ printf("Error: hex decode of %s failed! "
+ "(got %d bytes, expected 516)\n.\n",
+ parameter,
+ (int)new_lm_pswd.length);
new_lm_pswd = data_blob_null;
}
}
@@ -2049,10 +2058,10 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
old_lm_hash_enc = strhex_to_data_blob(NULL, parameter);
if (old_lm_hash_enc.length != 16)
{
- x_fprintf(x_stdout, "Error: hex decode of %s failed! "
- "(got %d bytes, expected 16)\n.\n",
- parameter,
- (int)old_lm_hash_enc.length);
+ printf("Error: hex decode of %s failed! "
+ "(got %d bytes, expected 16)\n.\n",
+ parameter,
+ (int)old_lm_hash_enc.length);
old_lm_hash_enc = data_blob_null;
}
} else if (strequal(request, "nt-domain")) {
@@ -2066,7 +2075,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode stdio_h
} else if (strequal(request, "old-password")) {
oldpswd = smb_xstrdup(parameter);
} else {
- x_fprintf(x_stdout, "Error: Unknown request %s\n.\n", request);
+ printf("Error: Unknown request %s\n.\n", request);
}
}
@@ -2083,7 +2092,7 @@ static void manage_squid_request(enum stdio_helper_mode stdio_helper_mode,
buf = talloc_strdup(state->mem_ctx, "");
if (!buf) {
DEBUG(0, ("Failed to allocate input buffer.\n"));
- x_fprintf(x_stderr, "ERR\n");
+ fprintf(stderr, "ERR\n");
exit(1);
}
@@ -2107,7 +2116,7 @@ static void manage_squid_request(enum stdio_helper_mode stdio_helper_mode,
if (buf_size > MAX_BUFFER_SIZE) {
DEBUG(2, ("Oversized message\n"));
- x_fprintf(x_stderr, "ERR\n");
+ fprintf(stderr, "ERR\n");
talloc_free(buf);
return;
}
@@ -2122,7 +2131,7 @@ static void manage_squid_request(enum stdio_helper_mode stdio_helper_mode,
if (buf[0] == '\0') {
DEBUG(2, ("Invalid Request\n"));
- x_fprintf(x_stderr, "ERR\n");
+ fprintf(stderr, "ERR\n");
talloc_free(buf);
return;
}
@@ -2139,20 +2148,20 @@ static void squid_stream(enum stdio_helper_mode stdio_mode,
struct ntlm_auth_state *state;
/* initialize FDescs */
- x_setbuf(x_stdout, NULL);
- x_setbuf(x_stderr, NULL);
+ setbuf(stdout, NULL);
+ setbuf(stderr, NULL);
mem_ctx = talloc_init("ntlm_auth");
if (!mem_ctx) {
DEBUG(0, ("squid_stream: Failed to create talloc context\n"));
- x_fprintf(x_stderr, "ERR\n");
+ fprintf(stderr, "ERR\n");
exit(1);
}
state = talloc_zero(mem_ctx, struct ntlm_auth_state);
if (!state) {
DEBUG(0, ("squid_stream: Failed to talloc ntlm_auth_state\n"));
- x_fprintf(x_stderr, "ERR\n");
+ fprintf(stderr, "ERR\n");
exit(1);
}
@@ -2180,7 +2189,7 @@ static bool check_auth_crap(void)
char *error_string;
static uint8_t zeros[16];
- x_setbuf(x_stdout, NULL);
+ setbuf(stdout, NULL);
if (request_lm_key)
flags |= WBFLAG_PAM_LMKEY;
@@ -2201,9 +2210,8 @@ static bool check_auth_crap(void)
&error_string, NULL);
if (!NT_STATUS_IS_OK(nt_status)) {
- x_fprintf(x_stdout, "%s (0x%x)\n",
- error_string,
- NT_STATUS_V(nt_status));
+ printf("%s (0x%x)\n", error_string,
+ NT_STATUS_V(nt_status));
SAFE_FREE(error_string);
return False;
}
@@ -2213,7 +2221,7 @@ static bool check_auth_crap(void)
sizeof(lm_key)) != 0)) {
hex_lm_key = hex_encode_talloc(talloc_tos(), (const unsigned char *)lm_key,
sizeof(lm_key));
- x_fprintf(x_stdout, "LM_KEY: %s\n", hex_lm_key);
+ printf("LM_KEY: %s\n", hex_lm_key);
TALLOC_FREE(hex_lm_key);
}
if (request_user_session_key
@@ -2221,7 +2229,7 @@ static bool check_auth_crap(void)
sizeof(user_session_key)) != 0)) {
hex_user_session_key = hex_encode_talloc(talloc_tos(), (const unsigned char *)user_session_key,
sizeof(user_session_key));
- x_fprintf(x_stdout, "NT_KEY: %s\n", hex_user_session_key);
+ printf("NT_KEY: %s\n", hex_user_session_key);
TALLOC_FREE(hex_user_session_key);
}
@@ -2339,18 +2347,20 @@ enum {
case OPT_CHALLENGE:
opt_challenge = strhex_to_data_blob(NULL, hex_challenge);
if (opt_challenge.length != 8) {
- x_fprintf(x_stderr, "hex decode of %s failed! (only got %d bytes)\n",
- hex_challenge,
- (int)opt_challenge.length);
+ fprintf(stderr, "hex decode of %s failed! "
+ "(only got %d bytes)\n",
+ hex_challenge,
+ (int)opt_challenge.length);
exit(1);
}
break;
case OPT_LM:
opt_lm_response = strhex_to_data_blob(NULL, hex_lm_response);
if (opt_lm_response.length != 24) {
- x_fprintf(x_stderr, "hex decode of %s failed! (only got %d bytes)\n",
- hex_lm_response,
- (int)opt_lm_response.length);
+ fprintf(stderr, "hex decode of %s failed! "
+ "(only got %d bytes)\n",
+ hex_lm_response,
+ (int)opt_lm_response.length);
exit(1);
}
break;
@@ -2358,9 +2368,10 @@ enum {
case OPT_NT:
opt_nt_response = strhex_to_data_blob(NULL, hex_nt_response);
if (opt_nt_response.length < 24) {
- x_fprintf(x_stderr, "hex decode of %s failed! (only got %d bytes)\n",
- hex_nt_response,
- (int)opt_nt_response.length);
+ fprintf(stderr, "hex decode of %s failed! "
+ "(only got %d bytes)\n",
+ hex_nt_response,
+ (int)opt_nt_response.length);
exit(1);
}
break;
@@ -2380,7 +2391,7 @@ enum {
opt_username = p+1;
*p = '\0';
if (opt_domain && !strequal(opt_domain, domain)) {
- x_fprintf(x_stderr, "Domain specified in username (%s) "
+ fprintf(stderr, "Domain specified in username (%s) "
"doesn't match specified domain (%s)!\n\n",
domain, opt_domain);
poptPrintHelp(pc, stderr, 0);
@@ -2403,7 +2414,7 @@ enum {
lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
if (lp_ctx == NULL) {
- x_fprintf(x_stderr, "loadparm_init_s3() failed!\n");
+ fprintf(stderr, "loadparm_init_s3() failed!\n");
exit(1);
}
@@ -2415,17 +2426,19 @@ enum {
exit(0);
}
}
- x_fprintf(x_stderr, "unknown helper protocol [%s]\n\nValid helper protools:\n\n", helper_protocol);
+ fprintf(stderr, "unknown helper protocol [%s]\n\n"
+ "Valid helper protools:\n\n", helper_protocol);
for (i=0; i<NUM_HELPER_MODES; i++) {
- x_fprintf(x_stderr, "%s\n", stdio_helper_protocols[i].name);
+ fprintf(stderr, "%s\n",
+ stdio_helper_protocols[i].name);
}
exit(1);
}
if (!opt_username || !*opt_username) {
- x_fprintf(x_stderr, "username must be specified!\n\n");
+ fprintf(stderr, "username must be specified!\n\n");
poptPrintHelp(pc, stderr, 0);
exit(1);
}
--
2.11.0
>From bc36924a1ab40efe5174f29fd7b95e061883a5a4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Nov 2016 01:42:36 +0100
Subject: [PATCH 09/16] vfs: expand_msdfs xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/modules/vfs_expand_msdfs.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c
index 40c57c2d107..ffbfa333bad 100644
--- a/source3/modules/vfs_expand_msdfs.c
+++ b/source3/modules/vfs_expand_msdfs.c
@@ -24,7 +24,6 @@
#include "smbd/globals.h"
#include "auth.h"
#include "../lib/tsocket/tsocket.h"
-#include "lib/util/xfile.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
@@ -45,12 +44,12 @@
static char *read_target_host(TALLOC_CTX *ctx, const char *mapfile,
const char *clientaddr)
{
- XFILE *f;
+ FILE *f;
char buf[1024];
char *space = buf;
bool found = false;
- f = x_fopen(mapfile, O_RDONLY, 0);
+ f = fopen(mapfile, "r");
if (f == NULL) {
DEBUG(0,("can't open IP map %s. Error %s\n",
@@ -60,7 +59,7 @@ static char *read_target_host(TALLOC_CTX *ctx, const char *mapfile,
DEBUG(10, ("Scanning mapfile [%s]\n", mapfile));
- while (x_fgets(buf, sizeof(buf), f) != NULL) {
+ while (fgets(buf, sizeof(buf), f) != NULL) {
if ((strlen(buf) > 0) && (buf[strlen(buf)-1] == '\n'))
buf[strlen(buf)-1] = '\0';
@@ -82,7 +81,7 @@ static char *read_target_host(TALLOC_CTX *ctx, const char *mapfile,
}
}
- x_fclose(f);
+ fclose(f);
if (!found) {
return NULL;
--
2.11.0
>From 2a1fedb32dfbd76a6e4423814fd2a6313f400abf Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Nov 2016 01:44:48 +0100
Subject: [PATCH 10/16] rpc_server: svcctl xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/rpc_server/svcctl/srv_svcctl_reg.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/source3/rpc_server/svcctl/srv_svcctl_reg.c b/source3/rpc_server/svcctl/srv_svcctl_reg.c
index 9b1af800b9d..1aa22a58be6 100644
--- a/source3/rpc_server/svcctl/srv_svcctl_reg.c
+++ b/source3/rpc_server/svcctl/srv_svcctl_reg.c
@@ -31,7 +31,6 @@
#include "rpc_server/svcctl/srv_svcctl_reg.h"
#include "auth.h"
#include "registry/reg_backend_db.h"
-#include "lib/util/xfile.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_REGISTRY
@@ -188,7 +187,7 @@ static bool read_init_file(TALLOC_CTX *mem_ctx,
struct rcinit_file_information *info = NULL;
char *filepath = NULL;
char str[1024];
- XFILE *f = NULL;
+ FILE *f = NULL;
char *p = NULL;
info = talloc_zero(mem_ctx, struct rcinit_file_information);
@@ -206,13 +205,13 @@ static bool read_init_file(TALLOC_CTX *mem_ctx,
if (filepath == NULL) {
return false;
}
- f = x_fopen( filepath, O_RDONLY, 0 );
+ f = fopen( filepath, "r" );
if (f == NULL) {
DEBUG(0,("read_init_file: failed to open [%s]\n", filepath));
return false;
}
- while ((x_fgets(str, sizeof(str) - 1, f)) != NULL) {
+ while ((fgets(str, sizeof(str) - 1, f)) != NULL) {
/* ignore everything that is not a full line
comment starting with a '#' */
@@ -238,7 +237,7 @@ static bool read_init_file(TALLOC_CTX *mem_ctx,
}
}
- x_fclose(f);
+ fclose(f);
if (info->description == NULL) {
info->description = talloc_strdup(info,
--
2.11.0
>From c2a689b35b3558d5cfbae0c4f19678bfbb6d73db Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 26 Nov 2016 09:27:19 +0100
Subject: [PATCH 11/16] printing: std_pcap_cache_reload xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/printing/print_standard.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/source3/printing/print_standard.c b/source3/printing/print_standard.c
index 4404aeb681d..7cbdac7b257 100644
--- a/source3/printing/print_standard.c
+++ b/source3/printing/print_standard.c
@@ -57,31 +57,32 @@
#include "includes.h"
#include "system/filesys.h"
#include "printing/pcap.h"
-#include "lib/util/xfile.h"
/* handle standard printcap - moved from pcap_printer_fn() */
bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
{
TALLOC_CTX *frame = talloc_stackframe();
- XFILE *pcap_file;
+ FILE *pcap_file;
char *pcap_line;
struct pcap_cache *pcache = NULL;
bool print_warning = false;
- if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) {
+ if ((pcap_file = fopen(pcap_name, "r")) == NULL) {
DEBUG(0, ("Unable to open printcap file %s for read!\n", pcap_name));
talloc_free(frame);
return false;
}
- for (; (pcap_line = x_fgets_slash(NULL, 1024, pcap_file)) != NULL;
- free(pcap_line)) {
+ while ((pcap_line = fgets_slash(frame, NULL, 1024,
+ pcap_file)) != NULL) {
char *name = NULL;
char *comment = NULL;
char *p, *q;
- if (*pcap_line == '#' || *pcap_line == 0)
+ if (*pcap_line == '#' || *pcap_line == 0) {
+ TALLOC_FREE(pcap_line);
continue;
+ }
/* now we have a real printer line - cut at the first : */
if ((p = strchr_m(pcap_line, ':')) != NULL)
@@ -108,11 +109,13 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
if (name == NULL && !has_punctuation) {
name = talloc_strdup(frame, p);
+ TALLOC_FREE(pcap_line);
continue;
}
if (has_punctuation) {
comment = talloc_strdup(frame, p);
+ TALLOC_FREE(pcap_line);
continue;
}
}
@@ -129,7 +132,7 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
comment,
NULL);
if (!ok) {
- x_fclose(pcap_file);
+ fclose(pcap_file);
pcap_cache_destroy_specific(&pcache);
talloc_free(frame);
return false;
@@ -137,6 +140,7 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
}
TALLOC_FREE(name);
TALLOC_FREE(comment);
+ TALLOC_FREE(pcap_line);
}
if (print_warning) {
@@ -146,7 +150,7 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
(unsigned int)MAXPRINTERLEN);
}
- x_fclose(pcap_file);
+ fclose(pcap_file);
*_pcache = pcache;
talloc_free(frame);
return true;
--
2.11.0
>From 0126bc79c8352fa73c2dd65e5e50dc46873341d1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 26 Nov 2016 15:33:06 +0100
Subject: [PATCH 12/16] printing: Convert aix_cache_reload to stdio
---
source3/printing/print_aix.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/source3/printing/print_aix.c b/source3/printing/print_aix.c
index 7b5a1e3881c..d3836a43568 100644
--- a/source3/printing/print_aix.c
+++ b/source3/printing/print_aix.c
@@ -27,13 +27,12 @@
#include "includes.h"
#include "system/filesys.h"
#include "printing/pcap.h"
-#include "lib/util/xfile.h"
#ifdef AIX
bool aix_cache_reload(struct pcap_cache **_pcache)
{
int iEtat;
- XFILE *pfile;
+ FILE *pfile;
char *line = NULL, *p;
char *name = NULL;
struct pcap_cache *pcache = NULL;
@@ -45,7 +44,7 @@ bool aix_cache_reload(struct pcap_cache **_pcache)
DEBUG(5, ("reloading aix printcap cache\n"));
- if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
+ if ((pfile = fopen(lp_printcapname(), "r")) == NULL) {
DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
TALLOC_FREE(ctx);
return false;
@@ -53,16 +52,20 @@ bool aix_cache_reload(struct pcap_cache **_pcache)
iEtat = 0;
/* scan qconfig file for searching <printername>: */
- for (;(line = x_fgets_slash(NULL, 1024, pfile)); free(line)) {
+ while (line = fgets_slash(ctx, NULL, 1024, pfile)) {
bool ok;
- if (*line == '*' || *line == 0)
+ if (*line == '*' || *line == 0) {
+ TALLOC_FREE(line);
continue;
+ }
switch (iEtat) {
case 0: /* locate an entry */
- if (*line == '\t' || *line == ' ')
+ if (*line == '\t' || *line == ' ') {
+ TALLOC_FREE(line);
continue;
+ }
if ((p = strchr_m(line, ':'))) {
char *saveptr;
@@ -72,8 +75,8 @@ bool aix_cache_reload(struct pcap_cache **_pcache)
name = talloc_strdup(ctx, p);
if (!name) {
pcap_cache_destroy_specific(&pcache);
- SAFE_FREE(line);
- x_fclose(pfile);
+ TALLOC_FREE(line);
+ fclose(pfile);
TALLOC_FREE(ctx);
return false;
}
@@ -95,8 +98,8 @@ bool aix_cache_reload(struct pcap_cache **_pcache)
name, NULL, NULL);
if (!ok) {
pcap_cache_destroy_specific(&pcache);
- SAFE_FREE(line);
- x_fclose(pfile);
+ TALLOC_FREE(line);
+ fclose(pfile);
TALLOC_FREE(ctx);
return false;
}
@@ -114,7 +117,7 @@ bool aix_cache_reload(struct pcap_cache **_pcache)
if (!ok) {
pcap_cache_destroy_specific(&pcache);
SAFE_FREE(line);
- x_fclose(pfile);
+ fclose(pfile);
TALLOC_FREE(ctx);
return false;
}
@@ -125,7 +128,7 @@ bool aix_cache_reload(struct pcap_cache **_pcache)
}
*_pcache = pcache;
- x_fclose(pfile);
+ fclose(pfile);
TALLOC_FREE(ctx);
return true;
}
--
2.11.0
>From 4d634e018572cf49489a723b11f9b26a99b541b3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 23 Nov 2016 08:55:16 +0100
Subject: [PATCH 13/16] libnbt: lmhosts xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
libcli/nbt/libnbt.h | 9 ++++-----
libcli/nbt/lmhosts.c | 19 +++++++++----------
source3/nmbd/nmbd_lmhosts.c | 2 +-
3 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h
index fd0c7fea66d..d4813b96165 100644
--- a/libcli/nbt/libnbt.h
+++ b/libcli/nbt/libnbt.h
@@ -24,7 +24,6 @@
#include "librpc/gen_ndr/nbt.h"
#include "librpc/ndr/libndr.h"
-#include "lib/util/xfile.h"
/*
possible states for pending requests
@@ -361,10 +360,10 @@ NTSTATUS nbt_name_refresh_wins_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
struct nbt_name_refresh_wins *io);
-XFILE *startlmhosts(const char *fname);
-bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
- struct sockaddr_storage *pss);
-void endlmhosts(XFILE *fp);
+FILE *startlmhosts(const char *fname);
+bool getlmhostsent(TALLOC_CTX *ctx, FILE *fp, char **pp_name, int *name_type,
+ struct sockaddr_storage *pss);
+void endlmhosts(FILE *fp);
NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
const char *name, int name_type,
diff --git a/libcli/nbt/lmhosts.c b/libcli/nbt/lmhosts.c
index e68dc08d1e5..722f6adc63d 100644
--- a/libcli/nbt/lmhosts.c
+++ b/libcli/nbt/lmhosts.c
@@ -22,7 +22,6 @@
*/
#include "includes.h"
-#include "lib/util/xfile.h"
#include "lib/util/util_net.h"
#include "system/filesys.h"
#include "system/network.h"
@@ -32,9 +31,9 @@
Start parsing the lmhosts file.
*********************************************************/
-XFILE *startlmhosts(const char *fname)
+FILE *startlmhosts(const char *fname)
{
- XFILE *fp = x_fopen(fname,O_RDONLY, 0);
+ FILE *fp = fopen(fname, "r");
if (!fp) {
DEBUG(4,("startlmhosts: Can't open lmhosts file %s. "
"Error was %s\n",
@@ -48,14 +47,14 @@ XFILE *startlmhosts(const char *fname)
Parse the next line in the lmhosts file.
*********************************************************/
-bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
- struct sockaddr_storage *pss)
+bool getlmhostsent(TALLOC_CTX *ctx, FILE *fp, char **pp_name, int *name_type,
+ struct sockaddr_storage *pss)
{
char line[1024];
*pp_name = NULL;
- while(!x_feof(fp) && !x_ferror(fp)) {
+ while(!feof(fp) && !ferror(fp)) {
char *ip = NULL;
char *flags = NULL;
char *extra = NULL;
@@ -66,7 +65,7 @@ bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
*name_type = -1;
- if (!x_fgets_slash(line,sizeof(line),fp)) {
+ if (!fgets_slash(NULL,line,sizeof(line),fp)) {
continue;
}
@@ -151,9 +150,9 @@ bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
Finish parsing the lmhosts file.
*********************************************************/
-void endlmhosts(XFILE *fp)
+void endlmhosts(FILE *fp)
{
- x_fclose(fp);
+ fclose(fp);
}
/********************************************************
@@ -170,7 +169,7 @@ NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
* "lmhosts" means parse the local lmhosts file.
*/
- XFILE *fp;
+ FILE *fp;
char *lmhost_name = NULL;
int name_type2;
struct sockaddr_storage return_ss;
diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c
index 80d89930fd4..042d0430a35 100644
--- a/source3/nmbd/nmbd_lmhosts.c
+++ b/source3/nmbd/nmbd_lmhosts.c
@@ -36,7 +36,7 @@ void load_lmhosts_file(const char *fname)
int name_type;
struct sockaddr_storage ss;
TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
- XFILE *fp = startlmhosts( fname );
+ FILE *fp = startlmhosts( fname );
if (!fp) {
DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
--
2.11.0
>From 086a53653d2079df86b4c15152e7c6babc69e765 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 23 Nov 2016 10:07:48 +0100
Subject: [PATCH 14/16] lib: smbreadline xfile->stdio
Signed-off-by: Volker Lendecke <vl at samba.org>
---
libcli/smbreadline/smbreadline.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libcli/smbreadline/smbreadline.c b/libcli/smbreadline/smbreadline.c
index 8be6e4855f7..1a0f61c2cfe 100644
--- a/libcli/smbreadline/smbreadline.c
+++ b/libcli/smbreadline/smbreadline.c
@@ -24,7 +24,6 @@
#include "system/select.h"
#include "system/readline.h"
#include "libcli/smbreadline/smbreadline.h"
-#include "lib/util/xfile.h"
#undef malloc
@@ -72,13 +71,13 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
char **(completion_fn)(const char *text, int start, int end))
{
char *line = NULL;
- int fd = x_fileno(x_stdin);
+ int fd = fileno(stdin);
char *ret;
/* Prompt might be NULL in non-interactive mode. */
if (prompt) {
- x_fprintf(x_stdout, "%s", prompt);
- x_fflush(x_stdout);
+ printf("%s", prompt);
+ fflush(stdout);
}
line = (char *)malloc(BUFSIZ);
@@ -94,7 +93,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
pfd.events = POLLIN|POLLHUP;
if (sys_poll_intr(&pfd, 1, 5000) == 1) {
- ret = x_fgets(line, BUFSIZ, x_stdin);
+ ret = fgets(line, BUFSIZ, stdin);
if (ret == 0) {
SAFE_FREE(line);
}
@@ -118,7 +117,7 @@ char *smb_readline(const char *prompt, void (*callback)(void),
char *ret;
bool interactive;
- interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE");
+ interactive = isatty(fileno(stdin)) || getenv("CLI_FORCE_INTERACTIVE");
if (!interactive) {
return smb_readline_replacement(NULL, callback, completion_fn);
}
--
2.11.0
>From aa35b7a46a223212e7ad0344ba85e2e91a92349c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 26 Nov 2016 09:50:33 +0100
Subject: [PATCH 15/16] 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 at samba.org>
---
source3/nmbd/nmbd.h | 1 -
source3/nmbd/nmbd_namelistdb.c | 45 +++++++++++++++++++++---------------
source3/nmbd/nmbd_proto.h | 8 +++----
source3/nmbd/nmbd_serverlistdb.c | 32 +++++++++++++++++---------
source3/nmbd/nmbd_synclists.c | 25 ++++++++++++--------
source3/nmbd/nmbd_winsserver.c | 49 ++++++++++++++++++++++++----------------
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 1c2b04d1656..4a0f9fc20a7 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);
--
2.11.0
>From 11478ba9cb33e8305f79b99c1593654a6c983e2f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 26 Nov 2016 15:42:42 +0100
Subject: [PATCH 16/16] lib: Remove xfile
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/util/wscript_build | 4 +-
lib/util/xfile.c | 524 -------------------------------------------------
lib/util/xfile.h | 114 -----------
3 files changed, 2 insertions(+), 640 deletions(-)
delete mode 100644 lib/util/xfile.c
delete mode 100644 lib/util/xfile.h
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 0a911a2a84f..27d0a55c387 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -68,7 +68,7 @@ bld.SAMBA_LIBRARY('talloc_report',
)
bld.SAMBA_SUBSYSTEM('samba-util-core',
- source='''xfile.c data_blob.c util_file.c time.c
+ source='''data_blob.c util_file.c time.c
signal.c util.c idtree.c fault.c
substitute.c util_process.c util_strlist.c
strv_util.c''',
@@ -123,7 +123,7 @@ else:
tevent_debug.c memcache.c unix_match.c''',
deps='samba-util-core DYNCONFIG close-low-fd tini tiniparser genrand',
public_deps='talloc tevent execinfo pthread LIBCRYPTO charset util_setid systemd systemd-daemon',
- public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h string_wrappers.h idtree.h idtree_random.h blocking.h signal.h substitute.h fault.h genrand.h',
+ public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h string_wrappers.h idtree.h idtree_random.h blocking.h signal.h substitute.h fault.h genrand.h',
header_path= [ ('dlinklist.h samba_util.h', '.'), ('*', 'util') ],
local_include=False,
vnum='0.0.1',
diff --git a/lib/util/xfile.c b/lib/util/xfile.c
deleted file mode 100644
index b22cb9871f2..00000000000
--- a/lib/util/xfile.c
+++ /dev/null
@@ -1,524 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- stdio replacement
- Copyright (C) Andrew Tridgell 2001
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file
- * @brief scalable FILE replacement
- */
-
-/*
- stdio is very convenient, but on some systems the file descriptor
- in FILE* is 8 bits, so it fails when more than 255 files are open.
-
- XFILE replaces stdio. It is less efficient, but at least it works
- when you have lots of files open
-
- The main restriction on XFILE is that it doesn't support seeking,
- and doesn't support O_RDWR. That keeps the code simple.
-*/
-
-#include "replace.h"
-#include "system/filesys.h"
-#include "memory.h"
-#include "xfile.h"
-#include "lib/util/debug.h"
-#include "lib/util/samba_util.h"
-
-#define XBUFSIZE BUFSIZ
-
-static XFILE _x_stdin = { 0, NULL, NULL, XBUFSIZE, 0, O_RDONLY, X_IOFBF, 0 };
-static XFILE _x_stdout = { 1, NULL, NULL, XBUFSIZE, 0, O_WRONLY, X_IOLBF, 0 };
-static XFILE _x_stderr = { 2, NULL, NULL, 0, 0, O_WRONLY, X_IONBF, 0 };
-
-XFILE *x_stdin = &_x_stdin;
-XFILE *x_stdout = &_x_stdout;
-XFILE *x_stderr = &_x_stderr;
-
-#define X_FLAG_EOF 1
-#define X_FLAG_ERROR 2
-#define X_FLAG_EINVAL 3
-
-/** simulate setvbuf() */
-int x_setvbuf(XFILE *f, char *buf, int mode, size_t size)
-{
- x_fflush(f);
- if (f->bufused) return -1;
-
- /* on files being read full buffering is the only option */
- if ((f->open_flags & O_ACCMODE) == O_RDONLY) {
- mode = X_IOFBF;
- }
-
- /* destroy any earlier buffer */
- SAFE_FREE(f->buf);
- f->buf = 0;
- f->bufsize = 0;
- f->next = NULL;
- f->bufused = 0;
- f->buftype = mode;
-
- if (f->buftype == X_IONBF) return 0;
-
- /* if buffering then we need some size */
- if (size == 0) size = XBUFSIZE;
-
- f->bufsize = size;
- f->bufused = 0;
-
- return 0;
-}
-
-/* allocate the buffer */
-static int x_allocate_buffer(XFILE *f)
-{
- if (f->buf) return 1;
- if (f->bufsize == 0) return 0;
- f->buf = (char *)malloc(f->bufsize);
- if (!f->buf) return 0;
- f->next = f->buf;
- return 1;
-}
-
-
-/** this looks more like open() than fopen(), but that is quite deliberate.
- I want programmers to *think* about O_EXCL, O_CREAT etc not just
- get them magically added
-*/
-XFILE *x_fopen(const char *fname, int flags, mode_t mode)
-{
- XFILE *ret;
-
- ret = (XFILE *)malloc_p(XFILE);
- if (!ret) return NULL;
-
- memset(ret, 0, sizeof(XFILE));
-
- if ((flags & O_ACCMODE) == O_RDWR) {
- /* we don't support RDWR in XFILE - use file
- descriptors instead */
- SAFE_FREE(ret);
- errno = EINVAL;
- return NULL;
- }
-
- ret->open_flags = flags;
-
- ret->fd = open(fname, flags, mode);
- if (ret->fd == -1) {
- SAFE_FREE(ret);
- return NULL;
- }
-
- x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
-
- return ret;
-}
-
-/** simulate fclose() */
-int x_fclose(XFILE *f)
-{
- int ret;
-
- /* make sure we flush any buffered data */
- x_fflush(f);
-
- ret = close(f->fd);
- f->fd = -1;
- if (f->buf) {
- /* make sure data can't leak into a later malloc */
- memset(f->buf, 0, f->bufsize);
- SAFE_FREE(f->buf);
- }
- /* check the file descriptor given to the function is NOT one of the static
- * descriptor of this libreary or we will free unallocated memory
- * --sss */
- if (f != x_stdin && f != x_stdout && f != x_stderr) {
- SAFE_FREE(f);
- }
- return ret;
-}
-
-/** simulate fwrite() */
-size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f)
-{
- ssize_t ret;
- size_t total=0;
-
- /* we might be writing unbuffered */
- if (f->buftype == X_IONBF ||
- (!f->buf && !x_allocate_buffer(f))) {
- ret = write(f->fd, p, size*nmemb);
- if (ret == -1) return -1;
- return ret/size;
- }
-
-
- while (total < size*nmemb) {
- size_t n = f->bufsize - f->bufused;
- n = MIN(n, (size*nmemb)-total);
-
- if (n == 0) {
- /* it's full, flush it */
- x_fflush(f);
- continue;
- }
-
- memcpy(f->buf + f->bufused, total+(const char *)p, n);
- f->bufused += n;
- total += n;
- }
-
- /* when line buffered we need to flush at the last linefeed. This can
- flush a bit more than necessary, but that is harmless */
- if (f->buftype == X_IOLBF && f->bufused) {
- int i;
- for (i=(size*nmemb)-1; i>=0; i--) {
- if (*(i+(const char *)p) == '\n') {
- x_fflush(f);
- break;
- }
- }
- }
-
- return total/size;
-}
-
-/** thank goodness for asprintf() */
- int x_vfprintf(XFILE *f, const char *format, va_list ap)
-{
- char *p;
- int len, ret;
- va_list ap2;
-
- va_copy(ap2, ap);
- len = vasprintf(&p, format, ap2);
- va_end(ap2);
- if (len <= 0) return len;
- ret = x_fwrite(p, 1, len, f);
- SAFE_FREE(p);
- return ret;
-}
-
- int x_fprintf(XFILE *f, const char *format, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, format);
- ret = x_vfprintf(f, format, ap);
- va_end(ap);
- return ret;
-}
-
-/* at least fileno() is simple! */
-int x_fileno(const XFILE *f)
-{
- return f->fd;
-}
-
-/** simulate fflush() */
-int x_fflush(XFILE *f)
-{
- int ret;
-
- if (f->flags & X_FLAG_ERROR) return -1;
-
- if ((f->open_flags & O_ACCMODE) != O_WRONLY) {
- errno = EINVAL;
- return -1;
- }
-
- if (f->bufused == 0) return 0;
-
- ret = write(f->fd, f->buf, f->bufused);
- if (ret == -1) return -1;
-
- f->bufused -= ret;
- if (f->bufused > 0) {
- f->flags |= X_FLAG_ERROR;
- memmove(f->buf, ret + (char *)f->buf, f->bufused);
- return -1;
- }
-
- return 0;
-}
-
-/** simulate setbuffer() */
-void x_setbuffer(XFILE *f, char *buf, size_t size)
-{
- x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, size);
-}
-
-/** simulate setbuf() */
-void x_setbuf(XFILE *f, char *buf)
-{
- x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, XBUFSIZE);
-}
-
-/** simulate setlinebuf() */
-void x_setlinebuf(XFILE *f)
-{
- x_setvbuf(f, NULL, X_IOLBF, 0);
-}
-
-
-/** simulate feof() */
-int x_feof(XFILE *f)
-{
- if (f->flags & X_FLAG_EOF) return 1;
- return 0;
-}
-
-/** simulate ferror() */
-int x_ferror(XFILE *f)
-{
- if (f->flags & X_FLAG_ERROR) return 1;
- return 0;
-}
-
-/* fill the read buffer */
-static void x_fillbuf(XFILE *f)
-{
- int n;
-
- if (f->bufused) return;
-
- if (!f->buf && !x_allocate_buffer(f)) return;
-
- n = read(f->fd, f->buf, f->bufsize);
- if (n <= 0) return;
- f->bufused = n;
- f->next = f->buf;
-}
-
-/** simulate fgetc() */
-int x_fgetc(XFILE *f)
-{
- int ret;
-
- if (f->flags & (X_FLAG_EOF | X_FLAG_ERROR)) return EOF;
-
- if (f->bufused == 0) x_fillbuf(f);
-
- if (f->bufused == 0) {
- f->flags |= X_FLAG_EOF;
- return EOF;
- }
-
- ret = *(uint8_t *)(f->next);
- f->next++;
- f->bufused--;
- return ret;
-}
-
-/** simulate fread */
-size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f)
-{
- size_t remaining = size * nmemb;
- size_t total = 0;
-
- while (remaining > 0) {
- size_t thistime;
-
- x_fillbuf(f);
-
- if (f->bufused == 0) {
- f->flags |= X_FLAG_EOF;
- break;
- }
-
- thistime = MIN(f->bufused, remaining);
-
- memcpy((char *)p+total, f->next, thistime);
-
- f->next += thistime;
- f->bufused -= thistime;
- remaining -= thistime;
- total += thistime;
- }
- return total/size;
-}
-
-/** simulate fgets() */
-char *x_fgets(char *s, int size, XFILE *stream)
-{
- char *s0 = s;
- int l = size;
- while (l>1) {
- int c = x_fgetc(stream);
- if (c == EOF) break;
- *s++ = (char)c;
- l--;
- if (c == '\n') break;
- }
- if (l==size || x_ferror(stream)) {
- return 0;
- }
- *s = 0;
- return s0;
-}
-
-/**
- * trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is
- * set then an error is returned */
-off_t x_tseek(XFILE *f, off_t offset, int whence)
-{
- if (f->flags & X_FLAG_ERROR)
- return -1;
-
- /* only SEEK_SET and SEEK_END are supported */
- /* SEEK_CUR needs internal offset counter */
- if (whence != SEEK_SET && whence != SEEK_END) {
- f->flags |= X_FLAG_EINVAL;
- errno = EINVAL;
- return -1;
- }
-
- /* empty the buffer */
- switch (f->open_flags & O_ACCMODE) {
- case O_RDONLY:
- f->bufused = 0;
- break;
- case O_WRONLY:
- if (x_fflush(f) != 0)
- return -1;
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- f->flags &= ~X_FLAG_EOF;
- return lseek(f->fd, offset, whence);
-}
-
-XFILE *x_fdup(const XFILE *f)
-{
- XFILE *ret;
- int fd;
-
- fd = dup(x_fileno(f));
- if (fd < 0) {
- return NULL;
- }
-
- ret = (XFILE *)malloc_p(XFILE);
- if (!ret) {
- close(fd);
- return NULL;
- }
- memset(ret, 0, sizeof(XFILE));
-
- ret->fd = fd;
- ret->open_flags = f->open_flags;
- x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
- return ret;
-}
-
-/**
- * @file
- * @brief File-related utility functions
- */
-
-/**
-read a line from a file with possible \ continuation chars.
-Blanks at the start or end of a line are stripped.
-The string will be allocated if s2 is NULL
-**/
-char *x_fgets_slash(char *s2,int maxlen,XFILE *f)
-{
- char *s=s2;
- int len = 0;
- int c;
- bool start_of_line = true;
-
- if (x_feof(f)) {
- return(NULL);
- }
-
- if (maxlen <2) {
- return(NULL);
- }
-
- if (!s2) {
- maxlen = MIN(maxlen,8);
- s = (char *)malloc(maxlen);
- }
-
- if (!s) {
- return(NULL);
- }
-
- *s = 0;
-
- while (len < maxlen-1) {
- c = x_getc(f);
- switch (c)
- {
- case '\r':
- break;
- case '\n':
- while (len > 0 && s[len-1] == ' ') {
- s[--len] = 0;
- }
- if (len > 0 && s[len-1] == '\\') {
- s[--len] = 0;
- start_of_line = true;
- break;
- }
- return(s);
- case EOF:
- if (len <= 0 && !s2) {
- SAFE_FREE(s);
- }
- return(len>0?s:NULL);
- case ' ':
- if (start_of_line) {
- break;
- }
- /* fall through */
- default:
- start_of_line = false;
- s[len++] = c;
- s[len] = 0;
- }
- if (!s2 && len > maxlen-3) {
- int m;
- char *t;
-
- m = maxlen * 2;
- if (m < maxlen) {
- DBG_ERR("length overflow");
- SAFE_FREE(s);
- return NULL;
- }
- maxlen = m;
-
- t = realloc_p(s, char, maxlen);
- if (!t) {
- DBG_ERR("failed to expand buffer!\n");
- SAFE_FREE(s);
- return(NULL);
- }
-
- s = t;
- }
- }
- return(s);
-}
diff --git a/lib/util/xfile.h b/lib/util/xfile.h
deleted file mode 100644
index 5fb6341dfc7..00000000000
--- a/lib/util/xfile.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- stdio replacement
- Copyright (C) Andrew Tridgell 2001
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _XFILE_H_
-#define _XFILE_H_
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <sys/stat.h>
-#include "attr.h"
-
-/*
- see xfile.c for explanations
-*/
-
-typedef struct _XFILE {
- int fd;
- char *buf;
- char *next;
- int bufsize;
- int bufused;
- int open_flags;
- int buftype;
- int flags;
-} XFILE;
-
-extern XFILE *x_stdin, *x_stdout, *x_stderr;
-
-/* buffering type */
-#define X_IOFBF 0
-#define X_IOLBF 1
-#define X_IONBF 2
-
-#define x_getc(f) x_fgetc(f)
-
-int x_vfprintf(XFILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2, 0);
-int x_fprintf(XFILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
-
-/** simulate setvbuf() */
-int x_setvbuf(XFILE *f, char *buf, int mode, size_t size);
-
-/** this looks more like open() than fopen(), but that is quite deliberate.
- I want programmers to *think* about O_EXCL, O_CREAT etc not just
- get them magically added
-*/
-XFILE *x_fopen(const char *fname, int flags, mode_t mode);
-
-/** simulate fclose() */
-int x_fclose(XFILE *f);
-
-/** simulate fwrite() */
-size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f);
-
-/** thank goodness for asprintf() */
-int x_fileno(const XFILE *f);
-
-/** simulate fflush() */
-int x_fflush(XFILE *f);
-
-/** simulate setbuffer() */
-void x_setbuffer(XFILE *f, char *buf, size_t size);
-
-/** simulate setbuf() */
-void x_setbuf(XFILE *f, char *buf);
-
-/** simulate setlinebuf() */
-void x_setlinebuf(XFILE *f);
-
-/** simulate feof() */
-int x_feof(XFILE *f);
-
-/** simulate ferror() */
-int x_ferror(XFILE *f);
-
-/** simulate fgetc() */
-int x_fgetc(XFILE *f);
-
-/** simulate fread */
-size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f);
-
-/** simulate fgets() */
-char *x_fgets(char *s, int size, XFILE *stream) ;
-
-/**
- * trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is
- * set then an error is returned */
-off_t x_tseek(XFILE *f, off_t offset, int whence);
-
-XFILE *x_fdup(const XFILE *f);
-
-/**
-read a line from a file with possible \ continuation chars.
-Blanks at the start or end of a line are stripped.
-The string will be allocated if s2 is NULL
-**/
-_PUBLIC_ char *x_fgets_slash(char *s2,int maxlen,XFILE *f);
-
-#endif /* _XFILE_H_ */
--
2.11.0
More information about the samba-technical
mailing list