Fix all warnings with gcc4.3.
authorJeremy Allison <jra@samba.org>
Thu, 1 Jan 2009 01:27:52 +0000 (17:27 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 1 Jan 2009 01:27:52 +0000 (17:27 -0800)
Jeremy.

15 files changed:
source/client/clitar.c
source/lib/fault.c
source/lib/tdb/tools/tdbtool.c
source/modules/vfs_netatalk.c
source/modules/vfs_recycle.c
source/rpcclient/cmd_spoolss.c
source/utils/eventlogadm.c
source/utils/net_ads.c
source/utils/net_cache.c
source/utils/net_lookup.c
source/utils/net_rpc.c
source/utils/net_time.c
source/utils/net_util.c
source/utils/profiles.c
source/utils/smbget.c

index 084f87e3996a86d0f1d55e35c633d9ec50764763..5a974467c30e5b27496643833c4ab36e6ebc9bcb 100644 (file)
@@ -329,13 +329,13 @@ static int dotarbuf(int f, char *b, int n)
 
                diff=tbufsiz-tp;
                memcpy(tarbuf + tp, b, diff);
-               fail=fail && (1+write(f, tarbuf, tbufsiz));
+               fail=fail && (1+sys_write(f, tarbuf, tbufsiz));
                n-=diff;
                b+=diff;
                tp=0;
 
                while (n >= tbufsiz) {
-                       fail=fail && (1 + write(f, b, tbufsiz));
+                       fail=fail && (1 + sys_write(f, b, tbufsiz));
                        n-=tbufsiz;
                        b+=tbufsiz;
                }
@@ -364,7 +364,10 @@ static void dozerobuf(int f, int n)
 
        if (n+tp >= tbufsiz) {
                memset(tarbuf+tp, 0, tbufsiz-tp);
-               write(f, tarbuf, tbufsiz);
+               if (sys_write(f, tarbuf, tbufsiz) != tbufsiz) {
+                       DEBUG(0, ("dozerobuf: sys_write fail\n"));
+                       return;
+               }
                memset(tarbuf, 0, (tp+=n-tbufsiz));
        } else {
                memset(tarbuf+tp, 0, n);
@@ -408,8 +411,12 @@ static void dotareof(int f)
 
        /* Could be a pipe, in which case S_ISREG should fail,
                * and we should write out at full size */
-       if (tp > 0)
-               write(f, tarbuf, S_ISREG(stbuf.st_mode) ? tp : tbufsiz);
+       if (tp > 0) {
+               size_t towrite = S_ISREG(stbuf.st_mode) ? tp : tbufsiz;
+               if (sys_write(f, tarbuf, towrite) != towrite) {
+                       DEBUG(0,("dotareof: sys_write fail\n"));
+               }
+       }
 }
 
 /****************************************************************************
index d4c1142937984673af64acd8e6df47d4b98bf17a..1bd7d038c9edf99a6ea08d0fc138e73c86993ea3 100644 (file)
@@ -119,7 +119,18 @@ void dump_core_setup(const char *progname)
                SAFE_FREE(logbase);
                return;
        }
-       mkdir(corepath,0700);
+       if (mkdir(corepath,0700) == -1) {
+               if (errno != EEXIST) {
+                       SAFE_FREE(corepath);
+                       SAFE_FREE(logbase);
+                       return;
+               }
+       }
+       if (chmod(corepath,0700) == -1) {
+               SAFE_FREE(corepath);
+               SAFE_FREE(logbase);
+               return;
+       }
 
        SAFE_FREE(corepath);
        if (asprintf(&corepath, "%s/cores/%s",
@@ -127,11 +138,26 @@ void dump_core_setup(const char *progname)
                SAFE_FREE(logbase);
                return;
        }
-       mkdir(corepath,0700);
+       if (mkdir(corepath,0700) == -1) {
+               if (errno != EEXIST) {
+                       SAFE_FREE(corepath);
+                       SAFE_FREE(logbase);
+                       return;
+               }
+       }
 
-       sys_chown(corepath,getuid(),getgid());
-       chmod(corepath,0700);
+       if (sys_chown(corepath,getuid(),getgid()) == -1) {
+               SAFE_FREE(corepath);
+               SAFE_FREE(logbase);
+               return;
+       }
+       if (chmod(corepath,0700) == -1) {
+               SAFE_FREE(corepath);
+               SAFE_FREE(logbase);
+               return;
+       }
 
+       SAFE_FREE(corepath);
        SAFE_FREE(logbase);
 
 #ifdef HAVE_GETRLIMIT
index 35f7f20b1d2b325c1c2eb1d603838199e15c7d7d..f61d2c0bdd5266b921a5ea6794f7e3eebf8ea4cb 100644 (file)
@@ -455,7 +455,7 @@ static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
                print_rec(the_tdb, *pkey, dbuf, NULL);
 }
 
-static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
+static int test_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
 {
        return 0;
 }
@@ -506,7 +506,9 @@ static int do_command(void)
             return 0;
        case CMD_SYSTEM:
            /* Shell command */
-           system(arg1);
+           if (system(arg1) == -1) {
+               terror("system failed");
+           }
            return 0;
        case CMD_QUIT:
            return 1;
index 2cc4a6c4ba9020f414ece77d8dc3149e19ad845c..5760cf8a68088b3969fb66504afe149e6fd4c8d4 100644 (file)
@@ -367,7 +367,9 @@ static int atalk_chown(struct vfs_handle_struct *handle, const char *path, uid_t
                goto exit_chown;
        }
 
-       chown(adbl_path, uid, gid);
+       if (chown(adbl_path, uid, gid) == -1) {
+               DEBUG(3, ("ATALK: chown error %s\n", strerror(errno)));
+       }
 
 exit_chown:    
        talloc_destroy(ctx);
@@ -399,7 +401,9 @@ static int atalk_lchown(struct vfs_handle_struct *handle, const char *path, uid_
                goto exit_lchown;
        }
 
-       sys_lchown(adbl_path, uid, gid);
+       if (sys_lchown(adbl_path, uid, gid) == -1) {
+               DEBUG(3, ("ATALK: lchown error %s\n", strerror(errno)));
+       }
 
 exit_lchown:   
        talloc_destroy(ctx);
index acc1936e5f8f772eea2a02248acf287a310c2e80..cb985e1be22f45bdf982afac63bd3e010aa62948 100644 (file)
@@ -525,7 +525,9 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
        }
 
        if (recycle_keep_dir_tree(handle) == True) {
-               asprintf(&temp_name, "%s/%s", repository, path_name);
+               if (asprintf(&temp_name, "%s/%s", repository, path_name) == -1) {
+                       ALLOC_CHECK(temp_name, done);
+               }
        } else {
                temp_name = SMB_STRDUP(repository);
        }
@@ -543,8 +545,9 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
                }
        }
 
-       asprintf(&final_name, "%s/%s", temp_name, base);
-       ALLOC_CHECK(final_name, done);
+       if (asprintf(&final_name, "%s/%s", temp_name, base) == -1) {
+               ALLOC_CHECK(final_name, done);
+       }
        DEBUG(10, ("recycle: recycled file name: %s\n", final_name));           /* new filename with path */
 
        /* check if we should delete file from recycle bin */
@@ -561,7 +564,9 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
        i = 1;
        while (recycle_file_exist(handle, final_name)) {
                SAFE_FREE(final_name);
-               asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base);
+               if (asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base) == -1) {
+                       ALLOC_CHECK(final_name, done);
+               }
        }
 
        DEBUG(10, ("recycle: Moving %s to %s\n", file_name, final_name));
index 2a9f2b82bb2c0bf1ba8c7dd2bfa86296736f66c3..1e9001f3d63bee410c0232e09ab948ba4ec6423c 100644 (file)
@@ -1655,9 +1655,14 @@ static WERROR cmd_spoolss_addform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
        
        /* Get a printer handle */
 
-       asprintf(&servername, "\\\\%s", cli->desthost);
+       if (asprintf(&servername, "\\\\%s", cli->desthost) == -1) {
+               return WERR_NOMEM;
+       }
        strupper_m(servername);
-       asprintf(&printername, "%s\\%s", servername, argv[1]);
+       if (asprintf(&printername, "%s\\%s", servername, argv[1]) == -1) {
+               SAFE_FREE(servername);
+               return WERR_NOMEM;
+       }
 
        werror = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", 
                                             PRINTER_ALL_ACCESS, 
@@ -1716,9 +1721,14 @@ static WERROR cmd_spoolss_setform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
        
        /* Get a printer handle */
 
-       asprintf(&servername, "\\\\%s", cli->desthost);
+       if (asprintf(&servername, "\\\\%s", cli->desthost)) {
+               return WERR_NOMEM;
+       }
        strupper_m(servername);
-       asprintf(&printername, "%s\\%s", servername, argv[1]);
+       if (asprintf(&printername, "%s\\%s", servername, argv[1]) == -1) {
+               SAFE_FREE(servername);
+               return WERR_NOMEM;
+       }
 
        werror = rpccli_spoolss_open_printer_ex(
                cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, 
@@ -1813,9 +1823,14 @@ static WERROR cmd_spoolss_getform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
        
        /* Get a printer handle */
 
-       asprintf(&servername, "\\\\%s", cli->desthost);
+       if (asprintf(&servername, "\\\\%s", cli->desthost) == -1) {
+               return WERR_NOMEM;
+       }
        strupper_m(servername);
-       asprintf(&printername, "%s\\%s", servername, argv[1]);
+       if (asprintf(&printername, "%s\\%s", servername, argv[1])) {
+               SAFE_FREE(servername);
+               return WERR_NOMEM;
+       }
 
        werror = rpccli_spoolss_open_printer_ex(
                cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, 
@@ -1866,9 +1881,14 @@ static WERROR cmd_spoolss_deleteform(struct rpc_pipe_client *cli,
        
        /* Get a printer handle */
 
-       asprintf(&servername, "\\\\%s", cli->desthost);
+       if (asprintf(&servername, "\\\\%s", cli->desthost) == -1) {
+               return WERR_NOMEM;
+       }
        strupper_m(servername);
-       asprintf(&printername, "%s\\%s", servername, argv[1]);
+       if (asprintf(&printername, "%s\\%s", servername, argv[1]) == -1) {
+               SAFE_FREE(servername);
+               return WERR_NOMEM;
+       }
 
        werror = rpccli_spoolss_open_printer_ex(
                cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, 
@@ -1916,9 +1936,14 @@ static WERROR cmd_spoolss_enum_forms(struct rpc_pipe_client *cli,
        
        /* Get a printer handle */
 
-       asprintf(&servername, "\\\\%s", cli->desthost);
+       if (asprintf(&servername, "\\\\%s", cli->desthost) == -1) {
+               return WERR_NOMEM;
+       }
        strupper_m(servername);
-       asprintf(&printername, "%s\\%s", servername, argv[1]);
+       if (asprintf(&printername, "%s\\%s", servername, argv[1]) == -1) {
+               SAFE_FREE(servername);
+               return WERR_NOMEM;
+       }
 
        werror = rpccli_spoolss_open_printer_ex(
                cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, 
index 1b38a7b13b25b02852496599be240655383be60b..5fed4d1a399867c7a8bf40e54d61ac1558218847 100644 (file)
@@ -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 )
index 95a68079befcb602aaf5c24183ec7ae438c27ed5..d0f7430174a308e5d303c161c8f1ef6df125bf3d 100644 (file)
@@ -476,7 +476,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);
@@ -531,7 +533,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);
 
@@ -1295,7 +1300,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 );
@@ -1634,7 +1641,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);
@@ -1805,7 +1819,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;
        }
 
@@ -1835,7 +1851,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);
        }
@@ -1883,7 +1901,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);
index 4e9ae18c0d9a6f8a738871aba547fdcf7a093e93..cabb6d5280845d3ada791ae1a6912caa39f00e26 100644 (file)
@@ -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;
index 8b9ddb62bacc111d74b74a0af4303b45261400e6..66f673b8d32fc7dbbb760ca07666e11ba4773ac5 100644 (file)
@@ -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;
index 65e0a49d3603005b7bef6ed5db71bd6922127cc2..8742f9ac0a224b27178533bbbacd55757cba18cd 100644 (file)
@@ -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);
        }
@@ -5537,7 +5539,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);
 
        /*
index f569538faca20af6d33832d3988e7c4dac66501d..ac3b8f3772fc68cb378b6ae9daa31e4f26837977 100644 (file)
@@ -114,7 +114,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",
index 4e08b5b7046e538dceded23b265b455d527ec5a0..ee02942ad21d8923e06833648ef4994e9f34145a 100644 (file)
@@ -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;
        }
 
index 0b8a0d4278386e968bdbfc2590e251cb532eb864..5dd788ad5ff937eac2c7d13d40422083ab280c2f 100644 (file)
@@ -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);
 }
index 3d4a71b71d1d1e9a51d2abd7964bebbfd037a892..c062134a55eb19eab5306bee9dac66338f34b2a0 100644 (file)
@@ -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);