masqmail
changeset 250:a41c013c8458
moved the queue manipulation code to an new function
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 04 Nov 2010 12:32:11 -0300 |
parents | f9da5a7caeda |
children | 2babd21e7c75 |
files | src/masqmail.c |
diffstat | 1 files changed, 65 insertions(+), 44 deletions(-) [+] |
line diff
1.1 --- a/src/masqmail.c Thu Nov 04 11:02:42 2010 -0300 1.2 +++ b/src/masqmail.c Thu Nov 04 12:32:11 2010 -0300 1.3 @@ -289,6 +289,70 @@ 1.4 } 1.5 } 1.6 1.7 +/* 1.8 +currently only the `rm' command is supported 1.9 +until this changes, we don't need any facility for further commands 1.10 +return success if at least one message had been deleted 1.11 +*/ 1.12 +static int 1.13 +manipulate_queue(char* cmd, char* id[]) 1.14 +{ 1.15 + gboolean ok = FALSE; 1.16 + 1.17 + if (strcmp(cmd, "rm") != 0) { 1.18 + fprintf(stderr, "unknown command %s\n", cmd); 1.19 + return FALSE; 1.20 + } 1.21 + 1.22 + set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); 1.23 + 1.24 + /* privileged users may delete any mail */ 1.25 + if (is_privileged_user(conf.orig_uid)) { 1.26 + for (; *id; id++) { 1.27 + fprintf(stderr, "id: %s\n", *id); 1.28 + if (queue_delete(*id)) { 1.29 + ok = TRUE; 1.30 + } 1.31 + } 1.32 + return ok; 1.33 + } 1.34 + 1.35 + struct passwd *pw = getpwuid(conf.orig_uid); 1.36 + if (!pw) { 1.37 + fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", 1.38 + conf.orig_uid, strerror(errno)); 1.39 + return FALSE; 1.40 + } 1.41 + 1.42 + /* non-privileged users may only delete their own messages */ 1.43 + for (; *id; id++) { 1.44 + message *msg = msg_spool_read(*id, FALSE); 1.45 + 1.46 + fprintf(stderr, "id: %s\n", *id); 1.47 + 1.48 + if (!msg->ident) { 1.49 + fprintf(stderr, "message %s does not have an ident\n", *id); 1.50 + continue; 1.51 + } 1.52 + if (strcmp(pw->pw_name, msg->ident) != 0) { 1.53 + fprintf(stderr, "you do not own message id %s\n", *id); 1.54 + continue; 1.55 + } 1.56 + 1.57 + if ( (msg->received_host || (msg->received_prot != PROT_LOCAL)) 1.58 +#ifdef ENABLE_IDENT 1.59 + && !is_in_netlist(msg->received_host, conf.ident_trusted_nets) 1.60 +#endif 1.61 + ) { 1.62 + fprintf(stderr, "message %s was not received locally or from a trusted network\n", *id); 1.63 + continue; 1.64 + } 1.65 + 1.66 + ok = queue_delete(*id); 1.67 + } 1.68 + return ok; 1.69 +} 1.70 + 1.71 int 1.72 main(int argc, char *argv[]) 1.73 { 1.74 @@ -614,50 +678,7 @@ 1.75 break; /* well... */ 1.76 1.77 case MODE_MCMD: 1.78 - if (strcmp(M_cmd, "rm") == 0) { 1.79 - gboolean ok = FALSE; 1.80 - 1.81 - set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); 1.82 - 1.83 - if (is_privileged_user(conf.orig_uid)) { 1.84 - for (; arg < argc; arg++) { 1.85 - if (queue_delete(argv[arg])) 1.86 - ok = TRUE; 1.87 - } 1.88 - } else { 1.89 - struct passwd *pw = getpwuid(conf.orig_uid); 1.90 - if (pw) { 1.91 - for (; arg < argc; arg++) { 1.92 - message *msg = msg_spool_read(argv[arg], FALSE); 1.93 -#ifdef ENABLE_IDENT 1.94 - if (((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) 1.95 - || is_in_netlist(msg->received_host, conf.ident_trusted_nets)) 1.96 -#else 1.97 - if ((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) 1.98 -#endif 1.99 - { 1.100 - if (msg->ident) { 1.101 - if (strcmp(pw->pw_name, msg->ident) == 0) { 1.102 - if (queue_delete(argv[arg])) 1.103 - ok = TRUE; 1.104 - } else { 1.105 - fprintf(stderr, "you do not own message id %s\n", argv[arg]); 1.106 - } 1.107 - } else 1.108 - fprintf(stderr, "message %s does not have an ident.\n", argv[arg]); 1.109 - } else { 1.110 - fprintf(stderr, "message %s was not received locally or from a trusted network.\n", argv[arg]); 1.111 - } 1.112 - } 1.113 - } else { 1.114 - fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", conf.orig_uid, strerror(errno)); 1.115 - } 1.116 - } 1.117 - exit(ok ? EXIT_SUCCESS : EXIT_FAILURE); 1.118 - } else { 1.119 - fprintf(stderr, "unknown command %s\n", M_cmd); 1.120 - exit(EXIT_FAILURE); 1.121 - } 1.122 + exit(manipulate_queue(M_cmd, &argv[arg]) ? 0 : 1); 1.123 break; 1.124 1.125 case MODE_ACCEPT: