diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-05-13 15:21:02 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-05-13 15:21:02 +0000 |
commit | 113cb4b143f63e18f2cbab9f0abec0ef453fbbd8 (patch) | |
tree | 8d8ccc1d6196e5570953033cbed3189a8111196a /src/main.c | |
parent | 06aae065b5b5ccf3ae1e4350f97d0ed0a2658501 (diff) | |
download | mailfromd-113cb4b143f63e18f2cbab9f0abec0ef453fbbd8.tar.gz mailfromd-113cb4b143f63e18f2cbab9f0abec0ef453fbbd8.tar.bz2 |
Mailfromd goes international
git-svn-id: file:///svnroot/mailfromd/trunk@1428 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 106 |
1 files changed, 57 insertions, 49 deletions
@@ -243,13 +243,13 @@ read_domain_file(char *name) FILE *fp; char buf[256]; char *p; fp = fopen(name, "r"); if (!fp) { - mu_error("Cannot open file `%s': %s", + mu_error(_("Cannot open file `%s': %s"), name, mu_strerror(errno)); return; } if (!domain_list) { mu_list_create(&domain_list); @@ -378,13 +378,13 @@ option_mailfrom(char *opt, void **pval, char *newval) "option --mailfrom is deprecated, consider using " "`-v mailfrom_address=\"%s\"' instead", (char*) newval); rc = mu_address_create(&addr, newval); if (rc) { - mu_error("Cannot create address `%s': %s", + mu_error(_("Cannot create address `%s': %s"), newval, mu_strerror(rc)); return 1; } mu_address_destroy(&addr); return option_string(opt, pval, newval); } @@ -398,13 +398,13 @@ set_mailfrom(void *value) /* FIXME-MU: compensate for mailutils deficiency */ if (*(char*)value == 0) value = DEFAULT_FROM_ADDRESS; rc = mu_address_create(&addr, value); if (rc) { - mu_error("Cannot create address `%s': %s", + mu_error(_("Cannot create address `%s': %s"), value, mu_strerror(rc)); return; } mu_address_destroy(&addr); defer_initialize_variable("mailfrom_address", value); } @@ -461,13 +461,13 @@ set_user(void *value) static void set_milter_timeout(void *value) { time_t to = *(time_t*) value; free(value); if (smfi_settimeout(to) == MI_FAILURE) { - mu_error("Invalid milter timeout: %lu", (unsigned long) to); + mu_error(_("Invalid milter timeout: %lu"), (unsigned long) to); exit(EX_USAGE); } } static void set_pidfile(void *value) @@ -604,13 +604,13 @@ option_debug(char *opt, void **pval, char *newval) static int option_time(char *opt, void **pval, char *newval) { time_t interval; const char *endp; if (parse_time_interval(newval, &interval, &endp)) { - mu_error("%s: unrecognized time format (near `%s')", + mu_error(_("%s: unrecognized time format (near `%s')"), opt, endp); return 1; } if (!*pval) *pval = xmalloc(sizeof(time_t)); *(time_t*) *pval = interval; @@ -618,13 +618,13 @@ option_time(char *opt, void **pval, char *newval) } static int option_pidfile(char *opt, void **pval, char *newval) { if (newval[0] != '/') { - mu_error("Invalid pidfile name: must be absolute"); + mu_error(_("Invalid pidfile name: must be absolute")); return 1; } return option_string(opt, pval, newval); } static int @@ -640,13 +640,13 @@ static int option_source(char *opt, void **pval, char *newval) { unsigned long address = inet_addr (newval); if (address == INADDR_NONE) { struct hostent *phe = gethostbyname (newval); if (!phe) { - mu_error("Cannot resolve `%s'", newval); + mu_error(_("Cannot resolve `%s'"), newval); return 1; } address = *(((unsigned long **) phe->h_addr_list)[0]); } if (*pval == 0) { @@ -669,21 +669,21 @@ option_group(char *opt, void **pval, char *newval) { struct group *group = getgrnam(newval); if (group) { if (!retain_groups) { int rc = mu_list_create(&retain_groups); if (rc) { - mu_error("Cannot create list: %s", + mu_error(_("Cannot create list: %s"), mu_strerror(rc)); return 1; } mu_list_set_comparator(retain_groups, gid_comp); } mu_list_append(retain_groups, (void*)group->gr_gid); } else { - mu_error("Unknown group: %s", newval); + mu_error(_("Unknown group: %s"), newval); return 1; } return 0; } void @@ -694,23 +694,23 @@ set_state_directory(void *value) int option_state_directory(char *opt, void **pval, char *newval) { struct stat st; if (stat(newval, &st)) { - mu_error("cannot stat file `%s': %s", + mu_error(_("Cannot stat file `%s': %s"), newval, mu_strerror(errno)); return 1; } if (!S_ISDIR(st.st_mode)) { - mu_error("`%s' is not a directory", newval); + mu_error(_("`%s' is not a directory"), newval); return 1; } if (newval[0] != '/') { - mu_error("state directory `%s' is not an absolute file name", + mu_error(_("State directory `%s' is not an absolute file name"), newval); return 1; } mailfromd_state_dir = xstrdup(newval); return 0; } @@ -787,13 +787,13 @@ process_options() } /* Command line parsing */ const char *program_version = "mailfromd (" PACKAGE_STRING ")"; -static char doc[] = N_("mailfromd -- MAIL FROM milter checker"); +static char doc[] = N_("mailfromd -- a general purpose milter daemon"); static char args_doc[] = "[var=value...][SCRIPT]"; enum mailfromd_option { OPTION_ALL = 256, OPTION_COMPACT, OPTION_CONFIG_FILE, @@ -836,18 +836,18 @@ static struct argp_option options[] = { #define GRP 0 { NULL, 0, NULL, 0, N_("Operation modifiers"), GRP }, { "delete", OPTION_DELETE, NULL, 0, N_("Delete given entries from the database"), GRP+1 }, { "list", OPTION_LIST, NULL, 0, - N_("List cache (default) or rates database"), GRP+1 }, + N_("List given database (default cache)"), GRP+1 }, { "expire", OPTION_EXPIRE, NULL, 0, - N_("Delete expired entries from the cache"), GRP+1 }, + N_("Delete expired entries from the database"), GRP+1 }, { "compact", OPTION_COMPACT, NULL, 0, N_("Compact the database"), GRP+1 }, - { "test", 't', N_("state"), OPTION_ARG_OPTIONAL, + { "test", 't', N_("HANDLER"), OPTION_ARG_OPTIONAL, N_("Run in test mode"), GRP+1 }, { "lint", OPTION_LINT, NULL, 0, N_("Check syntax and exit"), GRP+1 }, { "syntax-check", 0, NULL, OPTION_ALIAS, NULL, GRP+1 }, { "show-defaults", OPTION_SHOW_DEFAULTS, NULL, 0, N_("Show compilation defaults"), GRP+1 }, @@ -872,20 +872,20 @@ static struct argp_option options[] = { GRP+1 }, { "format", 'H', N_("FORMAT"), 0, N_("Format of the DB file to operate upon"), GRP+1 }, { "ignore-failed-reads", OPTION_IGNORE_FAILED_READS, NULL, 0, N_("Ignore failed reads while compacting the database"), GRP+1 }, { "predict", OPTION_PREDICT_NEXT, N_("RATE"), 0, - N_("Predict when the user will be able to " - "send next message (use with --list --format=rate)"), GRP+1 }, + N_("Predict when the user will be able to send next message"), + GRP+1 }, { "lock-retry-count", OPTION_LOCK_RETRY_COUNT, N_("NUMBER"), 0, N_("Set maximum number of attempts to acquire the lock"), GRP+1 }, { "lock-retry-timeout", OPTION_LOCK_RETRY_TIMEOUT, N_("TIME"), 0, N_("Set timeout for acquiring the lockfile"), GRP+1 }, { "expire-interval", 'e', N_("NUMBER"), 0, - N_("Set cache expiration interval to NUMBER seconds"), GRP+1 }, + N_("Set database expiration interval to NUMBER seconds"), GRP+1 }, { "all", OPTION_ALL, NULL, 0, N_("With --compact or --expire: apply the operation to all " "available databases"), GRP+1 }, { "time-format", OPTION_TIME_FORMAT, N_("FMT"), 0, N_("Output timestamps using given format (default \"%c\")"), GRP+1 }, @@ -895,13 +895,13 @@ static struct argp_option options[] = { N_("General options"), GRP }, { "state-directory", OPTION_STATE_DIRECTORY, N_("DIR"), 0, N_("Set new program state directory"), GRP+1 }, { "config-file", OPTION_CONFIG_FILE, N_("FILE"), OPTION_HIDDEN, N_("Read configuration from FILE"), GRP+1 }, { "include", 'I', N_("DIR"), 0, - N_("Add the directory dir to the list of directories to be " + N_("Add the directory DIR to the list of directories to be " "searched for header files"), GRP+1 }, { "port", 'p', N_("STRING"), 0, N_("Set communication socket"), GRP+1 }, { "remove", 'r', NULL, 0, N_("Force removing local socket file, if it already exists"), GRP+1 }, @@ -922,24 +922,24 @@ static struct argp_option options[] = { { "source", 'S', N_("ADDRESS"), 0, N_("Set source address for TCP connections"), GRP+1 }, { "optimize", 'O', N_("LEVEL"), OPTION_ARG_OPTIONAL, N_("Set code optimization level"), GRP+1 }, { "variable", 'v', N_("VAR=VALUE"), 0, N_("Assign VALUE to VAR"), GRP+1 }, + { "relayed-domain-file", OPTION_DOMAIN_FILE, N_("FILE"), 0, + N_("Read relayed domains from FILE"), GRP+1 }, #undef GRP #undef GRP #define GRP 30 { NULL, 0, NULL, 0, N_("Timeout control"), GRP }, - { "milter-timeout", OPTION_MILTER_TIMEOUT, N_("NUMBER"), 0, + { "milter-timeout", OPTION_MILTER_TIMEOUT, N_("TIME"), 0, N_("Set MTA connection timeout"), GRP+1 }, - { "timeout", OPTION_TIMEOUT, N_("NUMBER"), 0, - N_("Set I/O operation timeout (seconds)"), GRP+1 }, - { "relayed-domain-file", OPTION_DOMAIN_FILE, N_("FILE"), 0, - N_("Read relayed domains from FILE"), GRP+1 }, + { "timeout", OPTION_TIMEOUT, N_("TIME"), 0, + N_("Set I/O operation timeout"), GRP+1 }, #undef GRP #define GRP 40 { NULL, 0, NULL, 0, N_("Informational and debugging options"), GRP }, { "transcript", 'X', NULL, 0, @@ -997,17 +997,17 @@ static struct argp_option options[] = { static int validate_options() { if (all_option && !(mode == MAILFROMD_COMPACT || mode == MAILFROMD_EXPIRE)) { - mu_error("--all is meaningful only with --expire or --compact option"); + mu_error(_("--all is meaningful only with --expire or --compact option")); return 1; } if (all_option && format_option) - mu_error("--format is incompatible with --all"); + mu_error(_("--format is incompatible with --all")); return 0; } static error_t parse_opt (int key, char *arg, struct argp_state *state) @@ -1041,12 +1041,13 @@ parse_opt (int key, char *arg, struct argp_state *state) case OPTION_ALL: all_option = 1; break; case OPTION_CONFIG_FILE: + /*DEPRECATION*/ mu_error("Warning: --config-file is obsolete; give the filter script name as an argument"); script_file = arg; break; case OPTION_IGNORE_FAILED_READS: ignore_failed_reads_option = 1; @@ -1325,13 +1326,13 @@ switch_to_privs(uid_t uid, gid_t gid) int rc = 0; gid_t *emptygidset; size_t size = 1, j = 1; mu_iterator_t itr; if (uid == 0) { - mu_error("Refusing to run as root"); + mu_error(_("Refusing to run as root")); return 1; } /* Create a list of supplementary groups */ mu_list_count (retain_groups, &size); size++; @@ -1344,46 +1345,46 @@ switch_to_privs(uid_t uid, gid_t gid) mu_iterator_current (itr, (void **)(emptygidset + j++)); mu_iterator_destroy(&itr); } /* Reset group permissions */ if (geteuid() == 0 && setgroups(j, emptygidset)) { - mu_error("setgroups(1, %lu) failed: %s", + mu_error(_("setgroups(1, %lu) failed: %s"), (unsigned long) emptygidset[0], mu_strerror(errno)); rc = 1; } free(emptygidset); /* Switch to the user's gid. On some OSes the effective gid must be reset first */ #if defined(HAVE_SETEGID) if ((rc = setegid(gid)) < 0) - mu_error("setegid(%lu) failed: %s", + mu_error(_("setegid(%lu) failed: %s"), (unsigned long) gid, mu_strerror(errno)); #elif defined(HAVE_SETREGID) if ((rc = setregid(gid, gid)) < 0) - mu_error("setregid(%lu,%lu) failed: %s", + mu_error(_("setregid(%lu,%lu) failed: %s"), (unsigned long) gid, (unsigned long) gid, mu_strerror(errno)); #elif defined(HAVE_SETRESGID) if ((rc = setresgid(gid, gid, gid)) < 0) - mu_error("setresgid(%lu,%lu,%lu) failed: %s", + mu_error(_("setresgid(%lu,%lu,%lu) failed: %s"), (unsigned long) gid, (unsigned long) gid, (unsigned long) gid, mu_strerror(errno)); #endif if (rc == 0 && gid != 0) { if ((rc = setgid(gid)) < 0 && getegid() != gid) - mu_error("setgid(%lu) failed: %s", + mu_error(_("setgid(%lu) failed: %s"), (unsigned long) gid, mu_strerror(errno)); if (rc == 0 && getegid() != gid) { - mu_error("Cannot set effective gid to %lu", + mu_error(_("Cannot set effective gid to %lu"), (unsigned long) gid); rc = 1; } } /* Now reset uid */ @@ -1395,39 +1396,39 @@ switch_to_privs(uid_t uid, gid_t gid) || (getuid() != uid && (geteuid() == 0 || getuid() == 0))) { #if defined(HAVE_SETREUID) if (geteuid() != uid) { if (setreuid(uid, -1) < 0) { - mu_error("setreuid(%lu,-1) failed", + mu_error(_("setreuid(%lu,-1) failed"), (unsigned long) uid, mu_strerror(errno)); rc = 1; } if (setuid(uid) < 0) { - mu_error("second setuid(%lu) failed", + mu_error(_("second setuid(%lu) failed"), (unsigned long) uid, mu_strerror(errno)); rc = 1; } } else #endif { - mu_error("setuid(%lu) failed", + mu_error(_("setuid(%lu) failed"), (unsigned long) uid, mu_strerror(errno)); rc = 1; } } euid = geteuid(); if (uid != 0 && setuid(0) == 0) { - mu_error("seteuid(0) succeeded when it should not"); + mu_error(_("seteuid(0) succeeded when it should not")); rc = 1; } else if (uid != euid && setuid(euid) == 0) { - mu_error("Cannot drop non-root setuid privileges"); + mu_error(_("Cannot drop non-root setuid privileges")); rc = 1; } } return rc; @@ -1435,44 +1436,44 @@ switch_to_privs(uid_t uid, gid_t gid) void priv_setup() { if (getuid() == 0) { if (!user) { - mu_error("When running as root, --user option is mandatory."); + mu_error(_("When running as root, --user option is mandatory.")); exit(EX_USAGE); } else { struct passwd *pw = getpwnam(user); if (!pw) { - mu_error("No such user: %s", user); + mu_error(_("No such user: %s"), user); exit(EX_SOFTWARE); } if (pw && switch_to_privs(pw->pw_uid, pw->pw_gid)) exit(EX_SOFTWARE); } } } void assert_db_format() { if (!format_option) { - mu_error("Operation is not applicable"); + mu_error(_("Operation is not applicable")); exit(EX_USAGE); } } char * get_db_name() { assert_db_format(); if (file_option) return file_option; if (format_option->dbname) return format_option->dbname; - mu_error("Database file name is not given"); + mu_error(_("Database file name is not given")); exit(EX_USAGE); } void init_names() { @@ -1568,13 +1569,13 @@ mailfromd_list(int argc, char **argv) { int rc; char *name = get_db_name(); if (!format_option->print_item) { /* Should not happen */ - mu_error("List is not applicable to this DB format"); + mu_error(_("List is not applicable to this DB format")); exit(EX_USAGE); } rc = 0; if (argc) { int i; @@ -1602,13 +1603,13 @@ mailfromd_expire() { priv_setup(); if (all_option) db_format_enumerate(db_proc_enumerator, db_expire); else { if (!format_option->expire) { - mu_error("Expire is not applicable to this DB format"); + mu_error(_("Expire is not applicable to this DB format")); exit(EX_USAGE); } exit(db_expire(get_db_name(), format_option->expire) != 0); } } @@ -1617,13 +1618,13 @@ mailfromd_compact() { priv_setup(); if (all_option) db_format_enumerate(db_proc_enumerator, db_compact); else { if (!format_option->expire) { - mu_error("Compact is not applicable to this DB format"); + mu_error(_("Compact is not applicable to this DB format")); exit(EX_USAGE); } exit(db_compact(get_db_name(), format_option->expire) != 0); } } @@ -1708,12 +1709,19 @@ version(FILE *stream, struct argp_state *state) int main(int argc, char **argv) { int index; +#ifdef ENABLE_NLS + mu_init_nls(); + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); +#endif + MU_AUTH_REGISTER_ALL_MODULES(); mu_register_all_mailer_formats(); if (!program_invocation_short_name) program_invocation_short_name = argv[0]; argp_program_version_hook = version; @@ -1740,15 +1748,15 @@ main(int argc, char **argv) int i, n = -1; for (i = 0; i < argc; i++) { if (strchr(argv[i], '=') == 0) { if (n == -1) n = i; else { - mu_error("Script file " + mu_error(_("Script file " "specified twice " - "(%s and %s)", + "(%s and %s)"), argv[n], argv[i]); exit(EX_USAGE); } } } if (n >= 0) { @@ -1796,13 +1804,13 @@ main(int argc, char **argv) case MAILFROMD_COMPACT: mailfromd_compact(); break; case MAILFROMD_DAEMON: if (argc > 0) { - mu_error("Too many arguments"); + mu_error(_("Too many arguments")); exit(EX_USAGE); } mailfromd_daemon(); break; case MAILFROMD_TEST: |