235 #include <sys/stat.h>
240 #include <sysexits.h>
308 #define PQ_MODE_DEFAULT 0
309 #define PQ_MODE_MAILQ_LIST 1
310 #define PQ_MODE_FLUSH_QUEUE 2
311 #define PQ_MODE_FLUSH_SITE 3
312 #define PQ_MODE_FLUSH_FILE 4
313 #define PQ_MODE_JSON_LIST 5
318 #define STR vstring_str
334 static void show_queue(
int mode)
339 uid_t uid = getuid();
345 "User %s(%ld) is not allowed to view the mail queue",
360 msg_panic(
"show_queue: unknown mode %d", mode);
370 else if (errno == EACCES) {
372 "Connect to the %s %s service: %m",
380 else if (geteuid() == 0) {
385 msg_warn(
"Mail system is down -- accessing queue directly");
389 argv_add(argv, showq_path,
"-u",
"-S", (
char *) 0);
406 msg_panic(
"show_queue: unknown mode %d", mode);
413 "Error running %s", showq_path);
425 "Queue report unavailable - mail system is down");
431 static void flush_queue(
void)
434 uid_t uid = getuid();
440 "User %s(%ld) is not allowed to flush the mail queue",
448 "Cannot flush mail queue - mail system is down");
451 "Cannot flush mail queue - mail system is down");
457 static void flush_site(
const char *site)
461 uid_t uid = getuid();
467 "User %s(%ld) is not allowed to flush the mail queue",
479 "Cannot flush mail queue - mail system is down");
482 "Flush service is not configured for destination \"%s\"",
486 "Unknown flush server reply status %d", status);
492 static void flush_file(
const char *queue_id)
496 uid_t uid = getuid();
502 "User %s(%ld) is not allowed to flush the mail queue",
512 "Cannot flush mail queue - mail system is down");
515 "Unexpected flush server reply status %d", status);
521 static void unavailable(
void)
530 msg_fatal_status(
EX_USAGE,
"usage: postqueue -f | postqueue -i queueid | postqueue -j | postqueue -p | postqueue -s site");
537 int main(
int argc,
char **argv)
544 char *site_to_flush = 0;
545 char *id_to_flush = 0;
564 for (fd = 0; fd < 3; fd++)
565 if (
fstat(fd, &st) == -1
566 && (close(fd), open(
"/dev/null", O_RDWR, 0)) != fd)
575 argv[0] =
"postqueue";
592 while ((c =
GETOPT(argc, argv,
"c:fi:jps:v")) > 0) {
607 id_to_flush = optarg;
623 site_to_flush = optarg;
657 signal(SIGPIPE, SIG_IGN);
664 if (site_to_flush != 0) {
666 if (*site_to_flush ==
'[') {
673 "Cannot flush mail queue - invalid destination: \"%.100s%s\"",
674 site_to_flush, strlen(site_to_flush) > 100 ?
"..." :
"");
676 if (id_to_flush != 0) {
679 "Cannot flush queue ID - invalid name: \"%.100s%s\"",
680 id_to_flush, strlen(id_to_flush) > 100 ?
"..." :
"");
688 msg_panic(
"unknown operation mode: %d", mode);
696 flush_site(site_to_flush);
700 flush_file(id_to_flush);
const char * mail_task(const char *argv0)
char * mystrdup(const char *str)
char * var_import_environ
int mail_queue_id_ok(const char *queue_id)
void set_mail_conf_str(const char *, const char *)
ARGV * argv_free(ARGV *argvp)
#define VAR_IMPORT_ENVIRON
NORETURN msg_panic(const char *fmt,...)
VSTREAM * mail_connect(const char *class, const char *name, int block_mode)
#define PQ_MODE_FLUSH_FILE
#define CA_VSTREAM_POPEN_ARGV(v)
void argv_add(ARGV *argvp,...)
#define PQ_MODE_FLUSH_QUEUE
ARGV * argv_alloc(ssize_t len)
void mail_conf_read(void)
int vstream_pclose(VSTREAM *)
void clean_env(char **preserve_list)
int valid_hostname(const char *name, int gripe)
#define MAIL_CLASS_PUBLIC
MAIL_VERSION_STAMP_DECLARE
ARGV * mail_parm_split(const char *name, const char *value)
int valid_mailhost_literal(const char *addr, int gripe)
int vstream_fclose(VSTREAM *stream)
void msg_warn(const char *fmt,...)
int mail_flush_deferred(void)
void mail_dict_init(void)
#define CA_VSTREAM_POPEN_END
#define PQ_MODE_JSON_LIST
int flush_send_file(const char *queue_id)
int mail_flush_maildrop(void)
#define MAIL_VERSION_STAMP_ALLOCATE
void get_mail_conf_str_table(const CONFIG_STR_TABLE *)
void showq_json(VSTREAM *)
#define MAIL_VERSION_CHECK
char * concatenate(const char *arg0,...)
#define GETOPT(argc, argv, str)
void msg_syslog_init(const char *name, int logopt, int facility)
#define PQ_MODE_MAILQ_LIST
int main(int argc, char **argv)
#define PQ_MODE_FLUSH_SITE
const char * check_user_acl_byuid(const char *pname, const char *acl, uid_t uid)
void msg_vstream_init(const char *name, VSTREAM *vp)
void event_drain(int time_limit)
NORETURN msg_fatal_status(int status, const char *fmt,...)
VSTREAM VSTREAM const char VSTREAM * vstream_popen(int,...)
void showq_compat(VSTREAM *)
MSG_CLEANUP_FN msg_cleanup(MSG_CLEANUP_FN cleanup_fn)
int flush_send_site(const char *site)
void argv_terminate(ARGV *argvp)