Mercurial > masqmail
comparison src/masqmail.c @ 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 |
comparison
equal
deleted
inserted
replaced
249:f9da5a7caeda | 250:a41c013c8458 |
---|---|
285 fprintf(stderr, "Unknown error (%d)\r\n", err); | 285 fprintf(stderr, "Unknown error (%d)\r\n", err); |
286 exit(EXIT_FAILURE); | 286 exit(EXIT_FAILURE); |
287 } | 287 } |
288 exit(EXIT_FAILURE); | 288 exit(EXIT_FAILURE); |
289 } | 289 } |
290 } | |
291 | |
292 /* | |
293 currently only the `rm' command is supported | |
294 until this changes, we don't need any facility for further commands | |
295 return success if at least one message had been deleted | |
296 */ | |
297 static int | |
298 manipulate_queue(char* cmd, char* id[]) | |
299 { | |
300 gboolean ok = FALSE; | |
301 | |
302 if (strcmp(cmd, "rm") != 0) { | |
303 fprintf(stderr, "unknown command %s\n", cmd); | |
304 return FALSE; | |
305 } | |
306 | |
307 set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); | |
308 | |
309 /* privileged users may delete any mail */ | |
310 if (is_privileged_user(conf.orig_uid)) { | |
311 for (; *id; id++) { | |
312 fprintf(stderr, "id: %s\n", *id); | |
313 if (queue_delete(*id)) { | |
314 ok = TRUE; | |
315 } | |
316 } | |
317 return ok; | |
318 } | |
319 | |
320 struct passwd *pw = getpwuid(conf.orig_uid); | |
321 if (!pw) { | |
322 fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", | |
323 conf.orig_uid, strerror(errno)); | |
324 return FALSE; | |
325 } | |
326 | |
327 /* non-privileged users may only delete their own messages */ | |
328 for (; *id; id++) { | |
329 message *msg = msg_spool_read(*id, FALSE); | |
330 | |
331 fprintf(stderr, "id: %s\n", *id); | |
332 | |
333 if (!msg->ident) { | |
334 fprintf(stderr, "message %s does not have an ident\n", *id); | |
335 continue; | |
336 } | |
337 if (strcmp(pw->pw_name, msg->ident) != 0) { | |
338 fprintf(stderr, "you do not own message id %s\n", *id); | |
339 continue; | |
340 } | |
341 | |
342 if ( (msg->received_host || (msg->received_prot != PROT_LOCAL)) | |
343 #ifdef ENABLE_IDENT | |
344 && !is_in_netlist(msg->received_host, conf.ident_trusted_nets) | |
345 #endif | |
346 ) { | |
347 fprintf(stderr, "message %s was not received locally or from a trusted network\n", *id); | |
348 continue; | |
349 } | |
350 | |
351 ok = queue_delete(*id); | |
352 } | |
353 return ok; | |
290 } | 354 } |
291 | 355 |
292 int | 356 int |
293 main(int argc, char *argv[]) | 357 main(int argc, char *argv[]) |
294 { | 358 { |
612 case MODE_BI: | 676 case MODE_BI: |
613 exit(EXIT_SUCCESS); | 677 exit(EXIT_SUCCESS); |
614 break; /* well... */ | 678 break; /* well... */ |
615 | 679 |
616 case MODE_MCMD: | 680 case MODE_MCMD: |
617 if (strcmp(M_cmd, "rm") == 0) { | 681 exit(manipulate_queue(M_cmd, &argv[arg]) ? 0 : 1); |
618 gboolean ok = FALSE; | |
619 | |
620 set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); | |
621 | |
622 if (is_privileged_user(conf.orig_uid)) { | |
623 for (; arg < argc; arg++) { | |
624 if (queue_delete(argv[arg])) | |
625 ok = TRUE; | |
626 } | |
627 } else { | |
628 struct passwd *pw = getpwuid(conf.orig_uid); | |
629 if (pw) { | |
630 for (; arg < argc; arg++) { | |
631 message *msg = msg_spool_read(argv[arg], FALSE); | |
632 #ifdef ENABLE_IDENT | |
633 if (((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) | |
634 || is_in_netlist(msg->received_host, conf.ident_trusted_nets)) | |
635 #else | |
636 if ((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) | |
637 #endif | |
638 { | |
639 if (msg->ident) { | |
640 if (strcmp(pw->pw_name, msg->ident) == 0) { | |
641 if (queue_delete(argv[arg])) | |
642 ok = TRUE; | |
643 } else { | |
644 fprintf(stderr, "you do not own message id %s\n", argv[arg]); | |
645 } | |
646 } else | |
647 fprintf(stderr, "message %s does not have an ident.\n", argv[arg]); | |
648 } else { | |
649 fprintf(stderr, "message %s was not received locally or from a trusted network.\n", argv[arg]); | |
650 } | |
651 } | |
652 } else { | |
653 fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", conf.orig_uid, strerror(errno)); | |
654 } | |
655 } | |
656 exit(ok ? EXIT_SUCCESS : EXIT_FAILURE); | |
657 } else { | |
658 fprintf(stderr, "unknown command %s\n", M_cmd); | |
659 exit(EXIT_FAILURE); | |
660 } | |
661 break; | 682 break; |
662 | 683 |
663 case MODE_ACCEPT: | 684 case MODE_ACCEPT: |
664 { | 685 { |
665 guint accept_flags = (opt_t ? ACC_DEL_RCPTS | ACC_RCPT_FROM_HEAD : 0) | 686 guint accept_flags = (opt_t ? ACC_DEL_RCPTS | ACC_RCPT_FROM_HEAD : 0) |