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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
only in patch2:
unchanged:
--- qpopper-4.0.4.orig/popper/pop_config.c
+++ qpopper-4.0.4/popper/pop_config.c
@@ -85,6 +85,7 @@
#include <string.h>
#include <errno.h>
#include <ctype.h>
+#include <unistd.h>
#include <limits.h>
#ifdef QPOP_OPENSSL
@@ -1487,6 +1488,8 @@
int rslt;
char buf [ 256 ];
struct stat stat_buf;
+ BOOL bUser = FALSE;
+ BOOL bSpool = FALSE;
if ( p->bUser_opts ) {
@@ -1497,14 +1500,8 @@
p->user );
else {
rslt = stat ( buf, &stat_buf );
- if ( rslt == 0 ) {
- rslt = pop_config ( p, buf, CfgUser );
- if ( rslt == POP_FAILURE ) {
- pop_log ( p, POP_PRIORITY, HERE,
- "Unable to process user options file for user %s",
- p->user );
- }
- }
+ if ( rslt == 0 )
+ bUser = TRUE;
}
} /* p->user_opts */
@@ -1517,16 +1514,46 @@
p->user );
else {
rslt = stat ( buf, &stat_buf );
- if ( rslt == 0 ) {
- rslt = pop_config ( p, buf, CfgConnected );
- if ( rslt == POP_FAILURE ) {
- pop_log ( p, POP_PRIORITY, HERE,
- "Unable to process spool options file for user %s",
- p->user );
- }
- }
+ if ( rslt == 0 )
+ bSpool = TRUE;
}
} /* p->spool_opts */
+
+ /*
+ * If we are to process either, do it as the user, not root
+ */
+ if ( bUser || bSpool ) {
+ UID_T uid_save = 0;
+
+ uid_save = geteuid();
+ if ( seteuid ( pwp->pw_uid ) != 0 ) {
+ rslt = POP_FAILURE; /* seteuid failed */
+ pop_log ( p, POP_PRIORITY, HERE,
+ "seteuid(%i) for user %s failed",
+ pwp->pw_uid, p->user );
+ } /* seteuid failed */
+ else { /* we are now the user */
+ if ( bUser ) {
+ rslt = pop_config ( p, buf, CfgConnected );
+ if ( rslt == POP_FAILURE )
+ pop_log ( p, POP_PRIORITY, HERE,
+ "Unable to process user options file for user %s",
+ p->user );
+ }
+
+ if ( bSpool ) {
+ rslt = pop_config ( p, buf, CfgConnected );
+ if ( rslt == POP_FAILURE )
+ pop_log ( p, POP_PRIORITY, HERE,
+ "Unable to process spool options file for user %s",
+ p->user );
+ }
+
+ if ( seteuid ( uid_save ) != 0 )
+ pop_log ( p, POP_PRIORITY, HERE,
+ "seteuid(%i) back failed", uid_save );
+ } /* we are now the user */
+ } /* bUser || bSpool */
}
only in patch2:
unchanged:
--- qpopper-4.0.4.orig/popper/popauth.c
+++ qpopper-4.0.4/popper/popauth.c
@@ -107,6 +107,7 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
#ifndef HAVE_BCOPY
# define bcopy(src,dest,len) (void) (memcpy(dest,src,len))
@@ -277,6 +278,7 @@
static void helpful ( void );
static int check_db_err ( void *db, const char *op, BOOL bExp );
static const char *printable ( const char *p, int len );
+static void open_trace ( char *fname );
static void
@@ -453,6 +455,30 @@
}
+void
+open_trace ( char *tname )
+{
+ UID_T uid_save = -1;
+ UID_T myuid = -1;
+
+
+ uid_save = geteuid();
+ myuid = getuid();
+ if ( seteuid ( myuid ) != 0 )
+ adios ( HERE, "internal error @ %i", __LINE__ );
+
+ trace_file = fopen ( tname, "a+" );
+ if ( trace_file == NULL )
+ adios ( HERE, "Unable to open trace file \"%s\": %s (%d)\n",
+ tname, STRERROR(errno), errno );
+ BLATHER1 ( "Trace and Debug destination is file \"%s\"",
+ tname );
+
+ if ( seteuid ( uid_save ) != 0 )
+ adios ( HERE, "internal error @ %i", __LINE__ );
+}
+
+
#ifndef HAVE_STRDUP
#include <stddef.h>
@@ -748,13 +775,7 @@
helpful();
case TRACESW:
debug++;
- trace_file = fopen ( argv[1], "a+" );
- if ( trace_file == NULL )
- adios ( HERE,
- "Unable to open trace file \"%s\": %s (%d)\n",
- argv[1], STRERROR(errno), errno );
- BLATHER1 ( "Trace and Debug destination is file \"%s\"",
- argv[1] );
+ open_trace ( argv[1] );
argc--;
argv++;
break;
|