diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2012-03-07 11:19:06 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2012-03-07 11:19:06 +0000 |
| commit | a7c3c8dc14e19dcf6fb56495b3c09bc41a66acf9 (patch) | |
| tree | 0c9ee87dff342e005102e00f497c5d88bf844e01 /plugins/password/helpers | |
| parent | fe3e81a373f8018745d4473f0690ac9a7f015bb3 (diff) | |
- Helper files moved to helpers/ directory from drivers/
git-svn-id: https://svn.roundcube.net/trunk@5977 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins/password/helpers')
| -rw-r--r-- | plugins/password/helpers/chgdbmailusers.c | 48 | ||||
| -rw-r--r-- | plugins/password/helpers/chgsaslpasswd.c | 29 | ||||
| -rw-r--r-- | plugins/password/helpers/chgvirtualminpasswd.c | 28 | ||||
| -rw-r--r-- | plugins/password/helpers/chpass-wrapper.py | 32 |
4 files changed, 137 insertions, 0 deletions
diff --git a/plugins/password/helpers/chgdbmailusers.c b/plugins/password/helpers/chgdbmailusers.c new file mode 100644 index 000000000..28f79c100 --- /dev/null +++ b/plugins/password/helpers/chgdbmailusers.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +// set the UID this script will run as (root user) +#define UID 0 +#define CMD "/usr/sbin/dbmail-users" +#define RCOK 0x100 + +/* INSTALLING: + gcc -o chgdbmailusers chgdbmailusers.c + chown root.apache chgdbmailusers + strip chgdbmailusers + chmod 4550 chgdbmailusers +*/ + +main(int argc, char *argv[]) +{ + int cnt,rc,cc; + char cmnd[255]; + + strcpy(cmnd, CMD); + + if (argc > 1) + { + for (cnt = 1; cnt < argc; cnt++) + { + strcat(cmnd, " "); + strcat(cmnd, argv[cnt]); + } + } + else + { + fprintf(stderr, "__ %s: failed %d %d\n", argv[0], rc, cc); + return 255; + } + + cc = setuid(UID); + rc = system(cmnd); + + if ((rc != RCOK) || (cc != 0)) + { + fprintf(stderr, "__ %s: failed %d %d\n", argv[0], rc, cc); + return 1; + } + + return 0; +} diff --git a/plugins/password/helpers/chgsaslpasswd.c b/plugins/password/helpers/chgsaslpasswd.c new file mode 100644 index 000000000..bcdcb2e0d --- /dev/null +++ b/plugins/password/helpers/chgsaslpasswd.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <unistd.h> + +// set the UID this script will run as (cyrus user) +#define UID 96 +// set the path to saslpasswd or saslpasswd2 +#define CMD "/usr/sbin/saslpasswd2" + +/* INSTALLING: + gcc -o chgsaslpasswd chgsaslpasswd.c + chown cyrus.apache chgsaslpasswd + strip chgsaslpasswd + chmod 4550 chgsaslpasswd +*/ + +main(int argc, char *argv[]) +{ + int rc,cc; + + cc = setuid(UID); + rc = execvp(CMD, argv); + if ((rc != 0) || (cc != 0)) + { + fprintf(stderr, "__ %s: failed %d %d\n", argv[0], rc, cc); + return 1; + } + + return 0; +} diff --git a/plugins/password/helpers/chgvirtualminpasswd.c b/plugins/password/helpers/chgvirtualminpasswd.c new file mode 100644 index 000000000..4e2299c66 --- /dev/null +++ b/plugins/password/helpers/chgvirtualminpasswd.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <unistd.h> + +// set the UID this script will run as (root user) +#define UID 0 +#define CMD "/usr/sbin/virtualmin" + +/* INSTALLING: + gcc -o chgvirtualminpasswd chgvirtualminpasswd.c + chown root.apache chgvirtualminpasswd + strip chgvirtualminpasswd + chmod 4550 chgvirtualminpasswd +*/ + +main(int argc, char *argv[]) +{ + int rc,cc; + + cc = setuid(UID); + rc = execvp(CMD, argv); + if ((rc != 0) || (cc != 0)) + { + fprintf(stderr, "__ %s: failed %d %d\n", argv[0], rc, cc); + return 1; + } + + return 0; +} diff --git a/plugins/password/helpers/chpass-wrapper.py b/plugins/password/helpers/chpass-wrapper.py new file mode 100644 index 000000000..61bba849e --- /dev/null +++ b/plugins/password/helpers/chpass-wrapper.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import sys +import pwd +import subprocess + +BLACKLIST = ( + # add blacklisted users here + #'user1', +) + +try: + username, password = sys.stdin.readline().split(':', 1) +except ValueError, e: + sys.exit('Malformed input') + +try: + user = pwd.getpwnam(username) +except KeyError, e: + sys.exit('No such user: %s' % username) + +if user.pw_uid < 1000: + sys.exit('Changing the password for user id < 1000 is forbidden') + +if username in BLACKLIST: + sys.exit('Changing password for user %s is forbidden (user blacklisted)' % + username) + +handle = subprocess.Popen('/usr/sbin/chpasswd', stdin = subprocess.PIPE) +handle.communicate('%s:%s' % (username, password)) + +sys.exit(handle.returncode) |
