* University of Maryland at College Park
*/
/*
- * $Id: selfcheck.c,v 1.95 2006/08/29 11:21:00 martinea Exp $
+ * $Id: selfcheck.c 10421 2008-03-06 18:48:30Z martineau $
*
* do self-check and send back any error messages
*/
#include "amanda.h"
-#include "statfs.h"
+#include "fsusage.h"
#include "version.h"
#include "getfsent.h"
#include "amandates.h"
#include "client_util.h"
#include "conffile.h"
#include "amandad.h"
+#include "amxml.h"
+#include "base64.h"
#ifdef SAMBA_CLIENT
#include "findpass.h"
#endif
-#define selfcheck_debug(i,x) do { \
- if ((i) <= debug_selfcheck) { \
- dbprintf(x); \
- } \
-} while (0)
-
int need_samba=0;
int need_rundump=0;
int need_dump=0;
int need_gnutar=0;
int need_compress_path=0;
int need_calcsize=0;
-int program_is_backup_api=0;
+int program_is_application_api=0;
static char *amandad_auth = NULL;
static am_feature_t *our_features = NULL;
/* local functions */
int main(int argc, char **argv);
-static void check_options(char *program, char *calcprog, char *disk, char *amdevice, option_t *options);
-static void check_disk(char *program, char *calcprog, char *disk, char *amdevice, int level, option_t *options);
+static void check_options(dle_t *dle);
+static void check_disk(dle_t *dle);
static void check_overall(void);
-static void check_access(char *filename, int mode);
static int check_file_exist(char *filename);
-static void check_file(char *filename, int mode);
-static void check_dir(char *dirname, int mode);
-static void check_suid(char *filename);
static void check_space(char *dir, off_t kbytes);
int
int argc,
char ** argv)
{
- int level;
char *line = NULL;
- char *program = NULL;
- char *calcprog = NULL;
- char *disk = NULL;
char *qdisk = NULL;
- char *amdevice = NULL;
char *qamdevice = NULL;
char *optstr = NULL;
char *err_extra = NULL;
char *s, *fp;
- char *conffile;
- option_t *options;
int ch;
-#if defined(USE_DBMALLOC)
- unsigned long malloc_hist_1, malloc_size_1;
- unsigned long malloc_hist_2, malloc_size_2;
-#endif
+ dle_t *dle;
+ int level;
+ GSList *errlist;
/* initialize */
+ /*
+ * Configure program for internationalization:
+ * 1) Only set the message locale for now.
+ * 2) Set textdomain for all amanda related programs to "amanda"
+ * We don't want to be forced to support dozens of message catalogs.
+ */
+ setlocale(LC_MESSAGES, "C");
+ textdomain("amanda");
+
safe_fd(-1, 0);
safe_cd();
/* Don't die when child closes pipe */
signal(SIGPIPE, SIG_IGN);
-#if defined(USE_DBMALLOC)
- malloc_size_1 = malloc_inuse(&malloc_hist_1);
-#endif
-
erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
dbopen(DBG_SUBDIR_CLIENT);
startclock();
- dbprintf(("%s: version %s\n", get_pname(), version()));
+ dbprintf(_("version %s\n"), version());
if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
amandad_auth = stralloc(argv[2]);
}
- conffile = vstralloc(CONFIG_DIR, "/", "amanda-client.conf", NULL);
- if (read_clientconf(conffile) > 0) {
- printf("ERROR [reading conffile: %s]\n", conffile);
- error("error reading conffile: %s", conffile);
- /*NOTREACHED*/
- }
- amfree(conffile);
+ config_init(CONFIG_INIT_CLIENT, NULL);
+ /* (check for config errors comes later) */
+
+ check_running_as(RUNNING_AS_CLIENT_LOGIN);
our_features = am_init_feature_set();
our_feature_string = am_feature_to_string(our_features);
g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
}
- printf("OPTIONS ");
+ g_printf("OPTIONS ");
if(am_has_feature(g_options->features, fe_rep_options_features)) {
- printf("features=%s;", our_feature_string);
+ g_printf("features=%s;", our_feature_string);
}
if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
- printf("hostname=%s;", g_options->hostname);
+ g_printf("hostname=%s;", g_options->hostname);
}
- printf("\n");
+ g_printf("\n");
fflush(stdout);
if (g_options->config) {
- conffile = vstralloc(CONFIG_DIR, "/", g_options->config, "/",
- "amanda-client.conf", NULL);
- if (read_clientconf(conffile) > 0) {
- printf("ERROR [reading conffile: %s]\n", conffile);
- error("error reading conffile: %s", conffile);
- /*NOTREACHED*/
- }
- amfree(conffile);
+ /* overlay this configuration on the existing (nameless) configuration */
+ config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
+ g_options->config);
+
+ dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
+ }
- dbrename(g_options->config, DBG_SUBDIR_CLIENT);
+ /* check for any config errors now */
+ if (config_errors(&errlist) >= CFGERR_ERRORS) {
+ char *errstr = config_errors_to_error_string(errlist);
+ g_printf("%s\n", errstr);
+ dbclose();
+ return 1;
}
+ if (am_has_feature(g_options->features, fe_req_xml)) {
+ break;
+ }
continue;
}
+ dle = alloc_dle();
s = line;
ch = *s++;
if (ch == '\0') {
goto err; /* no program */
}
- program = s - 1;
+ dle->program = s - 1;
skip_non_whitespace(s, ch);
s[-1] = '\0'; /* terminate the program name */
- program_is_backup_api = 0;
- if(strcmp(program,"BACKUP")==0) {
- program_is_backup_api = 1;
+ dle->program_is_application_api = 0;
+ if(strcmp(dle->program,"APPLICATION")==0) {
+ dle->program_is_application_api = 1;
skip_whitespace(s, ch); /* find dumper name */
if (ch == '\0') {
goto err; /* no program */
}
- program = s - 1;
+ dle->program = s - 1;
skip_non_whitespace(s, ch);
s[-1] = '\0'; /* terminate the program name */
}
- if(strncmp_const(program, "CALCSIZE") == 0) {
+ if(strncmp_const(dle->program, "CALCSIZE") == 0) {
skip_whitespace(s, ch); /* find program name */
if (ch == '\0') {
goto err; /* no program */
}
- calcprog = s - 1;
+ dle->program = s - 1;
skip_non_whitespace(s, ch);
s[-1] = '\0';
+ dle->calcsize = 1;
}
else {
- calcprog = NULL;
+ dle->calcsize = 0;
}
skip_whitespace(s, ch); /* find disk name */
qdisk = s - 1;
skip_quoted_string(s, ch);
s[-1] = '\0'; /* terminate the disk name */
- disk = unquote_string(qdisk);
+ dle->disk = unquote_string(qdisk);
skip_whitespace(s, ch); /* find the device or level */
if (ch == '\0') {
skip_quoted_string(s, ch);
s[-1] = '\0'; /* terminate the device */
qamdevice = stralloc(fp);
- amdevice = unquote_string(qamdevice);
+ dle->device = unquote_string(qamdevice);
skip_whitespace(s, ch); /* find level number */
}
else {
- amdevice = stralloc(disk);
+ dle->device = stralloc(dle->disk);
+ qamdevice = stralloc(qdisk);
}
/* find level number */
if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
goto err; /* bad level */
}
+ dle->level = g_slist_append(dle->level, GINT_TO_POINTER(level));
skip_integer(s, ch);
skip_whitespace(s, ch);
optstr = s - 1;
skip_quoted_string(s, ch);
s[-1] = '\0'; /* terminate the options */
- options = parse_options(optstr, disk, amdevice, g_options->features, 1);
+ parse_options(optstr, dle, g_options->features, 1);
/*@ignore@*/
- check_options(program, calcprog, disk, amdevice, options);
- check_disk(program, calcprog, disk, amdevice, level, options);
+
+ check_options(dle);
+ check_disk(dle);
+
/*@end@*/
- free_sl(options->exclude_file);
- free_sl(options->exclude_list);
- free_sl(options->include_file);
- free_sl(options->include_list);
- amfree(options->auth);
- amfree(options->str);
- amfree(options);
} else if (ch == '\0') {
/* check all since no option */
need_samba=1;
need_compress_path=1;
need_calcsize=1;
/*@ignore@*/
- check_disk(program, calcprog, disk, amdevice, level, NULL);
+ check_disk(dle);
/*@end@*/
} else {
goto err; /* bad syntax */
}
- amfree(disk);
- amfree(amdevice);
+ amfree(qamdevice);
+ }
+ if (g_options == NULL) {
+ g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
+ error(_("Missing OPTIONS line in selfcheck input\n"));
+ /*NOTREACHED*/
+ }
+
+ if (am_has_feature(g_options->features, fe_req_xml)) {
+ char *errmsg = NULL;
+ dle_t *dles, *dle;
+
+ dles = amxml_parse_node_FILE(stdin, &errmsg);
+ if (errmsg) {
+ err_extra = errmsg;
+ goto err;
+ }
+ for (dle = dles; dle != NULL; dle = dle->next) {
+ run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
+ stdout);
+ }
+ for (dle = dles; dle != NULL; dle = dle->next) {
+ check_options(dle);
+ run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle,
+ stdout);
+ check_disk(dle);
+ run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle,
+ stdout);
+ }
+ for (dle = dles; dle != NULL; dle = dle->next) {
+ run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
+ stdout);
+ }
}
check_overall();
amfree(our_feature_string);
am_release_feature_set(our_features);
our_features = NULL;
- am_release_feature_set(g_options->features);
- g_options->features = NULL;
- amfree(g_options->str);
- amfree(g_options->hostname);
- amfree(g_options);
-
-#if defined(USE_DBMALLOC)
- malloc_size_2 = malloc_inuse(&malloc_hist_2);
-
- if(malloc_size_1 != malloc_size_2) {
- extern int dbfd;
-
- malloc_list(dbfd(), malloc_hist_1, malloc_hist_2);
- }
-#endif
+ free_g_options(g_options);
dbclose();
return 0;
err:
- printf("ERROR [BOGUS REQUEST PACKET]\n");
- dbprintf(("%s: REQ packet is bogus%s%s\n",
- debug_prefix_time(NULL),
- err_extra ? ": " : "",
- err_extra ? err_extra : ""));
+ if (err_extra) {
+ g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra);
+ dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
+ } else {
+ g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n"));
+ dbprintf(_("REQ packet is bogus\n"));
+ }
dbclose();
return 1;
}
static void
check_options(
- char * program,
- char * calcprog,
- char * disk,
- char * amdevice,
- option_t * options)
+ dle_t *dle)
{
- char *myprogram = program;
-
- if(strcmp(myprogram,"CALCSIZE") == 0) {
- int nb_exclude = 0;
- int nb_include = 0;
- char *file_exclude = NULL;
- char *file_include = NULL;
-
- if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
- if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
- if(options->include_file) nb_include += options->include_file->nb_element;
- if(options->include_list) nb_include += options->include_list->nb_element;
-
- if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
- if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
-
- amfree(file_exclude);
- amfree(file_include);
-
+ if (dle->calcsize == 1) {
need_calcsize=1;
- if (calcprog == NULL) {
- printf("ERROR [no program name for calcsize]\n");
- } else {
- myprogram = calcprog;
- }
}
- if(strcmp(myprogram,"GNUTAR") == 0) {
+ if (strcmp(dle->program,"GNUTAR") == 0) {
need_gnutar=1;
- if(amdevice[0] == '/' && amdevice[1] == '/') {
- if(options->exclude_file && options->exclude_file->nb_element > 1) {
- printf("ERROR [samba support only one exclude file]\n");
+ if(dle->device[0] == '/' && dle->device[1] == '/') {
+ if(dle->exclude_file && dle->exclude_file->nb_element > 1) {
+ g_printf(_("ERROR [samba support only one exclude file]\n"));
}
- if(options->exclude_list && options->exclude_list->nb_element > 0 &&
- options->exclude_optional==0) {
- printf("ERROR [samba does not support exclude list]\n");
+ if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
+ dle->exclude_optional==0) {
+ g_printf(_("ERROR [samba does not support exclude list]\n"));
}
- if(options->include_file && options->include_file->nb_element > 0) {
- printf("ERROR [samba does not support include file]\n");
+ if (dle->include_file && dle->include_file->nb_element > 0) {
+ g_printf(_("ERROR [samba does not support include file]\n"));
}
- if(options->include_list && options->include_list->nb_element > 0 &&
- options->include_optional==0) {
- printf("ERROR [samba does not support include list]\n");
+ if (dle->include_list && dle->include_list->nb_element > 0 &&
+ dle->include_optional==0) {
+ g_printf(_("ERROR [samba does not support include list]\n"));
}
need_samba=1;
- }
- else {
+ } else {
int nb_exclude = 0;
int nb_include = 0;
char *file_exclude = NULL;
char *file_include = NULL;
- if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
- if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
- if(options->include_file) nb_include += options->include_file->nb_element;
- if(options->include_list) nb_include += options->include_list->nb_element;
+ if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element;
+ if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element;
+ if (dle->include_file) nb_include += dle->include_file->nb_element;
+ if (dle->include_list) nb_include += dle->include_list->nb_element;
- if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
- if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
+ if (nb_exclude > 0) file_exclude = build_exclude(dle, 1);
+ if (nb_include > 0) file_include = build_include(dle, 1);
amfree(file_exclude);
amfree(file_include);
}
}
- if(strcmp(myprogram,"DUMP") == 0) {
- if(options->exclude_file && options->exclude_file->nb_element > 0) {
- printf("ERROR [DUMP does not support exclude file]\n");
+ if (strcmp(dle->program,"DUMP") == 0) {
+ if (dle->exclude_file && dle->exclude_file->nb_element > 0) {
+ g_printf(_("ERROR [DUMP does not support exclude file]\n"));
}
- if(options->exclude_list && options->exclude_list->nb_element > 0) {
- printf("ERROR [DUMP does not support exclude list]\n");
+ if (dle->exclude_list && dle->exclude_list->nb_element > 0) {
+ g_printf(_("ERROR [DUMP does not support exclude list]\n"));
}
- if(options->include_file && options->include_file->nb_element > 0) {
- printf("ERROR [DUMP does not support include file]\n");
+ if (dle->include_file && dle->include_file->nb_element > 0) {
+ g_printf(_("ERROR [DUMP does not support include file]\n"));
}
- if(options->include_list && options->include_list->nb_element > 0) {
- printf("ERROR [DUMP does not support include list]\n");
+ if (dle->include_list && dle->include_list->nb_element > 0) {
+ g_printf(_("ERROR [DUMP does not support include list]\n"));
}
#ifdef USE_RUNDUMP
need_rundump=1;
#ifndef AIX_BACKUP
#ifdef VDUMP
#ifdef DUMP
- if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
+ if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
#else
if (1)
#endif
{
need_vdump=1;
need_rundump=1;
- if (options->createindex)
+ if (dle->create_index)
need_vrestore=1;
}
else
#endif /* VDUMP */
#ifdef XFSDUMP
#ifdef DUMP
- if (strcmp(amname_to_fstype(amdevice), "xfs") == 0)
+ if (strcmp(amname_to_fstype(dle->device), "xfs") == 0)
#else
if (1)
#endif
{
need_xfsdump=1;
need_rundump=1;
- if (options->createindex)
+ if (dle->create_index)
need_xfsrestore=1;
}
else
#endif /* XFSDUMP */
#ifdef VXDUMP
#ifdef DUMP
- if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0)
+ if (strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
#else
if (1)
#endif
{
need_vxdump=1;
- if (options->createindex)
+ if (dle->create-index)
need_vxrestore=1;
}
else
#endif /* VXDUMP */
{
need_dump=1;
- if (options->createindex)
+ if (dle->create_index)
need_restore=1;
}
#else
/* AIX backup program */
need_dump=1;
- if (options->createindex)
+ if (dle->create_index)
need_restore=1;
#endif
}
- if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST)
- || (options->compress == COMP_CUST)) {
+ if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST)
+ || (dle->compress == COMP_CUST)) {
need_compress_path=1;
}
- if(options->auth && amandad_auth) {
- if(strcasecmp(options->auth, amandad_auth) != 0) {
- fprintf(stdout,"ERROR [client configured for auth=%s while server requested '%s']\n",
- amandad_auth, options->auth);
+ if (dle->auth && amandad_auth) {
+ if (strcasecmp(dle->auth, amandad_auth) != 0) {
+ g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
+ amandad_auth, dle->auth);
+ if (strcmp(dle->auth, "ssh") == 0) {
+ g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
+ "should be \"--auth=ssh\", or use another auth "
+ " for the DLE]\n"));
+ }
+ else {
+ g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
+ " must be the same as the DLE]\n"));
+ }
}
}
}
static void
check_disk(
- char * program,
- char * calcprog,
- char * disk,
- char * amdevice,
- int level,
- option_t *options)
+ dle_t *dle)
{
char *device = stralloc("nodevice");
char *err = NULL;
int access_result;
char *access_type;
char *extra_info = NULL;
- char *myprogram = program;
- char *qdisk = quote_string(disk);
- char *qamdevice = quote_string(amdevice);
+ char *qdisk = quote_string(dle->disk);
+ char *qamdevice = quote_string(dle->device);
char *qdevice = NULL;
- FILE *toolin;
- char number[NUM_STR_SIZE];
-
- (void)level; /* Quiet unused parameter warning */
- dbprintf(("%s: checking disk %s\n", debug_prefix_time(NULL), qdisk));
-
- if(strcmp(myprogram,"CALCSIZE") == 0) {
- if(amdevice[0] == '/' && amdevice[1] == '/') {
- err = vstralloc("Can't use CALCSIZE for samba estimate,",
- " use CLIENT: ",
- amdevice,
- NULL);
+ dbprintf(_("checking disk %s\n"), qdisk);
+ if (dle->calcsize == 1) {
+ if (dle->device[0] == '/' && dle->device[1] == '/') {
+ err = vstrallocf(_("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
+ dle->device);
goto common_exit;
}
- myprogram = calcprog;
}
- if (strcmp(myprogram, "GNUTAR")==0) {
- if(amdevice[0] == '/' && amdevice[1] == '/') {
+ if (strcmp(dle->program, "GNUTAR")==0) {
+ if(dle->device[0] == '/' && dle->device[1] == '/') {
#ifdef SAMBA_CLIENT
int nullfd, checkerr;
int passwdfd;
size_t pwtext_len;
pid_t checkpid;
amwait_t retstat;
- char number[NUM_STR_SIZE];
pid_t wpid;
- int ret, sig, rc;
+ int rc;
char *line;
char *sep;
FILE *ferr;
char *pw_fd_env;
int errdos;
- parsesharename(amdevice, &share, &subdir);
+ parsesharename(dle->device, &share, &subdir);
if (!share) {
- err = stralloc2("cannot parse for share/subdir disk entry ", amdevice);
+ err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), dle->device);
goto common_exit;
}
if ((subdir) && (SAMBA_VERSION < 2)) {
- err = vstralloc("subdirectory specified for share '",
- amdevice,
- "' but samba not v2 or better",
- NULL);
+ err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
+ dle->device);
goto common_exit;
}
if ((user_and_password = findpass(share, &domain)) == NULL) {
- err = stralloc2("cannot find password for ", amdevice);
+ err = vstrallocf(_("cannot find password for %s"), dle->device);
goto common_exit;
}
lpass = strlen(user_and_password);
if ((pwtext = strchr(user_and_password, '%')) == NULL) {
- err = stralloc2("password field not \'user%pass\' for ", amdevice);
+ err = vstrallocf(_("password field not \'user%%pass\' for %s"), dle->device);
goto common_exit;
}
*pwtext++ = '\0';
pwtext_len = (size_t)strlen(pwtext);
amfree(device);
if ((device = makesharename(share, 0)) == NULL) {
- err = stralloc2("cannot make share name of ", share);
+ err = vstrallocf(_("cannot make share name of %s"), share);
goto common_exit;
}
if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
- err = stralloc2("Cannot access /dev/null : ", strerror(errno));
+ err = vstrallocf(_("Cannot access /dev/null : %s"), strerror(errno));
goto common_exit;
}
} else {
pw_fd_env = "dummy_PASSWD_FD";
}
- checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE,
+ checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0,
&nullfd, &nullfd, &checkerr,
pw_fd_env, &passwdfd,
"smbclient",
aclose(nullfd);
/*@ignore@*/
if ((pwtext_len > 0)
- && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) {
- err = vstralloc("password write failed: ",
- amdevice,
- ": ",
- strerror(errno),
- NULL);
+ && full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) {
+ err = vstrallocf(_("password write failed: %s: %s"),
+ dle->device, strerror(errno));
aclose(passwdfd);
goto common_exit;
}
aclose(passwdfd);
ferr = fdopen(checkerr, "r");
if (!ferr) {
- printf("ERROR [Can't fdopen: %s]\n", strerror(errno));
- error("Can't fdopen: %s", strerror(errno));
+ g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
+ error(_("Can't fdopen: %s"), strerror(errno));
/*NOTREACHED*/
}
sep = "";
afclose(ferr);
checkerr = -1;
rc = 0;
+ sep = "";
while ((wpid = wait(&retstat)) != -1) {
- if (WIFSIGNALED(retstat)) {
- ret = 0;
- rc = sig = WTERMSIG(retstat);
- } else {
- sig = 0;
- rc = ret = WEXITSTATUS(retstat);
- }
- if (rc != 0) {
+ if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
+ char *exitstr = str_exit_status("smbclient", retstat);
strappend(err, sep);
- if (ret == 0) {
- strappend(err, "got signal ");
- ret = sig;
- } else {
- strappend(err, "returned ");
- }
- snprintf(number, (size_t)sizeof(number), "%d", ret);
- strappend(err, number);
+ strappend(err, exitstr);
+ sep = "\n";
+ amfree(exitstr);
+
+ rc = 1;
}
}
if (errdos != 0 || rc != 0) {
- err = newvstralloc(err,
- "samba access error: ",
- amdevice,
- ": ",
- extra_info ? extra_info : "",
- err,
- NULL);
- amfree(extra_info);
+ if (extra_info) {
+ err = newvstrallocf(err,
+ _("samba access error: %s: %s %s"),
+ dle->device, extra_info, err);
+ amfree(extra_info);
+ } else {
+ err = newvstrallocf(err, _("samba access error: %s: %s"),
+ dle->device, err);
+ }
}
#else
- err = stralloc2("This client is not configured for samba: ", qdisk);
+ err = vstrallocf(_("This client is not configured for samba: %s"),
+ qdisk);
#endif
goto common_exit;
}
amode = F_OK;
amfree(device);
- device = amname_to_dirname(amdevice);
- } else if (strcmp(myprogram, "DUMP") == 0) {
- if(amdevice[0] == '/' && amdevice[1] == '/') {
- err = vstralloc("The DUMP program cannot handle samba shares,",
- " use GNUTAR: ",
- qdisk,
- NULL);
+ device = amname_to_dirname(dle->device);
+ } else if (strcmp(dle->program, "DUMP") == 0) {
+ if(dle->device[0] == '/' && dle->device[1] == '/') {
+ err = vstrallocf(
+ _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
+ qdisk);
goto common_exit;
}
#ifdef VDUMP /* { */
#ifdef DUMP /* { */
- if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
+ if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
#else /* }{ */
if (1)
#endif /* } */
{
amfree(device);
- device = amname_to_dirname(amdevice);
+ device = amname_to_dirname(dle->device);
amode = F_OK;
} else
#endif /* } */
{
amfree(device);
- device = amname_to_devname(amdevice);
+ device = amname_to_devname(dle->device);
#ifdef USE_RUNDUMP
amode = F_OK;
#else
#endif
}
}
- else { /* program_is_backup_api==1 */
- pid_t backup_api_pid;
- int property_pipe[2];
+ else { /* program_is_application_api==1 */
+ pid_t application_api_pid;
backup_support_option_t *bsu;
+ int app_err[2];
+ GPtrArray *errarray;
+
+ bsu = backup_support_option(dle->program, g_options, dle->disk,
+ dle->device, &errarray);
+
+ if (!bsu) {
+ char *line;
+ guint i;
+ for (i=0; i < errarray->len; i++) {
+ line = g_ptr_array_index(errarray, i);
+ fprintf(stdout, _("ERROR Application '%s': %s\n"),
+ dle->program, line);
+ amfree(line);
+ }
+ err = vstrallocf(_("Application '%s': can't run support command"),
+ dle->program);
+ goto common_exit;
+ }
- bsu = backup_support_option(program, g_options, disk, amdevice);
+ if (dle->calcsize && !bsu->calcsize) {
+ g_printf("ERROR application %s doesn't support calcsize estimate\n",
+ dle->program);
+ }
+ if (dle->include_file && dle->include_file->nb_element > 0 &&
+ !bsu->include_file) {
+ g_printf("ERROR application %s doesn't support include-file\n",
+ dle->program);
+ }
+ if (dle->include_list && dle->include_list->nb_element > 0 &&
+ !bsu->include_list) {
+ g_printf("ERROR application %s doesn't support include-list\n",
+ dle->program);
+ }
+ if (dle->include_optional && !bsu->include_optional) {
+ g_printf("ERROR application %s doesn't support optional include\n",
+ dle->program);
+ }
+ if (dle->exclude_file && dle->exclude_file->nb_element > 0 &&
+ !bsu->exclude_file) {
+ g_printf("ERROR application %s doesn't support exclude-file\n",
+ dle->program);
+ }
+ if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
+ !bsu->exclude_list) {
+ g_printf("ERROR application %s doesn't support exclude-list\n",
+ dle->program);
+ }
+ if (dle->exclude_optional && !bsu->exclude_optional) {
+ g_printf("ERROR application %s doesn't support optional exclude\n",
+ dle->program);
+ }
+ fflush(stdout);fflush(stderr);
- if (pipe(property_pipe) < 0) {
- err = vstralloc("pipe failed: ", strerror(errno), NULL);
+ if (pipe(app_err) < 0) {
+ err = vstrallocf(_("Application '%s': can't create pipe"),
+ dle->program);
goto common_exit;
}
- fflush(stdout);fflush(stderr);
-
- switch (backup_api_pid = fork()) {
+
+ switch (application_api_pid = fork()) {
case -1:
- err = vstralloc("fork failed: ", strerror(errno), NULL);
+ err = vstrallocf(_("fork failed: %s"), strerror(errno));
goto common_exit;
case 0: /* child */
{
- char *argvchild[14];
- char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
+ char **argvchild, **arg;
+ char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
+ GSList *scriptlist;
+ script_t *script;
+ char *cmdline;
int j=0;
- argvchild[j++] = program;
+ int k;
+
+ aclose(app_err[0]);
+ dup2(app_err[1], 2);
+
+ k = application_property_argv_size(dle);
+ for (scriptlist = dle->scriptlist; scriptlist != NULL;
+ scriptlist = scriptlist->next) {
+ script = (script_t *)scriptlist->data;
+ if (script->result && script->result->proplist) {
+ k += property_argv_size(script->result->proplist);
+ }
+ }
+ argvchild = g_new0(char *, 18 + k);
+ argvchild[j++] = dle->program;
argvchild[j++] = "selfcheck";
if (bsu->message_line == 1) {
argvchild[j++] = "--message";
argvchild[j++] = "--host";
argvchild[j++] = g_options->hostname;
}
- if (disk != NULL && bsu->disk == 1) {
+ if (dle->disk != NULL && bsu->disk == 1) {
argvchild[j++] = "--disk";
- argvchild[j++] = disk;
+ argvchild[j++] = dle->disk;
}
argvchild[j++] = "--device";
- argvchild[j++] = amdevice;
- if(options && options->createindex && bsu->index_line == 1) {
+ argvchild[j++] = dle->device;
+ if (dle->create_index && bsu->index_line == 1) {
argvchild[j++] = "--index";
argvchild[j++] = "line";
}
- if (!options->no_record && bsu->record == 1) {
+ if (dle->record && bsu->record == 1) {
argvchild[j++] = "--record";
}
+ if (dle->calcsize && bsu->calcsize == 1) {
+ argvchild[j++] = "--calcsize";
+ }
+ j += application_property_add_to_argv(&argvchild[j], dle, bsu);
+
+ for (scriptlist = dle->scriptlist; scriptlist != NULL;
+ scriptlist = scriptlist->next) {
+ script = (script_t *)scriptlist->data;
+ if (script->result && script->result->proplist) {
+ j += property_add_to_argv(&argvchild[j],
+ script->result->proplist);
+ }
+ }
+
argvchild[j++] = NULL;
- dup2(property_pipe[0], 0);
- aclose(property_pipe[1]);
- execve(cmd,argvchild,safe_env());
- printf("ERROR [Can't execute %s: %s]\n", cmd, strerror(errno));
+
+ cmdline = stralloc(cmd);
+ for(arg = argvchild; *arg != NULL; arg++) {
+ char *quoted = quote_string(*arg);
+ cmdline = vstrextend(&cmdline, " ", quoted, NULL);
+ amfree(quoted);
+ }
+ dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline);
+ amfree(cmdline);
+
+ safe_fd(-1, 0);
+ execve(cmd, argvchild, safe_env());
+ g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
exit(127);
}
default: /* parent */
{
- int status;
- aclose(property_pipe[0]);
- toolin = fdopen(property_pipe[1],"w");
- if (!toolin) {
- err = vstralloc("Can't fdopen: ", strerror(errno), NULL);
- goto common_exit;
- }
- output_tool_property(toolin, options);
- fflush(toolin);
- fclose(toolin);
- if (waitpid(backup_api_pid, &status, 0) < 0) {
- if (!WIFEXITED(status)) {
- snprintf(number, SIZEOF(number), "%d",
- (int)WTERMSIG(status));
- err = vstralloc("Tool exited with signal ", number,
- NULL);
- } else if (WEXITSTATUS(status) != 0) {
- snprintf(number, SIZEOF(number), "%d",
- (int)WEXITSTATUS(status));
- err = vstralloc("Tool exited with status ", number,
- NULL);
- } else {
- err = stralloc("waitpid returned negative value");
+ int status;
+ FILE *app_stderr;
+ char *line;
+
+ aclose(app_err[1]);
+ app_stderr = fdopen(app_err[0], "r");
+ while((line = agets(app_stderr)) != NULL) {
+ if (strlen(line) > 0) {
+ fprintf(stdout, "ERROR Application '%s': %s\n",
+ dle->program, line);
+ dbprintf("ERROR %s\n", line);
}
+ amfree(line);
+ }
+ if (waitpid(application_api_pid, &status, 0) < 0) {
+ err = vstrallocf(_("waitpid failed: %s"),
+ strerror(errno));
+ goto common_exit;
+ } else if (!WIFEXITED(status)) {
+ err = vstrallocf(_("Application '%s': exited with signal %d"),
+ dle->program, WTERMSIG(status));
+ goto common_exit;
+ } else if (WEXITSTATUS(status) != 0) {
+ err = vstrallocf(_("Application '%s': exited with status %d"),
+ dle->program, WEXITSTATUS(status));
goto common_exit;
}
}
}
qdevice = quote_string(device);
- dbprintf(("%s: device %s\n", debug_prefix_time(NULL), qdevice));
+ dbprintf(_("device %s\n"), qdevice);
/* skip accessability test if this is an AFS entry */
if(strncmp_const(device, "afs:") != 0) {
access_type = "access";
#endif
if(access_result == -1) {
- err = vstralloc("could not ", access_type, " ", qdevice,
- " (", qdisk, "): ", strerror(errno), NULL);
+ err = vstrallocf(_("Could not access %s (%s): %s"),
+ qdevice, qdisk, strerror(errno));
}
#ifdef CHECK_FOR_ACCESS_WITH_OPEN
aclose(access_result);
common_exit:
+ if (!qdevice)
+ qdevice = quote_string(device);
+
amfree(share);
amfree(subdir);
if(user_and_password) {
amfree(domain);
if(err) {
- printf("ERROR [%s]\n", err);
- dbprintf(("%s: %s\n", debug_prefix_time(NULL), err));
+ g_printf(_("ERROR %s\n"), err);
+ dbprintf(_("%s\n"), err);
amfree(err);
} else {
- printf("OK %s\n", qdisk);
- dbprintf(("%s: disk %s OK\n", debug_prefix_time(NULL), qdisk));
- printf("OK %s\n", qamdevice);
- dbprintf(("%s: amdevice %s OK\n",
- debug_prefix_time(NULL), qamdevice));
- printf("OK %s\n", qdevice);
- dbprintf(("%s: device %s OK\n", debug_prefix_time(NULL), qdevice));
+ g_printf("OK %s\n", qdisk);
+ dbprintf(_("disk %s OK\n"), qdisk);
+ g_printf("OK %s\n", qamdevice);
+ dbprintf(_("amdevice %s OK\n"), qamdevice);
+ g_printf("OK %s\n", qdevice);
+ dbprintf(_("device %s OK\n"), qdevice);
}
if(extra_info) {
- dbprintf(("%s: extra info: %s\n", debug_prefix_time(NULL), extra_info));
+ dbprintf(_("extra info: %s\n"), extra_info);
amfree(extra_info);
}
amfree(qdisk);
if( need_runtar )
{
- cmd = vstralloc(libexecdir, "/", "runtar", versionsuffix(), NULL);
+ cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL);
check_file(cmd,X_OK);
check_suid(cmd);
amfree(cmd);
if( need_rundump )
{
- cmd = vstralloc(libexecdir, "/", "rundump", versionsuffix(), NULL);
+ cmd = vstralloc(amlibexecdir, "/", "rundump", versionsuffix(), NULL);
check_file(cmd,X_OK);
check_suid(cmd);
amfree(cmd);
#ifdef DUMP
check_file(DUMP, X_OK);
#else
- printf("ERROR [DUMP program not available]\n");
+ g_printf(_("ERROR [DUMP program not available]\n"));
#endif
}
#ifdef RESTORE
check_file(RESTORE, X_OK);
#else
- printf("ERROR [RESTORE program not available]\n");
+ g_printf(_("ERROR [RESTORE program not available]\n"));
#endif
}
#ifdef VDUMP
check_file(VDUMP, X_OK);
#else
- printf("ERROR [VDUMP program not available]\n");
+ g_printf(_("ERROR [VDUMP program not available]\n"));
#endif
}
#ifdef VRESTORE
check_file(VRESTORE, X_OK);
#else
- printf("ERROR [VRESTORE program not available]\n");
+ g_printf(_("ERROR [VRESTORE program not available]\n"));
#endif
}
#ifdef XFSDUMP
check_file(XFSDUMP, F_OK);
#else
- printf("ERROR [XFSDUMP program not available]\n");
+ g_printf(_("ERROR [XFSDUMP program not available]\n"));
#endif
}
#ifdef XFSRESTORE
check_file(XFSRESTORE, X_OK);
#else
- printf("ERROR [XFSRESTORE program not available]\n");
+ g_printf(_("ERROR [XFSRESTORE program not available]\n"));
#endif
}
#ifdef VXDUMP
check_file(VXDUMP, X_OK);
#else
- printf("ERROR [VXDUMP program not available]\n");
+ g_printf(_("ERROR [VXDUMP program not available]\n"));
#endif
}
#ifdef VXRESTORE
check_file(VXRESTORE, X_OK);
#else
- printf("ERROR [VXRESTORE program not available]\n");
+ g_printf(_("ERROR [VXRESTORE program not available]\n"));
#endif
}
#ifdef GNUTAR
check_file(GNUTAR, X_OK);
#else
- printf("ERROR [GNUTAR program not available]\n");
+ g_printf(_("ERROR [GNUTAR program not available]\n"));
#endif
- need_amandates = 1;
gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
if (strlen(gnutar_list_dir) == 0)
gnutar_list_dir = NULL;
- if (gnutar_list_dir)
+ if (gnutar_list_dir) {
+ /* make sure our listed-incremental dir is ready */
check_dir(gnutar_list_dir, R_OK|W_OK);
+ } else {
+ /* no listed-incremental dir, so check that amandates is ready */
+ need_amandates = 1;
+ }
}
- if (need_amandates) {
- char *amandates_file;
- amandates_file = getconf_str(CNF_AMANDATES);
- check_file(amandates_file, R_OK|W_OK);
- }
if( need_calcsize ) {
char *cmd;
- cmd = vstralloc(libexecdir, "/", "calcsize", versionsuffix(), NULL);
+ cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL);
check_file(cmd, X_OK);
amfree(cmd);
+
+ /* calcsize uses amandates */
+ need_amandates = 1;
+ }
+
+ if (need_amandates) {
+ char *amandates_file;
+ amandates_file = getconf_str(CNF_AMANDATES);
+ check_file(amandates_file, R_OK|W_OK);
}
if( need_samba ) {
#ifdef SAMBA_CLIENT
check_file(SAMBA_CLIENT, X_OK);
#else
- printf("ERROR [SMBCLIENT program not available]\n");
+ g_printf(_("ERROR [SMBCLIENT program not available]\n"));
#endif
testfd = open("/etc/amandapass", R_OK);
if (testfd >= 0) {
if(fstat(testfd, &buf) == 0) {
if ((buf.st_mode & 0x7) != 0) {
- printf("ERROR [/etc/amandapass is world readable!]\n");
+ g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
} else {
- printf("OK [/etc/amandapass is readable, but not by all]\n");
+ g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
}
} else {
- printf("OK [unable to stat /etc/amandapass: %s]\n",
+ g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
strerror(errno));
}
aclose(testfd);
} else {
- printf("ERROR [unable to open /etc/amandapass: %s]\n",
+ g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
strerror(errno));
}
}
check_file(COMPRESS_PATH, X_OK);
if (need_dump || need_xfsdump ) {
- if (check_file_exist("/var/lib/dumpdates")) {
- check_file("/var/lib/dumpdates",
+ if (check_file_exist("/etc/dumpdates")) {
+ check_file("/etc/dumpdates",
#ifdef USE_RUNDUMP
F_OK
#else
} else {
#ifndef USE_RUNDUMP
if (access("/etc", R_OK|W_OK) == -1) {
- printf("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n", strerror(errno));
+ g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
}
#endif
}
check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
#endif
- check_space("/var/lib", (off_t)64); /* for /var/lib/dumpdates writing */
+ check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
}
static void
char * dir,
off_t kbytes)
{
- generic_fs_stats_t statp;
+ struct fs_usage fsusage;
char *quoted = quote_string(dir);
+ intmax_t kb_avail;
- if(get_fs_stats(dir, &statp) == -1) {
- printf("ERROR [cannot statfs %s: %s]\n", quoted, strerror(errno));
- } else if(statp.avail < kbytes) {
- printf("ERROR [dir %s needs " OFF_T_FMT "KB, only has "
- OFF_T_FMT "KB available.]\n", quoted,
- (OFF_T_FMT_TYPE)kbytes,
- (OFF_T_FMT_TYPE)statp.avail);
- } else {
- printf("OK %s has more than " OFF_T_FMT " KB available.\n",
- quoted, (OFF_T_FMT_TYPE)kbytes);
+ if(get_fs_usage(dir, NULL, &fsusage) == -1) {
+ g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
+ amfree(quoted);
+ return;
}
- amfree(quoted);
-}
-static void
-check_access(
- char * filename,
- int mode)
-{
- char *noun, *adjective;
- char *quoted = quote_string(filename);
-
- if(mode == F_OK)
- noun = "find", adjective = "exists";
- else if((mode & X_OK) == X_OK)
- noun = "execute", adjective = "executable";
- else if((mode & (W_OK|R_OK)) == (W_OK|R_OK))
- noun = "read/write", adjective = "read/writable";
- else
- noun = "access", adjective = "accessible";
-
- if(access(filename, mode) == -1)
- printf("ERROR [can not %s %s: %s]\n", noun, quoted, strerror(errno));
- else
- printf("OK %s %s\n", quoted, adjective);
+ /* do the division first to avoid potential integer overflow */
+ kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
+
+ if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
+ g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
+ (long long)kbytes);
+ } else if (kb_avail < kbytes) {
+ g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
+ (long long)kbytes,
+ (long long)kb_avail);
+ } else {
+ g_printf(_("OK %s has more than %lldKB available.\n"),
+ quoted, (long long)kbytes);
+ }
amfree(quoted);
}
return 1;
}
-static void
-check_file(
- char * filename,
- int mode)
-{
- struct stat stat_buf;
- char *quoted;
-
- if(!stat(filename, &stat_buf)) {
- if(!S_ISREG(stat_buf.st_mode)) {
- quoted = quote_string(filename);
- printf("ERROR [%s is not a file]\n", quoted);
- amfree(quoted);
- }
- }
- check_access(filename, mode);
-}
-
-static void
-check_dir(
- char * dirname,
- int mode)
-{
- struct stat stat_buf;
- char *quoted;
- char *dir;
-
- if(!stat(dirname, &stat_buf)) {
- if(!S_ISDIR(stat_buf.st_mode)) {
- quoted = quote_string(dirname);
- printf("ERROR [%s is not a directory]\n", quoted);
- amfree(quoted);
- }
- }
- dir = stralloc2(dirname, "/.");
- check_access(dir, mode);
- amfree(dir);
-}
-
-static void
-check_suid(
- char * filename)
-{
-/* The following is only valid for real Unixs */
-#ifndef IGNORE_UID_CHECK
- struct stat stat_buf;
- char *quoted = quote_string(filename);
-
- if(!stat(filename, &stat_buf)) {
- if(stat_buf.st_uid != 0 ) {
- printf("ERROR [%s is not owned by root]\n", quoted);
- }
- if((stat_buf.st_mode & S_ISUID) != S_ISUID) {
- printf("ERROR [%s is not SUID root]\n", quoted);
- }
- }
- else {
- printf("ERROR [can not stat %s]\n", quoted);
- }
- amfree(quoted);
-#else
- (void)filename; /* Quiet unused parameter warning */
-#endif
-}