Jeremy.
return 0;
case CMD_SYSTEM:
/* Shell command */
- system(arg1);
+ if (system(arg1) == -1) {
+ terror("system() call failed\n");
+ }
return 0;
case CMD_QUIT:
return 1;
ndr->depth++;
for (i=0;i<count;i++) {
char *idx=NULL;
- asprintf(&idx, "[%d]", i);
- if (idx) {
+ if (asprintf(&idx, "[%d]", i) == -1) {
ndr_print_uint8(ndr, idx, data[i]);
free(idx);
}
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;
}
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);
/* 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"));
+ }
+ }
}
/****************************************************************************
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",
SAFE_FREE(logbase);
return;
}
- mkdir(corepath,0700);
+ if (mkdir(corepath,0700) == -1) {
+ if (errno != EEXIST) {
+ SAFE_FREE(corepath);
+ SAFE_FREE(logbase);
+ return;
+ }
+ }
- chown(corepath,getuid(),getgid());
- chmod(corepath,0700);
+ if (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
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);
goto exit_lchown;
}
- lchown(adbl_path, uid, gid);
+ if (lchown(adbl_path, uid, gid) == -1) {
+ DEBUG(3, ("ATALK: lchown error %s\n", strerror(errno)));
+ }
exit_lchown:
talloc_destroy(ctx);
}
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);
}
}
}
- 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 */
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));
/* 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,
/* 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,
/* 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,
/* 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,
/* 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,
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 )
}
/* 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);
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);
/* 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 );
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);
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;
}
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);
}
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);
}
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;
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);
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;
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);
}
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);
/*
/* 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",
return NULL;
}
- asprintf(&prompt, "Enter %s's password:", user);
- if (!prompt) {
+ if (asprintf(&prompt, "Enter %s's password:", user) == -1) {
return NULL;
}
return;
}
- fprintf(stdout, var);
+ fprintf(stdout, "%s", var);
va_end(args);
SAFE_FREE(var);
}
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);
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);
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);
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);