summaryrefslogtreecommitdiff
path: root/mail/poppassd/patches/patch-ac
blob: 58cd4397e9fdb6f04f8ae3e336a2333cb632c5ac (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
$NetBSD: patch-ac,v 1.8 2005/12/05 14:12:29 taca Exp $

--- password/poppassd.c.orig	Mon Dec  5 10:45:21 2005
+++ password/poppassd.c
@@ -171,8 +171,13 @@
 /* LANMAN allows up to 14 char passwords (truncates if longer), but tacacs
    only seems to allow 11. */
 
+#ifndef PASSWD_BINARY
 #define PASSWD_BINARY "/usr/bin/passwd"         /* TBD: config.h */
+#endif
+
+#ifndef SMBPASSWD_BINARY
 #define SMBPASSWD_BINARY "/usr/bin/smbpasswd"   /* TBD: config.h */
+#endif
 
 #include "config.h"
 
@@ -180,6 +185,8 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 
+#include <signal.h>
+
 #if HAVE_SYS_NETINET_IN_H
 #  include <sys/netinet/in.h>
 #endif
@@ -257,7 +264,7 @@ int     dochild (int master, char *slave
 int     findpty (char **slave);
 void    writestring (int fd, char *s);
 int     talktochild (int master, char *user, char *oldpass, char *newpass,
-                 char *emess, int asroot);
+                 char *emess);
 int     match (char *str, char *pat);
 int     expect (int master, char **expected, char *buf);
 void    getemess (int master, char **expected, char *buf);
@@ -274,7 +281,7 @@ void    get_client_info ( POP *p, BOOL n
 char   *sock_ntop ( struct sockaddr *p, int salen );
 int     sock_port ( struct sockaddr *p, int salen );
 char   *debug_str ( char *p, int inLen, int order );
-
+void	reapchild (int);
 
 /*
  * External prototypes
@@ -295,6 +302,8 @@ pop_result auth_user ( POP *p, char *pas
 
 static char *P1[] =
    {
+     "changing local password for *\nold password: ",  /* BSD */
+     "old password: ",				 /* NetBSD>=3.0 */
      "changing password for *\nold password: ",  /* shadow */
      "enter login password: ",                   /* Solaris */
      "old smb password: ",                       /* smb */
@@ -324,6 +333,7 @@ static char *P4[] =
    {
      "password changed. ", /* shadow */
      "password changed ",  /* smb */
+     "password changed for user *\n",  /* smb */
      ""
    };
 
@@ -338,6 +348,8 @@ char           msg_buf [ 2048 ]     = ""
 char          *pwd_binary           = PASSWD_BINARY;
 char          *smb_binary           = SMBPASSWD_BINARY;
 
+int child_pid;
+int child_status;
 
 /*
  * Be careful using TRACE in an 'if' statement!
@@ -347,18 +359,19 @@ char          *smb_binary           = SM
 #define RUN_PASSWD 1
 #define RUN_SMBPASSWD 2
 
-
 int main ( int argc, char *argv[] )
 {
     char           line    [BUFSIZE]   = "";
     char           oldpass [BUFSIZE]   = "";
     char           newpass [BUFSIZE]   = "";
     int            nopt                = -1;
-    static char    options []          = "dl:p:Rs:t:vy:?";
+    static char    options []          = "dhl:oPp:RSs:t:vy:";
     int            mode                = 0;
     char          *ptr                 = NULL;
     POP            p;
     BOOL           no_rev_lookup       = FALSE;
+    int		   compat_mode	       = 0;
+    BOOL	   bad_user	       = FALSE;
 
 #ifdef HAS_SHADOW
     struct spwd *spwd;
@@ -376,8 +389,6 @@ int main ( int argc, char *argv[] )
             pname = ptr + 1;
     }
 
-    openlog ( pname, POP_LOGOPTS, LOG_LOCAL2 );
-
     /*
      * Set up some stuff in -p- so we can call Qpopper routines
      */
@@ -385,6 +396,17 @@ int main ( int argc, char *argv[] )
     p.AuthType            = noauth;
     p.myname              = pname;
 
+#ifndef   POP_FACILITY
+#  if defined(OSF1) || defined(LINUX)
+#    define POP_FACILITY    LOG_MAIL
+#  else
+#    define POP_FACILITY    LOG_LOCAL0
+#  endif /* OSF1 or Linux */
+#endif /* POP_FACILITY not defined */
+
+    p.log_facility        = (log_facility_type) POP_FACILITY;
+    openlog ( pname, POP_LOGOPTS, p.log_facility );
+
     /*
      * Handle command-line options
      */
@@ -393,9 +415,9 @@ int main ( int argc, char *argv[] )
     {
         switch (nopt)
         {
-            case '?':
-                fprintf ( stderr, "%s [-?] [-d] [-l 0|1|2] [-p [passd-path]] "
-                                  "[-R] [-s [smbpasswd-path]]\n\t"
+            case 'h':
+                fprintf ( stderr, "%s [-h] [-d] [-l 0|1|2] [-p [passd-path]] "
+                                  "[-P] [-R] [-S] [-s [smbpasswd-path]]\n\t"
                                   "[-t trace-file] [-v] [-y log-facility]\n",
                           pname );
                 exit (1);
@@ -412,20 +434,34 @@ int main ( int argc, char *argv[] )
                 verbose = TRUE;
                 break;
 
+           case 'S':
+                mode |= RUN_SMBPASSWD;
+                TRACE ( trace_file, POP_DEBUG, HERE,
+			"Changing SMB password enabled" );
+                break;
+
+
            case 's':
                 mode |= RUN_SMBPASSWD;
                 if ( optarg != NULL && *optarg != '\0' )
                     smb_binary = optarg;
                 TRACE ( trace_file, POP_DEBUG, HERE,
-                        "Changing SMB passwords using %s", smb_binary );
+                        "Changing SMB password using %s", smb_binary );
+                break;
+
+           case 'P':
+                mode |= RUN_PASSWD;
+                TRACE ( trace_file, POP_DEBUG, HERE,
+			"Changing standard password enabled" );
                 break;
 
+
            case 'p':
                 mode |= RUN_PASSWD;
                 if ( optarg != NULL && *optarg != '\0' )
                     pwd_binary = optarg;
                 TRACE ( trace_file, POP_DEBUG, HERE,
-                        "Changing standard passwords using %s", pwd_binary );
+                        "Changing standard password using %s", pwd_binary );
                 break;
 
            case 't':
@@ -476,6 +512,10 @@ int main ( int argc, char *argv[] )
                         "Avoiding reverse lookups (-R)" );
                 break;
 
+	    case 'o':		/* compatibility mode */
+		compat_mode = 1;
+		break;
+
             case 'y': /* log facility */
                 if ( optarg == NULL || *optarg == '\0' ) {
                     err_msg ( HERE, "-y value expected" );
@@ -563,44 +603,50 @@ int main ( int argc, char *argv[] )
         return 1;
     }
 
-    WriteToClient ( "200 your new password please." );
-    ReadFromClient ( line );
-    sscanf ( line, "newpass %s", newpass );
-     
-    /* new pass required */
-    if ( strlen (newpass) == 0 )
-    {
-        WriteToClient ("500 New password required.");
-        return 1;
-    }
-
     pw = getpwnam ( userid );
     if ( pw == NULL )
     {
-        WriteToClient ( "500 Invalid user or password" );
-        return 1;
-    }
+	bad_user = TRUE;
+    } else {
 
 #ifdef HAS_SHADOW
-    if ((spwd = getspnam(userid)) == NULL)
-          pw->pw_passwd = "";
-    else
-          pw->pw_passwd = spwd->sp_pwdp;
+	if ((spwd = getspnam(userid)) == NULL)
+	    pw->pw_passwd = "";
+	else
+	    pw->pw_passwd = spwd->sp_pwdp;
 #endif
 
+	if ( chkPass ( userid, oldpass, pw, &p ) == FAILURE )
+	{
+	    syslog ( LOG_ERR, "password failure for %s", userid );
+	    bad_user = TRUE;
+	}
+
+	if ( pw->pw_uid <= BLOCK_UID )
+	{
+	    syslog( LOG_ERR, "someone tried to change %s's password", userid );
+	    bad_user = TRUE;
+	}
+    }
+    if (compat_mode && bad_user) {
+	sleep(1);		/* XXX */
+	WriteToClient ( "500 Invalid user or password" );
+	return 1;
+    }
 
-    if ( chkPass ( userid, oldpass, pw, &p ) == FAILURE )
-    {
-        syslog ( LOG_ERR, "password failure for %s", userid );
-        WriteToClient ( "500 Invalid user or password" );
-        return 1;
+    WriteToClient ( "200 your new password please." );
+    ReadFromClient ( line );
+    sscanf ( line, "newpass %s", newpass );
+     
+    if (bad_user) {
+	WriteToClient ( "500 Invalid user or password" );
+	return 1;
     }
 
-    if ( pw->pw_uid <= BLOCK_UID )
- 
+    /* new pass required */
+    if ( strlen (newpass) == 0 )
     {
-        syslog ( LOG_ERR, "someone tried to change %s's password", userid );
-        WriteToClient ( "500 Not a user account." );
+        WriteToClient ("500 New password required.");
         return 1;
     }
 
@@ -633,6 +679,20 @@ int main ( int argc, char *argv[] )
     return 0;
 }
 
+/* catch child */
+void
+reapchild(sig)
+	int sig;
+{
+    int status;
+    int pid;
+
+    while ((pid = wait3(&status, WNOHANG, NULL)) > 0) {
+	child_pid = pid;
+	child_status = status;
+    }
+}
+
 
 /* Run a child process to do the password change */
 
@@ -653,6 +713,10 @@ void runchild ( char *userid, char *oldp
         exit ( 1 );
     }
 
+  signal(SIGCHLD, reapchild);
+  child_pid = 0;
+  child_status = -1;
+
   /* fork child process to talk to password program */
 
   pid = fork();
@@ -665,7 +729,7 @@ void runchild ( char *userid, char *oldp
 
   if ( pid > 0 )   /* Parent */
   {
-    if (talktochild (master, userid, oldpass, newpass, emess, smb) == FAILURE)
+    if (talktochild (master, userid, oldpass, newpass, emess) == FAILURE)
     {
       logit ( trace_file, LOG_ERR, HERE, 
               "%s failed for %s", smb ? "smbpasswd" : "passwd", userid );
@@ -677,10 +741,16 @@ void runchild ( char *userid, char *oldp
     wpid = waitpid ( pid, &wstat, 0 );
     if ( wpid < 0 )
     {
-      logit ( trace_file, LOG_ERR, HERE, "wait for child failed" );
-      WriteToClient ("500 Server error (wait failed), get help!");
-      exit(1);
+      if (child_pid > 0) {
+	wpid = child_pid;
+	wstat = child_status;
+      } else {
+	logit ( trace_file, LOG_ERR, HERE, "wait for child failed" );
+	WriteToClient ("500 Server error (wait failed), get help!");
+	exit(1);
+      }
     }
+    signal(SIGCHLD, SIG_DFL);
 
     if ( pid != wpid )
     {
@@ -702,7 +772,6 @@ void runchild ( char *userid, char *oldp
       WriteToClient ("500 Server error (abnormal exit), get help!");
       exit(1);
     }
-
     close ( master ); /* done with the pty */
   }
   else      /* Child */
@@ -784,6 +853,13 @@ int dochild (int master, char *slavedev,
    chdir ("/");
    umask (0);
 
+#ifdef HAVE_SETLOGIN
+   if (setlogin(userid) < 0) {
+      err_msg ( HERE, "setlogin failed: %m" );
+      return(0);
+   }
+#endif
+
 /*
  * Become the user and run passwd. Linux shadowed passwd doesn't need
  * to be run as root with the username passed on the command line.
@@ -883,20 +959,19 @@ void writestring (int fd, char *s)
  * that the password wasn't changed).
  */
 int talktochild (int master, char *userid, char *oldpass, char *newpass,
-                 char *emess, int asroot)
+                 char *emess)
 {
+     int n;
      char buf[BUFSIZE];
      char pswd[BUFSIZE+1];
 
      *emess = 0;
 
      TRACE ( trace_file, POP_DEBUG, HERE,
-             "talktochild; master=%d; userid=%s; asroot=%d",
-             master, userid, asroot );
+             "talktochild; master=%d; userid=%s", master, userid);
 
      /* only get current password if not root */
-     if (!asroot)
-     {
+     if (geteuid() == 0) {
        /* wait for current password prompt */
        if (!expect(master, P1, buf)) return FAILURE;
 
@@ -926,6 +1001,10 @@ int talktochild (int master, char *useri
      if ( !expect(master, P4, buf) )
         TRACE ( trace_file, POP_DEBUG, HERE, "no response -- assuming OK" );
 
+     while ((n = read(master, buf, sizeof buf)) > 0) {
+        TRACE ( trace_file, POP_DEBUG, HERE, "reading remained output" );
+	;
+     }
      return SUCCESS;
 }
 
@@ -955,8 +1034,12 @@ int match (char *str, char *pat)
            strlen(pat), debug_str(pat, strlen(pat), 1) );
 
    while (*str && *pat) {
-     if (*pat == '*')
-       break;
+     if (*pat == '*') {
+       pat++;
+       while (*str != '\0' && *str != '\n')
+	 *str++;
+       continue;
+     }
 
      /* ignore multiple space sequences */
      if (*pat == ' ' && isspace (*str)) {
@@ -1055,7 +1138,11 @@ int expect (int master, char **expected,
         if ( m < 0 ) {
            err_msg ( HERE, "read error from child" );
            return FAILURE;
-        }
+        } else if (m == 0) {
+	   TRACE ( trace_file, POP_DEBUG, HERE, "no data from child");
+	   return FAILURE;
+	}
+
         buf [ n + m ] = '\0';
 
         TRACE ( trace_file, POP_DEBUG, HERE, "...read: (%d) '%.128s'",