diff options
author | Jeremy Allison <jra@samba.org> | 2008-12-31 16:30:11 -0800 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2008-12-31 16:30:11 -0800 |
commit | bb23f5725f538d14b2ccec0463cfb1136be3ebd0 (patch) | |
tree | 392ffa5f6e85aa85ee05c7fbdd0dbeaee8aee5cc | |
parent | d99aeed50f1221561d8d935777216d372a2a4a71 (diff) | |
download | samba-bb23f5725f538d14b2ccec0463cfb1136be3ebd0.tar.gz samba-bb23f5725f538d14b2ccec0463cfb1136be3ebd0.tar.bz2 samba-bb23f5725f538d14b2ccec0463cfb1136be3ebd0.zip |
Fix more asprintf and "ignoring return code" warnings from gcc 4.3.
Jeremy.
-rw-r--r-- | source3/client/client.c | 60 | ||||
-rw-r--r-- | source3/libsmb/passchange.c | 78 | ||||
-rw-r--r-- | source3/script/mkbuildoptions.awk | 14 | ||||
-rw-r--r-- | source3/winbindd/winbindd_ads.c | 5 | ||||
-rw-r--r-- | source3/winbindd/winbindd_cache.c | 4 |
5 files changed, 103 insertions, 58 deletions
diff --git a/source3/client/client.c b/source3/client/client.c index 03bc15c68c..c63921aa1a 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -382,7 +382,7 @@ static int do_cd(const char *new_dir) /* Ensure cur_dir ends in a DIRSEP */ if ((new_cd[0] != '\0') && (*(new_cd+strlen(new_cd)-1) != CLI_DIRSEP_CHAR)) { - new_cd = talloc_asprintf_append(new_cd, CLI_DIRSEP_STR); + new_cd = talloc_asprintf_append(new_cd, "%s", CLI_DIRSEP_STR); if (!new_cd) { goto out; } @@ -889,7 +889,7 @@ static int cmd_dir(void) if (*buf == CLI_DIRSEP_CHAR) { mask = talloc_strdup(ctx, buf); } else { - mask = talloc_asprintf_append(mask, buf); + mask = talloc_asprintf_append(mask, "%s", buf); } } else { mask = talloc_asprintf_append(mask, "*"); @@ -930,7 +930,7 @@ static int cmd_du(void) return 1; } if ((mask[0] != '\0') && (mask[strlen(mask)-1]!=CLI_DIRSEP_CHAR)) { - mask = talloc_asprintf_append(mask, CLI_DIRSEP_STR); + mask = talloc_asprintf_append(mask, "%s", CLI_DIRSEP_STR); if (!mask) { return 1; } @@ -941,7 +941,7 @@ static int cmd_du(void) if (*buf == CLI_DIRSEP_CHAR) { mask = talloc_strdup(ctx, buf); } else { - mask = talloc_asprintf_append(mask, buf); + mask = talloc_asprintf_append(mask, "%s", buf); } } else { mask = talloc_strdup(ctx, "*"); @@ -1127,7 +1127,7 @@ static int cmd_get(void) d_printf("get <filename> [localname]\n"); return 1; } - rname = talloc_asprintf_append(rname, fname); + rname = talloc_asprintf_append(rname, "%s", fname); if (!rname) { return 1; } @@ -1243,7 +1243,10 @@ static void do_mget(file_info *finfo, const char *dir) } do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true); - chdir(".."); + if (chdir("..") == -1) { + d_printf("do_mget: failed to chdir to .. (error %s)\n", + strerror(errno) ); + } client_set_cur_dir(saved_curdir); TALLOC_FREE(mget_mask); TALLOC_FREE(saved_curdir); @@ -1286,7 +1289,7 @@ static int cmd_more(void) unlink(lname); return 1; } - rname = talloc_asprintf_append(rname, fname); + rname = talloc_asprintf_append(rname, "%s", fname); if (!rname) { return 1; } @@ -1306,7 +1309,10 @@ static int cmd_more(void) if (!pager_cmd) { return 1; } - system(pager_cmd); + if (system(pager_cmd) == -1) { + d_printf("system command '%s' returned -1\n", + pager_cmd); + } unlink(lname); return rc; @@ -1338,7 +1344,7 @@ static int cmd_mget(void) mget_mask = talloc_strdup(ctx, buf); } else { mget_mask = talloc_asprintf_append(mget_mask, - buf); + "%s", buf); } if (!mget_mask) { return 1; @@ -1434,7 +1440,7 @@ static int cmd_mkdir(void) } return 1; } - mask = talloc_asprintf_append(mask, buf); + mask = talloc_asprintf_append(mask, "%s", buf); if (!mask) { return 1; } @@ -1463,14 +1469,14 @@ static int cmd_mkdir(void) trim_char(ddir,'.','\0'); p = strtok_r(ddir, "/\\", &saveptr); while (p) { - ddir2 = talloc_asprintf_append(ddir2, p); + ddir2 = talloc_asprintf_append(ddir2, "%s", p); if (!ddir2) { return 1; } if (!cli_chkpath(targetcli, ddir2)) { do_mkdir(ddir2); } - ddir2 = talloc_asprintf_append(ddir2, CLI_DIRSEP_STR); + ddir2 = talloc_asprintf_append(ddir2, "%s", CLI_DIRSEP_STR); if (!ddir2) { return 1; } @@ -1502,7 +1508,7 @@ static int cmd_altname(void) d_printf("altname <file>\n"); return 1; } - name = talloc_asprintf_append(name, buf); + name = talloc_asprintf_append(name, "%s", buf); if (!name) { return 1; } @@ -1586,7 +1592,7 @@ static int cmd_allinfo(void) d_printf("allinfo <file>\n"); return 1; } - name = talloc_asprintf_append(name, buf); + name = talloc_asprintf_append(name, "%s", buf); if (!name) { return 1; } @@ -1731,9 +1737,9 @@ static int cmd_put(void) } if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { - rname = talloc_asprintf_append(rname, buf); + rname = talloc_asprintf_append(rname, "%s", buf); } else { - rname = talloc_asprintf_append(rname, lname); + rname = talloc_asprintf_append(rname, "%s", lname); } if (!rname) { return 1; @@ -2130,7 +2136,7 @@ static int cmd_del(void) d_printf("del <filename>\n"); return 1; } - mask = talloc_asprintf_append(mask, buf); + mask = talloc_asprintf_append(mask, "%s", buf); if (!mask) { return 1; } @@ -3491,7 +3497,10 @@ static int cmd_lcd(void) char *d; if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { - chdir(buf); + if (chdir(buf) == -1) { + d_printf("chdir to %s failed (%s)\n", + buf, strerror(errno)); + } } d = TALLOC_ARRAY(ctx, char, PATH_MAX+1); if (!d) { @@ -3522,7 +3531,7 @@ static int cmd_reget(void) d_printf("reget <filename>\n"); return 1; } - remote_name = talloc_asprintf_append(remote_name, fname); + remote_name = talloc_asprintf_append(remote_name, "%s", fname); if (!remote_name) { return 1; } @@ -3569,10 +3578,10 @@ static int cmd_reput(void) if (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { remote_name = talloc_asprintf_append(remote_name, - buf); + "%s", buf); } else { remote_name = talloc_asprintf_append(remote_name, - local_name); + "%s", local_name); } if (!remote_name) { return 1; @@ -4106,13 +4115,13 @@ static void completion_remote_filter(const char *mnt, TALLOC_FREE(ctx); return; } - tmp = talloc_asprintf_append(tmp, f->name); + tmp = talloc_asprintf_append(tmp, "%s", f->name); if (!tmp) { TALLOC_FREE(ctx); return; } if (f->mode & aDIR) { - tmp = talloc_asprintf_append(tmp, CLI_DIRSEP_STR); + tmp = talloc_asprintf_append(tmp, "%s", CLI_DIRSEP_STR); } if (!tmp) { TALLOC_FREE(ctx); @@ -4460,7 +4469,10 @@ static int process_stdin(void) /* special case - first char is ! */ if (*line == '!') { - system(line + 1); + if (system(line + 1) == -1) { + d_printf("system() command %s failed.\n", + line+1); + } SAFE_FREE(line); TALLOC_FREE(frame); continue; diff --git a/source3/libsmb/passchange.c b/source3/libsmb/passchange.c index 2746a4681e..76b06088d6 100644 --- a/source3/libsmb/passchange.c +++ b/source3/libsmb/passchange.c @@ -38,8 +38,10 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam *err_str = NULL; if(!resolve_name( remote_machine, &ss, 0x20)) { - asprintf(err_str, "Unable to find an IP address for machine " - "%s.\n", remote_machine); + if (asprintf(err_str, "Unable to find an IP address for machine " + "%s.\n", remote_machine) == -1) { + *err_str = NULL; + } return NT_STATUS_UNSUCCESSFUL; } @@ -50,9 +52,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam result = cli_connect(cli, remote_machine, &ss); if (!NT_STATUS_IS_OK(result)) { - asprintf(err_str, "Unable to connect to SMB server on " + if (asprintf(err_str, "Unable to connect to SMB server on " "machine %s. Error was : %s.\n", - remote_machine, nt_errstr(result)); + remote_machine, nt_errstr(result))==-1) { + *err_str = NULL; + } cli_shutdown(cli); return result; } @@ -61,9 +65,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam make_nmb_name(&called , remote_machine, 0x20); if (!cli_session_request(cli, &calling, &called)) { - asprintf(err_str, "machine %s rejected the session setup. " + if (asprintf(err_str, "machine %s rejected the session setup. " "Error was : %s.\n", - remote_machine, cli_errstr(cli) ); + remote_machine, cli_errstr(cli)) == -1) { + *err_str = NULL; + } result = cli_nt_error(cli); cli_shutdown(cli); return result; @@ -74,9 +80,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam result = cli_negprot(cli); if (!NT_STATUS_IS_OK(result)) { - asprintf(err_str, "machine %s rejected the negotiate " + if (asprintf(err_str, "machine %s rejected the negotiate " "protocol. Error was : %s.\n", - remote_machine, nt_errstr(result)); + remote_machine, nt_errstr(result)) == -1) { + *err_str = NULL; + } result = cli_nt_error(cli); cli_shutdown(cli); return result; @@ -97,8 +105,10 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam if (!NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_MUST_CHANGE) && !NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_EXPIRED)) { - asprintf(err_str, "Could not connect to machine %s: " - "%s\n", remote_machine, cli_errstr(cli)); + if (asprintf(err_str, "Could not connect to machine %s: " + "%s\n", remote_machine, cli_errstr(cli)) == -1) { + *err_str = NULL; + } cli_shutdown(cli); return result; } @@ -114,9 +124,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam result = cli_session_setup(cli, "", "", 0, "", 0, ""); if (!NT_STATUS_IS_OK(result)) { - asprintf(err_str, "machine %s rejected the session " + if (asprintf(err_str, "machine %s rejected the session " "setup. Error was : %s.\n", - remote_machine, cli_errstr(cli) ); + remote_machine, cli_errstr(cli)) == -1) { + *err_str = NULL; + } cli_shutdown(cli); return result; } @@ -127,9 +139,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam } if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { - asprintf(err_str, "machine %s rejected the tconX on the IPC$ " + if (asprintf(err_str, "machine %s rejected the tconX on the IPC$ " "share. Error was : %s.\n", - remote_machine, cli_errstr(cli) ); + remote_machine, cli_errstr(cli)) == -1) { + *err_str = NULL; + } result = cli_nt_error(cli); cli_shutdown(cli); return result; @@ -162,18 +176,22 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam if (lp_client_lanman_auth()) { /* Use the old RAP method. */ if (!cli_oem_change_password(cli, user_name, new_passwd, old_passwd)) { - asprintf(err_str, "machine %s rejected the " + if (asprintf(err_str, "machine %s rejected the " "password change: Error was : %s.\n", - remote_machine, cli_errstr(cli) ); + remote_machine, cli_errstr(cli)) == -1) { + *err_str = NULL; + } result = cli_nt_error(cli); cli_shutdown(cli); return result; } } else { - asprintf(err_str, "SAMR connection to machine %s " + if (asprintf(err_str, "SAMR connection to machine %s " "failed. Error was %s, but LANMAN password " "changed are disabled\n", - nt_errstr(result), remote_machine); + nt_errstr(result), remote_machine) == -1) { + *err_str = NULL; + } result = cli_nt_error(cli); cli_shutdown(cli); return result; @@ -191,9 +209,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam || NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) { /* it failed, but for reasons such as wrong password, too short etc ... */ - asprintf(err_str, "machine %s rejected the password change: " + if (asprintf(err_str, "machine %s rejected the password change: " "Error was : %s.\n", - remote_machine, get_friendly_nt_error_msg(result)); + remote_machine, get_friendly_nt_error_msg(result)) == -1) { + *err_str = NULL; + } cli_shutdown(cli); return result; } @@ -222,10 +242,12 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam || NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) { /* it failed, but again it was due to things like new password too short */ - asprintf(err_str, "machine %s rejected the " + if (asprintf(err_str, "machine %s rejected the " "(anonymous) password change: Error was : " "%s.\n", remote_machine, - get_friendly_nt_error_msg(result)); + get_friendly_nt_error_msg(result)) == -1) { + *err_str = NULL; + } cli_shutdown(cli); return result; } @@ -241,17 +263,21 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam cli_shutdown(cli); return NT_STATUS_OK; } - asprintf(err_str, "machine %s rejected the password " + if (asprintf(err_str, "machine %s rejected the password " "change: Error was : %s.\n", - remote_machine, cli_errstr(cli) ); + remote_machine, cli_errstr(cli)) == -1) { + *err_str = NULL; + } result = cli_nt_error(cli); cli_shutdown(cli); return result; } else { - asprintf(err_str, "SAMR connection to machine %s " + if (asprintf(err_str, "SAMR connection to machine %s " "failed. Error was %s, but LANMAN password " "changed are disabled\n", - nt_errstr(result), remote_machine); + nt_errstr(result), remote_machine) == -1) { + *err_str = NULL; + } cli_shutdown(cli); return NT_STATUS_UNSUCCESSFUL; } diff --git a/source3/script/mkbuildoptions.awk b/source3/script/mkbuildoptions.awk index 02562cf7b2..a1e5d85061 100644 --- a/source3/script/mkbuildoptions.awk +++ b/source3/script/mkbuildoptions.awk @@ -23,29 +23,31 @@ BEGIN { print "#include \"build_env.h\""; print "#include \"dynconfig.h\""; print ""; - print "static void output(bool screen, const char *format, ...) PRINTF_ATTRIBUTE(2,3);"; + print "static int output(bool screen, const char *format, ...) PRINTF_ATTRIBUTE(2,3);"; print "void build_options(bool screen);"; print ""; print ""; print "/****************************************************************************"; print "helper function for build_options"; print "****************************************************************************/"; - print "static void output(bool screen, const char *format, ...)"; + print "static int output(bool screen, const char *format, ...)"; print "{"; - print " char *ptr;"; + print " char *ptr = NULL;"; + print " int ret = 0;"; print " va_list ap;"; print " "; print " va_start(ap, format);"; - print " vasprintf(&ptr,format,ap);"; + print " ret = vasprintf(&ptr,format,ap);"; print " va_end(ap);"; print ""; print " if (screen) {"; - print " d_printf(\"%s\", ptr);"; + print " d_printf(\"%s\", ptr ? ptr : \"\");"; print " } else {"; - print " DEBUG(4,(\"%s\", ptr));"; + print " DEBUG(4,(\"%s\", ptr ? ptr : \"\"));"; print " }"; print " "; print " SAFE_FREE(ptr);"; + print " return ret;"; print "}"; print ""; print "/****************************************************************************"; diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c index 5c7d491849..a508682e5e 100644 --- a/source3/winbindd/winbindd_ads.c +++ b/source3/winbindd/winbindd_ads.c @@ -525,7 +525,10 @@ static NTSTATUS query_user(struct winbindd_domain *domain, } sidstr = sid_binstring(sid); - asprintf(&ldap_exp, "(objectSid=%s)", sidstr); + if (asprintf(&ldap_exp, "(objectSid=%s)", sidstr) == -1) { + status = NT_STATUS_NO_MEMORY; + goto done; + } rc = ads_search_retry(ads, &msg, ldap_exp, attrs); free(ldap_exp); free(sidstr); diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c index 2f4a6ffe56..1ae7966bc3 100644 --- a/source3/winbindd/winbindd_cache.c +++ b/source3/winbindd/winbindd_cache.c @@ -3852,7 +3852,9 @@ static TDB_DATA make_tdc_key( const char *domain_name ) } - asprintf( &keystr, "TRUSTDOMCACHE/%s", domain_name ); + if (asprintf( &keystr, "TRUSTDOMCACHE/%s", domain_name ) == -1) { + return key; + } key = string_term_tdb_data(keystr); return key; |