1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*++
/* NAME
/* hold_message 3
/* SUMMARY
/* move message to hold queue
/* SYNOPSIS
/* #include <hold_message.h>
/*
/* int hold_message(path_buf, queue_name, queue_id)
/* VSTRING *path_buf;
/* const char *queue_name;
/* const char *queue_id;
/* DESCRIPTION
/* The \fBhold_message\fR() routine moves the specified
/* queue file to the \fBhold\fR queue, where it will sit
/* until someone either destroys it or releases it.
/*
/* Arguments:
/* .IP path_buf
/* A null pointer, or storage for the new pathname.
/* .IP queue_name
/* Queue name with the message that needs to be placed on hold.
/* .IP queue_id
/* Queue file name with the message that needs to be placed on hold.
/* DIAGNOSTICS
/* The result is -1 in case of failure, 0 in case of success.
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*--*/
/* System library. */
#include <sys_defs.h>
#include <stdio.h> /* rename() */
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
/* Utility library. */
#include <msg.h>
#include <set_eugid.h>
#include <sane_fsops.h>
/* Global library. */
#include <mail_queue.h>
#include <mail_params.h>
#include <hold_message.h>
#define STR(x) vstring_str(x)
/* hold_message - move message to hold queue */
int hold_message(VSTRING *path_buf, const char *queue_name,
const char *queue_id)
{
VSTRING *old_path = vstring_alloc(100);
VSTRING *new_path = 0;
uid_t saved_uid;
gid_t saved_gid;
int err;
/*
* If not running as the mail system, change privileges first.
*/
if ((saved_uid = geteuid()) != var_owner_uid) {
saved_gid = getegid();
set_eugid(var_owner_uid, var_owner_gid);
}
/*
* Your buffer or mine?
*/
if (path_buf == 0)
new_path = path_buf = vstring_alloc(100);
/*
* This code duplicates mail_queue_rename(), except that it also returns
* the result pathname to the caller.
*/
(void) mail_queue_path(old_path, queue_name, queue_id);
(void) mail_queue_path(path_buf, MAIL_QUEUE_HOLD, queue_id);
if ((err = sane_rename(STR(old_path), STR(path_buf))) == 0
|| ((err = mail_queue_mkdirs(STR(path_buf)) == 0)
&& (err = sane_rename(STR(old_path), STR(path_buf))) == 0)) {
if (msg_verbose)
msg_info("%s: placed on hold", queue_id);
}
/*
* Restore privileges.
*/
if (saved_uid != var_owner_uid)
set_eugid(saved_uid, saved_gid);
/*
* Cleanup.
*/
vstring_free(old_path);
if (new_path)
vstring_free(new_path);
return (err);
}
|