From 9c45d9ad13fdf439d44d7443ae75da15ea0223ed Mon Sep 17 00:00:00 2001 From: Sam Varshavchik Date: Mon, 19 Aug 2013 16:39:41 -0400 Subject: Initial checkin Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy. --- sqwebmail/changepw.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 sqwebmail/changepw.c (limited to 'sqwebmail/changepw.c') diff --git a/sqwebmail/changepw.c b/sqwebmail/changepw.c new file mode 100644 index 0000000..cd88528 --- /dev/null +++ b/sqwebmail/changepw.c @@ -0,0 +1,109 @@ +#include "config.h" +/* +** Copyright 2000-2006 Double Precision, Inc. See COPYING for +** distribution information. +*/ + +#include "auth.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "htmllibdir.h" +#include "numlib/numlib.h" +#if HAVE_SYS_WAIT_H +#include +#endif +#ifndef WEXITSTATUS +#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) +#endif +#ifndef WIFEXITED +#define WIFEXITED(stat_val) (((stat_val) & 255) == 0) +#endif + + + +static int badstr(const char *p) +{ + while (p && *p) + { + if ((int)(unsigned char)*p < ' ') + return 1; + ++p; + } + return 0; +} + +int changepw(const char *service, + const char *uid, + const char *opwd, + const char *npwd) +{ + pid_t p, p2; + int waitstat; + int pipefd[2]; + FILE *fp; + + if (badstr(uid) || badstr(opwd) || badstr(npwd)) + { + errno=EINVAL; + return -1; + } + + signal(SIGCHLD, SIG_DFL); + signal(SIGPIPE, SIG_IGN); + + if (pipe(pipefd) < 0) + { + perror("CRIT: authdaemon: pipe() failed"); + errno=EINVAL; + return (-1); + } + + p=fork(); + + if (p == 0) + { + char *argv[2]; + + argv[0]=SQWEBPASSWD; + argv[1]=0; + dup2(pipefd[0], 0); + close(pipefd[0]); + close(pipefd[1]); + execv(argv[0], argv); + perror("CRIT: failed to execute " SQWEBPASSWD); + exit(1); + } + + close(pipefd[0]); + + if ((fp=fdopen(pipefd[1], "w")) != 0) + { + fprintf(fp, "%s\t%s\t%s\t%s\n", + service, uid, opwd, npwd); + fclose(fp); + } + close(pipefd[1]); + + while ((p2=wait(&waitstat)) != p) + { + if (p2 < 0 && errno == ECHILD) + { + perror("CRIT: authdaemon: wait() failed"); + errno=EPERM; + return (-1); + } + } + + if (WIFEXITED(waitstat) && WEXITSTATUS(waitstat) == 0) + return (0); + + errno=EPERM; + return (-1); +} -- cgit v1.2.3