summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-12-31 18:06:57 -0800
committerJeremy Allison <jra@samba.org>2008-12-31 18:06:57 -0800
commit07e0094365e8dc360a83eec2e7cf9b1d5d8d6d00 (patch)
tree412f448d68b4b0f36c5b330a1f3eef77acf12a2f /source3/utils
parentbb23f5725f538d14b2ccec0463cfb1136be3ebd0 (diff)
downloadsamba-07e0094365e8dc360a83eec2e7cf9b1d5d8d6d00.tar.gz
samba-07e0094365e8dc360a83eec2e7cf9b1d5d8d6d00.tar.bz2
samba-07e0094365e8dc360a83eec2e7cf9b1d5d8d6d00.zip
Fix all warnings in source3 with gcc4.3.
Jeremy.
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/eventlogadm.c4
-rw-r--r--source3/utils/net_ads.c35
-rw-r--r--source3/utils/net_cache.c5
-rw-r--r--source3/utils/net_lookup.c8
-rw-r--r--source3/utils/net_rpc.c8
-rw-r--r--source3/utils/net_time.c4
-rw-r--r--source3/utils/net_util.c3
-rw-r--r--source3/utils/profiles.c2
-rw-r--r--source3/utils/smbget.c28
9 files changed, 72 insertions, 25 deletions
diff --git a/source3/utils/eventlogadm.c b/source3/utils/eventlogadm.c
index 1b38a7b13b..5fed4d1a39 100644
--- a/source3/utils/eventlogadm.c
+++ b/source3/utils/eventlogadm.c
@@ -111,7 +111,9 @@ static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename
ZERO_STRUCT( ee ); /* MUST initialize between records */
while ( !feof( f1 ) ) {
- fgets( linein, sizeof( linein ) - 1, f1 );
+ if (fgets( linein, sizeof( linein ) - 1, f1 ) == NULL) {
+ break;
+ }
linein[strlen( linein ) - 1] = 0; /* whack the line delimiter */
if ( debugflag )
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
index 27d534665c..766f3216f0 100644
--- a/source3/utils/net_ads.c
+++ b/source3/utils/net_ads.c
@@ -478,7 +478,9 @@ static int ads_user_add(struct net_context *c, int argc, const char **argv)
}
/* try setting the password */
- asprintf(&upn, "%s@%s", argv[0], ads->config.realm);
+ if (asprintf(&upn, "%s@%s", argv[0], ads->config.realm) == -1) {
+ goto done;
+ }
status = ads_krb5_set_password(ads->auth.kdc_server, upn, argv[1],
ads->auth.time_offset);
SAFE_FREE(upn);
@@ -533,7 +535,10 @@ static int ads_user_info(struct net_context *c, int argc, const char **argv)
return -1;
}
- asprintf(&searchstring, "(sAMAccountName=%s)", escaped_user);
+ if (asprintf(&searchstring, "(sAMAccountName=%s)", escaped_user) == -1) {
+ SAFE_FREE(escaped_user);
+ return -1;
+ }
rc = ads_search(ads, &res, searchstring, attrs);
SAFE_FREE(searchstring);
@@ -1297,7 +1302,9 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
/* kinit with the machine password */
use_in_memory_ccache();
- asprintf( &ads_dns->auth.user_name, "%s$", global_myname() );
+ if (asprintf( &ads_dns->auth.user_name, "%s$", global_myname()) == -1) {
+ goto fail;
+ }
ads_dns->auth.password = secrets_fetch_machine_password(
r->out.netbios_domain_name, NULL, NULL );
ads_dns->auth.realm = SMB_STRDUP( r->out.dns_domain_name );
@@ -1636,7 +1643,14 @@ static int net_ads_printer_publish(struct net_context *c, int argc, const char *
return -1;
}
- asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, printername_escaped, srv_dn);
+ if (asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, printername_escaped, srv_dn) == -1) {
+ SAFE_FREE(srv_cn_escaped);
+ SAFE_FREE(printername_escaped);
+ d_fprintf(stderr, "Internal error, out of memory!");
+ ads_destroy(&ads);
+ talloc_destroy(mem_ctx);
+ return -1;
+ }
SAFE_FREE(srv_cn_escaped);
SAFE_FREE(printername_escaped);
@@ -1807,7 +1821,9 @@ static int net_ads_password(struct net_context *c, int argc, const char **argv)
user = argv[0];
if (!strchr_m(user, '@')) {
- asprintf(&chr, "%s@%s", argv[0], lp_realm());
+ if (asprintf(&chr, "%s@%s", argv[0], lp_realm()) == -1) {
+ return -1;
+ }
user = chr;
}
@@ -1837,7 +1853,9 @@ static int net_ads_password(struct net_context *c, int argc, const char **argv)
if (argv[1]) {
new_password = (char *)argv[1];
} else {
- asprintf(&prompt, "Enter new password for %s:", user);
+ if (asprintf(&prompt, "Enter new password for %s:", user) == -1) {
+ return -1;
+ }
new_password = getpass(prompt);
free(prompt);
}
@@ -1885,7 +1903,10 @@ int net_ads_changetrustpw(struct net_context *c, int argc, const char **argv)
fstrcpy(my_name, global_myname());
strlower_m(my_name);
- asprintf(&host_principal, "%s$@%s", my_name, ads->config.realm);
+ if (asprintf(&host_principal, "%s$@%s", my_name, ads->config.realm) == -1) {
+ ads_destroy(&ads);
+ return -1;
+ }
d_printf("Changing password for principal: %s\n", host_principal);
ret = ads_change_trust_account_password(ads, host_principal);
diff --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c
index 4e9ae18c0d..cabb6d5280 100644
--- a/source3/utils/net_cache.c
+++ b/source3/utils/net_cache.c
@@ -64,9 +64,8 @@ static void print_cache_entry(const char* keystr, const char* datastr,
}
timeout_str[strlen(timeout_str) - 1] = '\0'; /* remove tailing CR */
} else {
- asprintf(&alloc_str, "%.2d:%.2d:%.2d", timeout_tm.tm_hour,
- timeout_tm.tm_min, timeout_tm.tm_sec);
- if (!alloc_str) {
+ if (asprintf(&alloc_str, "%.2d:%.2d:%.2d", timeout_tm.tm_hour,
+ timeout_tm.tm_min, timeout_tm.tm_sec) == -1) {
return;
}
timeout_str = alloc_str;
diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 8b9ddb62ba..66f673b8d3 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -196,7 +196,9 @@ static int net_lookup_dc(struct net_context *c, int argc, const char **argv)
return -1;
print_sockaddr(addr, sizeof(addr), &ss);
- asprintf(&pdc_str, "%s", addr);
+ if (asprintf(&pdc_str, "%s", addr) == -1) {
+ return -1;
+ }
d_printf("%s\n", pdc_str);
sitename = sitename_fetch(domain);
@@ -237,7 +239,9 @@ static int net_lookup_pdc(struct net_context *c, int argc, const char **argv)
return -1;
print_sockaddr(addr, sizeof(addr), &ss);
- asprintf(&pdc_str, "%s", addr);
+ if (asprintf(&pdc_str, "%s", addr) == -1) {
+ return -1;
+ }
d_printf("%s\n", pdc_str);
SAFE_FREE(pdc_str);
return 0;
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index 5c83b590c1..e0d606c19a 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -749,7 +749,9 @@ static int rpc_user_password(struct net_context *c, int argc, const char **argv)
if (argv[1]) {
u1003.usri1003_password = argv[1];
} else {
- asprintf(&prompt, "Enter new password for %s:", argv[0]);
+ if (asprintf(&prompt, "Enter new password for %s:", argv[0]) == -1) {
+ return -1;
+ }
u1003.usri1003_password = getpass(prompt);
SAFE_FREE(prompt);
}
@@ -5533,7 +5535,9 @@ static int rpc_trustdom_establish(struct net_context *c, int argc,
strupper_m(domain_name);
/* account name used at first is our domain's name with '$' */
- asprintf(&acct_name, "%s$", lp_workgroup());
+ if (asprintf(&acct_name, "%s$", lp_workgroup()) == -1) {
+ return -1;
+ }
strupper_m(acct_name);
/*
diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c
index 8be9ed922c..b6198376af 100644
--- a/source3/utils/net_time.c
+++ b/source3/utils/net_time.c
@@ -116,7 +116,9 @@ static int net_time_set(struct net_context *c, int argc, const char **argv)
/* yes, I know this is cheesy. Use "net time system" if you want to
roll your own. I'm putting this in as it works on a large number
of systems and the user has a choice in whether its used or not */
- asprintf(&cmd, "/bin/date %s", systime(t));
+ if (asprintf(&cmd, "/bin/date %s", systime(t)) == -1) {
+ return -1;
+ }
result = system(cmd);
if (result)
d_fprintf(stderr, "%s failed. Error was (%s)\n",
diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
index 590a916522..7fbfdbab44 100644
--- a/source3/utils/net_util.c
+++ b/source3/utils/net_util.c
@@ -550,8 +550,7 @@ const char *net_prompt_pass(struct net_context *c, const char *user)
return NULL;
}
- asprintf(&prompt, "Enter %s's password:", user);
- if (!prompt) {
+ if (asprintf(&prompt, "Enter %s's password:", user) == -1) {
return NULL;
}
diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c
index 0b8a0d4278..5dd788ad5f 100644
--- a/source3/utils/profiles.c
+++ b/source3/utils/profiles.c
@@ -47,7 +47,7 @@ static void verbose_output(const char *format, ...)
return;
}
- fprintf(stdout, var);
+ fprintf(stdout, "%s", var);
va_end(args);
SAFE_FREE(var);
}
diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 3d4a71b71d..c062134a55 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -91,14 +91,18 @@ static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen,
if(!nonprompt && !username) {
printf("Username for %s at %s [guest] ", shr, srv);
- fgets(tmp, sizeof(tmp), stdin);
+ if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+ return;
+ }
if(tmp[strlen(tmp)-1] == '\n')tmp[strlen(tmp)-1] = '\0';
strncpy(un, tmp, unlen-1);
} else if(username) strncpy(un, username, unlen-1);
if(!nonprompt && !password) {
char *prompt, *pass;
- asprintf(&prompt, "Password for %s at %s: ", shr, srv);
+ if (asprintf(&prompt, "Password for %s at %s: ", shr, srv) == -1) {
+ return;
+ }
pass = getpass(prompt);
free(prompt);
strncpy(pw, pass, pwlen-1);
@@ -138,7 +142,9 @@ static int smb_download_dir(const char *base, const char *name, int resume)
while((dirent = smbc_readdir(dirhandle))) {
char *newname;
if(!strcmp(dirent->name, ".") || !strcmp(dirent->name, ".."))continue;
- asprintf(&newname, "%s/%s", tmpname, dirent->name);
+ if (asprintf(&newname, "%s/%s", tmpname, dirent->name) == -1) {
+ return 0;
+ }
switch(dirent->smbc_type) {
case SMBC_DIR:
smb_download_dir(base, newname, resume);
@@ -231,11 +237,19 @@ static void print_progress(const char *name, time_t start, time_t now, off_t sta
human_readable(avg, havg, sizeof(havg));
len = asprintf(&status, "%s of %s (%.2f%%) at %s/s ETA: %s", hpos, htotal, prcnt, havg, print_time(eta));
+ if (len == -1) {
+ return;
+ }
if(columns) {
int required = strlen(name), available = columns - len - strlen("[] ");
- if(required > available) asprintf(&filename, "...%s", name + required - available + 3);
- else filename = SMB_STRNDUP(name, available);
+ if(required > available) {
+ if (asprintf(&filename, "...%s", name + required - available + 3) == -1) {
+ return;
+ }
+ } else {
+ filename = SMB_STRNDUP(name, available);
+ }
} else filename = SMB_STRDUP(name);
fprintf(stderr, "\r[%s] %s", filename, status);
@@ -574,7 +588,9 @@ int main(int argc, const char **argv)
load_case_tables();
/* only read rcfile if it exists */
- asprintf(&rcfile, "%s/.smbgetrc", getenv("HOME"));
+ if (asprintf(&rcfile, "%s/.smbgetrc", getenv("HOME")) == -1) {
+ return 1;
+ }
if(access(rcfile, F_OK) == 0)
readrcfile(rcfile, long_options);
free(rcfile);