1 /* $NetBSD: mark_corrupt.c,v 1.1.1.1 2009/06/23 10:08:47 tron Exp $ */
2
3 /*++
4 /* NAME
5 /* mark_corrupt 3
6 /* SUMMARY
7 /* mark queue file as corrupt
8 /* SYNOPSIS
9 /* #include <mark_corrupt.h>
10 /*
11 /* char *mark_corrupt(src)
12 /* VSTREAM *src;
13 /* DESCRIPTION
14 /* The \fBmark_corrupt\fR() routine marks the specified open
15 /* queue file as corrupt, and returns a suitable delivery status
16 /* so that the queue manager will do the right thing.
17 /* LICENSE
18 /* .ad
19 /* .fi
20 /* The Secure Mailer license must be distributed with this software.
21 /* AUTHOR(S)
22 /* Wietse Venema
23 /* IBM T.J. Watson Research
24 /* P.O. Box 704
25 /* Yorktown Heights, NY 10598, USA
26 /*--*/
27
28 /* System library. */
29
30 #include <sys_defs.h>
31 #include <sys/stat.h>
32 #include <unistd.h>
33
34 /* Utility library. */
35
36 #include <msg.h>
37 #include <vstream.h>
38 #include <set_eugid.h>
39
40 /* Global library. */
41
42 #include <mail_queue.h>
43 #include <mail_params.h>
44 #include <deliver_request.h>
45 #include <mark_corrupt.h>
46
47 /* mark_corrupt - mark queue file as corrupt */
48
mark_corrupt(VSTREAM * src)49 int mark_corrupt(VSTREAM *src)
50 {
51 const char *myname = "mark_corrupt";
52 uid_t saved_uid;
53 gid_t saved_gid;
54
55 /*
56 * If not running as the mail system, change privileges first.
57 */
58 if ((saved_uid = geteuid()) != var_owner_uid) {
59 saved_gid = getegid();
60 set_eugid(var_owner_uid, var_owner_gid);
61 }
62
63 /*
64 * For now, the result value is -1; this may become a bit mask, or
65 * something even more advanced than that, when the delivery status
66 * becomes more than just done/deferred.
67 */
68 msg_warn("corrupted queue file: %s", VSTREAM_PATH(src));
69 if (fchmod(vstream_fileno(src), MAIL_QUEUE_STAT_CORRUPT))
70 msg_fatal("%s: fchmod %s: %m", myname, VSTREAM_PATH(src));
71
72 /*
73 * Restore privileges.
74 */
75 if (saved_uid != var_owner_uid)
76 set_eugid(saved_uid, saved_gid);
77
78 return (DEL_STAT_DEFER);
79 }
80