summaryrefslogtreecommitdiff
path: root/source3/lib/popt_common.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-11-15 14:19:52 -0800
committerJeremy Allison <jra@samba.org>2007-11-15 14:19:52 -0800
commit68be9a820059ee96dd26c527efd7c14e679d3f2c (patch)
treec3c853a01013fc7977ab02a31e673fe17b4135e6 /source3/lib/popt_common.c
parent8e1b0f81c27dc332560f19de27fb86ac96c59775 (diff)
downloadsamba-68be9a820059ee96dd26c527efd7c14e679d3f2c.tar.gz
samba-68be9a820059ee96dd26c527efd7c14e679d3f2c.tar.bz2
samba-68be9a820059ee96dd26c527efd7c14e679d3f2c.zip
More pstring removal. This one was tricky. I had to add
one horror (pstring_clean_name()) which will have to remain until I've removed all pstrings from the client code. Jeremy. (This used to be commit 1ea3ac80146b83c2522b69e7747c823366a2b47d)
Diffstat (limited to 'source3/lib/popt_common.c')
-rw-r--r--source3/lib/popt_common.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 7cc066d667..dbb66b0ba5 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -41,19 +41,22 @@ struct user_auth_info cmdline_auth_info;
static void set_logfile(poptContext con, const char * arg)
{
- pstring logfile;
+ char *logfile = NULL;
const char *pname;
-
+
/* Find out basename of current program */
pname = strrchr_m(poptGetInvocationName(con),'/');
if (!pname)
pname = poptGetInvocationName(con);
- else
+ else
pname++;
- pstr_sprintf(logfile, "%s/log.%s", arg, pname);
+ if (asprintf(&logfile, "%s/log.%s", arg, pname) < 0) {
+ return;
+ }
lp_set_logfile(logfile);
+ SAFE_FREE(logfile);
}
static bool PrintSambaVersionString;
@@ -285,22 +288,24 @@ const struct poptOption popt_common_dynconfig[] = {
* get a password from a a file or file descriptor
* exit on failure
* ****************************************************************************/
+
static void get_password_file(struct user_auth_info *a)
{
int fd = -1;
char *p;
bool close_it = False;
- pstring spec;
+ char *spec = NULL;
char pass[128];
if ((p = getenv("PASSWD_FD")) != NULL) {
- pstrcpy(spec, "descriptor ");
- pstrcat(spec, p);
+ if (asprintf(&spec, "descriptor %s", p) < 0) {
+ return;
+ }
sscanf(p, "%d", &fd);
- close_it = False;
+ close_it = false;
} else if ((p = getenv("PASSWD_FILE")) != NULL) {
fd = sys_open(p, O_RDONLY, 0);
- pstrcpy(spec, p);
+ spec = SMB_STRDUP(p);
if (fd < 0) {
fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n",
spec, strerror(errno));
@@ -325,15 +330,18 @@ static void get_password_file(struct user_auth_info *a)
} else {
fprintf(stderr, "Error reading password from file %s: %s\n",
spec, "empty password\n");
+ SAFE_FREE(spec);
exit(1);
}
default:
fprintf(stderr, "Error reading password from file %s: %s\n",
spec, strerror(errno));
+ SAFE_FREE(spec);
exit(1);
}
}
+ SAFE_FREE(spec);
pstrcpy(a->password, pass);
if (close_it)
close(fd);