2 ** Copyright 2001-2006 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
18 #include <sys/types.h>
22 #include "authchangepwdir.h"
23 #include "numlib/numlib.h"
25 static const char rcsid
[]="$Id: authsyschangepwd.c,v 1.10 2006/06/01 10:47:33 mrsam Exp $";
27 static int dochangepwd(struct passwd
*, const char *, const char *);
29 int auth_syspasswd(const char *service
, /* Ignored */
30 const char *userid
, /* Generally ignored */
31 const char *oldpwd
, /* Old password */
32 const char *newpwd
) /* New password */
34 char *cpy
=strdup(userid
);
61 rc
=dochangepwd(pwd
, oldpwd
, newpwd
);
67 return (1); /* Fatal error */
70 #define EXPECT AUTHCHANGEPWDIR "/authsystem.passwd"
72 static int dochangepwd(struct passwd
*pwd
,
73 const char *oldpwd
, const char *newpwd
)
80 signal(SIGCHLD
, SIG_DFL
);
81 signal(SIGTERM
, SIG_DFL
);
85 perror("CRIT: authsyschangepwd: pipe() failed");
96 perror("CRIT: authsyschangepwd: fork() failed");
110 open("/dev/null", O_WRONLY
);
113 if (pwd
->pw_uid
!= getuid())
124 setlogin(pwd
->pw_name
);
126 libmail_changeuidgid(pwd
->pw_uid
, pwd
->pw_gid
);
132 execv(argv
[0], argv
);
138 signal(SIGPIPE
, SIG_IGN
);
140 if ((fp
=fdopen(pipefd
[1], "w")) == NULL
)
142 perror("CRIT: authsyschangepwd: fdopen() failed");
147 fprintf(fp
, "%s\n%s\n", oldpwd
, newpwd
);
152 while ((p2
=wait(&waitstat
)) != p
)
154 if (p2
< 0 && errno
== ECHILD
)
156 perror("CRIT: authsyschangepwd: wait() failed");
162 if (WIFEXITED(waitstat
) && WEXITSTATUS(waitstat
) == 0)