checkpw-1.02/0000755000175000017500000000000010631177432012052 5ustar ohiraohiracheckpw-1.02/auto_patrn.h0000644000175000017500000000011207232242620014364 0ustar ohiraohira#ifndef AUTO_PATRN_H #define AUTO_PATRN_H extern int auto_patrn; #endif checkpw-1.02/conf-cc0000644000175000017500000000006007232236301013273 0ustar ohiraohiragcc -O2 This will be used to compile .c files. checkpw-1.02/conf-ld0000644000175000017500000000007707232236165013325 0ustar ohiraohiragcc -s This will be used to link .o files into an executable. checkpw-1.02/selectcheckpw=s0000644000175000017500000000000007306650361015071 0ustar ohiraohiracheckpw-1.02/Makefile0000644000175000017500000002216007307046476013524 0ustar ohiraohira# Don't edit Makefile! Use conf-* for configuration. SHELL=/bin/sh default: it it: prog install instcheck load: warn-auto.sh conf-ld ( cat warn-auto.sh; \ echo 'main="$$1"; shift'; \ echo exec "`head -1 conf-ld`" \ '-o "$$main" "$$main".o $${1+"$$@"}' \ ) > load chmod 755 load prog: auto-str auto-int8 checkpw checkapoppw \ selectcheckpw loginlog \ run-pop run-apop run-rules run-both run-multidir run-multipw auto_patrn.c: auto-int8 conf-patrn ./auto-int8 auto_patrn `head -1 conf-patrn` > auto_patrn.c auto_patrn.o: compile \ auto_patrn.c ./compile auto_patrn.c compile: warn-auto.sh conf-cc ( cat warn-auto.sh; \ echo exec "`head -1 conf-cc`" '-c $${1+"$$@"}' \ ) > compile chmod 755 compile checkapoppw.o: compile \ checkapoppw.c \ error.h pathexec.h prot.h stralloc.h gen_alloc.h openreadclose.h env.h \ global.h md5.h auto_maildir.h auto_password.h auto_patrn.h ./compile checkapoppw.c check: it instcheck ./instcheck env.o: compile \ env.c \ str.h env.h ./compile env.c auto_password.c: auto-str conf-password ./auto-str auto_password `head -1 conf-password` > auto_password.c auto_password.o: compile \ auto_password.c ./compile auto_password.c setup: it install ./install open_read.o: compile \ open_read.c \ open.h ./compile open_read.c selectcheckpw: warn-auto.sh selectcheckpw.sh conf-home cat warn-auto.sh selectcheckpw.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > selectcheckpw chmod 755 selectcheckpw auto_home.c: auto-str conf-home ./auto-str auto_home `head -1 conf-home` > auto_home.c auto_home.o: compile \ auto_home.c ./compile auto_home.c checkapoppw: load checkapoppw.o auto_maildir.o auto_password.o \ auto_patrn.o md5c.o unix.a byte.a ./load checkapoppw auto_maildir.o auto_password.o auto_patrn.o md5c.o \ unix.a byte.a auto-str: load auto-str.o unix.a byte.a ./load auto-str unix.a byte.a alloc_re.o: compile \ alloc_re.c \ alloc.h byte.h ./compile alloc_re.c run-multidir: warn-auto.sh run-multidir.sh conf-home cat warn-auto.sh run-multidir.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > run-multidir chmod 755 run-multidir run-pop: warn-auto.sh run-pop.sh conf-home cat warn-auto.sh run-pop.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > run-pop chmod 755 run-pop makelib: warn-auto.sh systype ( cat warn-auto.sh; \ echo 'main="$$1"; shift'; \ echo 'rm -f "$$main"'; \ echo 'ar cr "$$main" $${1+"$$@"}'; \ case "`cat systype`" in \ sunos-5.*) ;; \ unix_sv*) ;; \ irix64-*) ;; \ irix-*) ;; \ dgux-*) ;; \ hp-ux-*) ;; \ sco*) ;; \ *) echo 'ranlib "$$main"' ;; \ esac \ ) > makelib chmod 755 makelib openreadclose.o: compile \ openreadclose.c \ error.h open.h readclose.h stralloc.h gen_alloc.h openreadclose.h ./compile openreadclose.c run-apop: warn-auto.sh run-apop.sh conf-home cat warn-auto.sh run-apop.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > run-apop chmod 755 run-apop run-both: warn-auto.sh run-both.sh conf-home cat warn-auto.sh run-both.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > run-both chmod 755 run-both str_start.o: compile \ str_start.c \ str.h ./compile str_start.c instcheck.o: compile \ instcheck.c \ strerr.h error.h readwrite.h exit.h ./compile instcheck.c auto_maildir.c: auto-str conf-maildir ./auto-str auto_maildir `head -1 conf-maildir` > auto_maildir.c auto_maildir.o: compile \ auto_maildir.c ./compile auto_maildir.c open_trunc.o: compile \ open_trunc.c \ open.h ./compile open_trunc.c error.o: compile \ error.c \ error.h ./compile error.c strerr_die.o: compile \ strerr_die.c \ buffer.h exit.h strerr.h ./compile strerr_die.c buffer_get.o: compile \ buffer_get.c \ buffer.h byte.h error.h ./compile buffer_get.c fmt_ulong.o: compile \ fmt_ulong.c \ fmt.h ./compile fmt_ulong.c buffer_put.o: compile \ buffer_put.c \ buffer.h str.h byte.h error.h ./compile buffer_put.c strerr_sys.o: compile \ strerr_sys.c \ error.h strerr.h ./compile strerr_sys.c stralloc_catb.o: compile \ stralloc_catb.c \ stralloc.h gen_alloc.h byte.h ./compile stralloc_catb.c stralloc_cats.o: compile \ stralloc_cats.c \ byte.h str.h stralloc.h gen_alloc.h ./compile stralloc_cats.c buffer_copy.o: compile \ buffer_copy.c \ buffer.h ./compile buffer_copy.c stralloc_eady.o: compile \ stralloc_eady.c \ alloc.h stralloc.h gen_alloc.h gen_allocdefs.h ./compile stralloc_eady.c byte.a: makelib byte_copy.o byte_cr.o byte_diff.o str_chr.o str_len.o \ str_start.o ./makelib byte.a byte_copy.o byte_cr.o byte_diff.o str_chr.o str_len.o \ str_start.o run-multipw: warn-auto.sh run-multipw.sh conf-home cat warn-auto.sh run-multipw.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > run-multipw chmod 755 run-multipw pathexec_env.o: compile \ pathexec_env.c \ stralloc.h gen_alloc.h alloc.h str.h byte.h env.h pathexec.h ./compile pathexec_env.c systype: find-systype.sh conf-cc conf-ld trycpp.c x86cpuid.c ( cat warn-auto.sh; \ echo CC=\'`head -1 conf-cc`\'; \ echo LD=\'`head -1 conf-ld`\'; \ cat find-systype.sh; \ ) | sh > systype hier.o: compile \ hier.c \ auto_home.h ./compile hier.c pathexec_run.o: compile \ pathexec_run.c \ error.h stralloc.h gen_alloc.h str.h env.h pathexec.h ./compile pathexec_run.c substdo.o: compile \ substdo.c \ substdio.h str.h byte.h error.h ./compile substdo.c md5c.o: compile \ md5c.c \ global.h md5.h ./compile md5c.c byte_cr.o: compile \ byte_cr.c \ byte.h ./compile byte_cr.c stralloc_pend.o: compile \ stralloc_pend.c \ alloc.h stralloc.h gen_alloc.h gen_allocdefs.h ./compile stralloc_pend.c stralloc_opyb.o: compile \ stralloc_opyb.c \ stralloc.h gen_alloc.h byte.h ./compile stralloc_opyb.c stralloc_opys.o: compile \ stralloc_opys.c \ byte.h str.h stralloc.h gen_alloc.h ./compile stralloc_opys.c prot.o: compile \ prot.c \ hasshsgr.h prot.h ./compile prot.c auto-str.o: compile \ auto-str.c \ buffer.h readwrite.h exit.h ./compile auto-str.c buffer.o: compile \ buffer.c \ buffer.h ./compile buffer.c auto-int8: load auto-int8.o unix.a byte.a ./load auto-int8 unix.a byte.a unix.a: makelib alloc.o alloc_re.o buffer.o buffer_2.o buffer_copy.o \ buffer_get.o buffer_put.o env.o error.o error_str.o open_read.o \ open_trunc.o openreadclose.o readclose.o pathexec_env.o pathexec_run.o \ prot.o stralloc_cat.o stralloc_catb.o stralloc_cats.o stralloc_eady.o \ stralloc_opyb.o stralloc_opys.o stralloc_pend.o strerr_die.o strerr_sys.o \ substdo.o scan_8long.o fmt_ulong.o ./makelib unix.a alloc.o alloc_re.o buffer.o buffer_2.o buffer_copy.o \ buffer_get.o buffer_put.o env.o error.o error_str.o open_read.o \ open_trunc.o openreadclose.o readclose.o pathexec_env.o pathexec_run.o \ prot.o stralloc_cat.o stralloc_catb.o stralloc_cats.o stralloc_eady.o \ stralloc_opyb.o stralloc_opys.o stralloc_pend.o strerr_die.o \ strerr_sys.o substdo.o scan_8long.o fmt_ulong.o checkpw.o: compile \ checkpw.c \ error.h pathexec.h prot.h stralloc.h gen_alloc.h openreadclose.h env.h \ auto_maildir.h auto_password.h auto_patrn.h ./compile checkpw.c readclose.o: compile \ readclose.c \ error.h readclose.h stralloc.h gen_alloc.h ./compile readclose.c alloc.o: compile \ alloc.c \ alloc.h error.h ./compile alloc.c loginlog: warn-auto.sh loginlog.sh conf-home cat warn-auto.sh loginlog.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > loginlog chmod 755 loginlog stralloc_cat.o: compile \ stralloc_cat.c \ byte.h stralloc.h gen_alloc.h ./compile stralloc_cat.c run-rules: warn-auto.sh run-rules.sh conf-home cat warn-auto.sh run-rules.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g \ > run-rules chmod 755 run-rules buffer_2.o: compile \ buffer_2.c \ readwrite.h buffer.h ./compile buffer_2.c byte_copy.o: compile \ byte_copy.c \ byte.h ./compile byte_copy.c byte_diff.o: compile \ byte_diff.c \ byte.h ./compile byte_diff.c install: load install.o hier.o auto_home.o unix.a byte.a ./load install hier.o auto_home.o unix.a byte.a auto-int8.o: compile \ auto-int8.c \ substdio.h readwrite.h exit.h scan.h fmt.h ./compile auto-int8.c error_str.o: compile \ error_str.c \ error.h ./compile error_str.c checkpw: load checkpw.o auto_maildir.o auto_password.o auto_patrn.o \ unix.a byte.a ./load checkpw auto_maildir.o auto_password.o auto_patrn.o unix.a byte.a \ install.o: compile \ install.c \ buffer.h strerr.h error.h open.h readwrite.h exit.h ./compile install.c instcheck: load instcheck.o hier.o auto_home.o unix.a byte.a ./load instcheck hier.o auto_home.o unix.a byte.a str_chr.o: compile \ str_chr.c \ str.h ./compile str_chr.c scan_8long.o: compile \ scan_8long.c \ scan.h ./compile scan_8long.c str_len.o: compile \ str_len.c \ str.h ./compile str_len.c checkpw-1.02/checkapoppw.c0000644000175000017500000000577107416246526014544 0ustar ohiraohira#include #include "error.h" #include "pathexec.h" #include "prot.h" #include "stralloc.h" #include "openreadclose.h" #include "env.h" #include "global.h" #include "md5.h" #include "auto_maildir.h" #include "auto_password.h" #include "auto_patrn.h" #include static struct passwd *pw; static char up[513]; static int uplen; static stralloc stored = {0}; static stralloc pwfile = {0}; static char *hextable = "0123456789abcdef"; void cleanup() { int i; for (i = 0;i < sizeof(up);++i) up[i] = 0; for (i = 0;i < stored.len;++i) stored.s[i] = 0; } void die(int x) { cleanup(); _exit(x); } main(int argc,char **argv) { char *login; char *dash; char *ext; char *password; char *timestamp; struct stat st; int r; int i; MD5_CTX context; unsigned char digest[16]; char encrypted[16*2+1]; char *s; if (!argv[1]) _exit(2); dash = env_get("DASH"); uplen = 0; for (;;) { do r = read(3,up + uplen,sizeof(up) - uplen); while ((r == -1) && (errno == error_intr)); if (r == -1) _exit(111); if (r == 0) break; uplen += r; if (uplen >= sizeof(up)) _exit(1); } close(3); i = 0; if (i >= uplen) _exit(2); login = up + i; while (up[i++]) if (i >= uplen) _exit(2); password = up + i; if (i >= uplen) _exit(2); while (up[i++]) if (i >= uplen) _exit(2); timestamp = up + i; if (i >= uplen) _exit(2); while (up[i++]) if (i >= uplen) _exit(2); i = 0; ext = login + str_len(login); for (;;) { pw = getpwnam(login); if (pw) break; if (errno == error_txtbsy) die(111); for (; ext != login && *ext != '-'; --ext); if (ext == login) die(1); if (i) login[i] = '-'; i = ext - login; login[i] = 0; ++ext; } if (chdir(pw->pw_dir) == -1) die(111); if (!stralloc_copys(&pwfile, auto_maildir)) die(111); if (dash && *ext) { if (!stralloc_cats(&pwfile, dash)) die(111); if (!stralloc_cats(&pwfile, ext)) die(111); } if (!stralloc_append(&pwfile, "/")) die(111); if (!stralloc_cats(&pwfile, auto_password)) die(111); if (!stralloc_0(&pwfile)) die(111); if (stat(pwfile.s,&st) == -1) die(1); if (st.st_uid != pw->pw_uid) die(1); if (st.st_mode & auto_patrn) die(111); if (openreadclose(pwfile.s,&stored,32) != 1) die(111); if (!stralloc_0(&stored)) die(111); stored.s[str_chr(stored.s,'\n')] = 0; MD5Init(&context); MD5Update(&context, timestamp, str_len(timestamp)); MD5Update(&context, stored.s, str_len(stored.s)); MD5Final(digest, &context); s = encrypted; for (i = 0; i < sizeof(digest); ++i) { *s = hextable[digest[i]/16]; ++s; *s = hextable[digest[i]%16]; ++s; } *s = '\0'; if (strcmp(password,encrypted)) die(1); if (prot_gid((int) pw->pw_gid) == -1) die(1); if (prot_uid((int) pw->pw_uid) == -1) die(1); if (!pathexec_env("USER",pw->pw_name)) die(111); if (!pathexec_env("EXT",ext)) die(111); if (!pathexec_env("HOME",pw->pw_dir)) die(111); if (!pathexec_env("SHELL",pw->pw_shell)) die(111); cleanup(); pathexec(argv + 1); _exit(111); } checkpw-1.02/checkapoppw=x0000644000175000017500000000010107306611063014554 0ustar ohiraohiraauto_maildir.o auto_password.o auto_patrn.o md5c.o unix.a byte.a checkpw-1.02/FILES0000644000175000017500000000202507307046476012647 0ustar ohiraohiraFILES INSTALL Makefile README TARGETS auto_patrn.h conf-cc conf-ld checkapoppw.c x86cpuid.c env.c env.h fmt.h md5.h conf-home auto_password.h str.h open_read.c auto_home.h gen_allocdefs.h warn-auto.sh stralloc.h alloc_re.c trycpp.c openreadclose.c openreadclose.h str_start.c run-rules.sh instcheck.c auto_maildir.h open_trunc.c error.c error.h strerr_die.c buffer_get.c fmt_ulong.c buffer_put.c strerr_sys.c stralloc_catb.c stralloc_cats.c global.h buffer_copy.c stralloc_eady.c byte.h exit.h pathexec_env.c hier.c run-multidir.sh pathexec_run.c run-pop.sh substdo.c md5c.c byte_cr.c conf-password stralloc_pend.c stralloc_opyb.c stralloc_opys.c open.h prot.c prot.h selectcheckpw.sh conf-patrn auto-str.c buffer.c buffer.h scan.h run-apop.sh conf-maildir readwrite.h hasshsgr.h checkpw.c readclose.c readclose.h alloc.c alloc.h pathexec.h gen_alloc.h stralloc_cat.c find-systype.sh run-both.sh buffer_2.c substdio.h run-multipw.sh byte_copy.c byte_diff.c loginlog.sh auto-int8.c error_str.c strerr.h install.c str_chr.c scan_8long.c str_len.c checkpw-1.02/default.a.do0000644000175000017500000000025707232240625014243 0ustar ohiraohiraif test -r "$2=l" then dependon "$2=l" dependon makelib `cat "$2=l"` directtarget formake ./makelib $1 `cat "$2=l"` ./makelib $1 `cat "$2=l"` else nosuchtarget fi checkpw-1.02/default.o.do0000644000175000017500000000031507232236165014260 0ustar ohiraohiraif test -r $2=m then dependon $2=m $2.s directtarget as -o $1 $2.s formake as -o $1 $2.s exit 0 fi depend -$2=m directtarget dependon compile dependcc $2.c formake ./compile $2.c ./compile $2.c checkpw-1.02/x86cpuid.c0000644000175000017500000000116107232241100013652 0ustar ohiraohira#include void nope() { exit(1); } main() { unsigned long x[4]; unsigned long y[4]; int i; int j; char c; signal(SIGILL,nope); x[0] = 0; x[1] = 0; x[2] = 0; x[3] = 0; asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) ); if (!x[0]) return 0; asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) ); for (i = 1;i < 4;++i) for (j = 0;j < 4;++j) { c = x[i] >> (8 * j); if (c < 32) c = 32; if (c > 126) c = 126; putchar(c); } printf("-%08x-%08x\n",y[0],y[3]); return 0; } checkpw-1.02/env.c0000644000175000017500000000043607232241103012777 0ustar ohiraohira#include "str.h" #include "env.h" extern /*@null@*/char *env_get(char *s) { int i; unsigned int len; if (!s) return 0; len = str_len(s); for (i = 0;environ[i];++i) if (str_start(environ[i],s) && (environ[i][len] == '=')) return environ[i] + len + 1; return 0; } checkpw-1.02/env.h0000644000175000017500000000014507232241103013001 0ustar ohiraohira#ifndef ENV_H #define ENV_H extern char **environ; extern /*@null@*/char *env_get(char *); #endif checkpw-1.02/fmt.h0000644000175000017500000000207607232261062013012 0ustar ohiraohira#ifndef FMT_H #define FMT_H #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ #define FMT_LEN ((char *) 0) /* convenient abbreviation */ extern unsigned int fmt_uint(char *,unsigned int); extern unsigned int fmt_uint0(char *,unsigned int,unsigned int); extern unsigned int fmt_xint(char *,unsigned int); extern unsigned int fmt_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int); extern unsigned int fmt_ushort(char *,unsigned short); extern unsigned int fmt_xshort(char *,unsigned short); extern unsigned int fmt_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short); extern unsigned int fmt_ulong(char *,unsigned long); extern unsigned int fmt_xlong(char *,unsigned long); extern unsigned int fmt_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long); extern unsigned int fmt_plusminus(char *,int); extern unsigned int fmt_minus(char *,int); extern unsigned int fmt_0x(char *,int); extern unsigned int fmt_str(char *,const char *); extern unsigned int fmt_strn(char *,const char *,unsigned int); #endif checkpw-1.02/md5.h0000644000175000017500000000250607232252645012716 0ustar ohiraohira/* MD5.H - header file for MD5C.C */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing this software or this function. License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing the derived work. RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. */ /* MD5 context. */ typedef struct { UINT4 state[4]; /* state (ABCD) */ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } MD5_CTX; void MD5Init PROTO_LIST ((MD5_CTX *)); void MD5Update PROTO_LIST ((MD5_CTX *, unsigned char *, unsigned int)); void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); checkpw-1.02/conf-home0000644000175000017500000000016707232253433013653 0ustar ohiraohira/ This is the checkpw home directory. The checkpw and checkapoppw programs will be installed in the bin subdirectory. checkpw-1.02/auto_password.h0000644000175000017500000000012607232241743015114 0ustar ohiraohira#ifndef AUTO_PASSWORD_H #define AUTO_PASSWORD_H extern char auto_password[]; #endif checkpw-1.02/str.h0000644000175000017500000000056207232241103013024 0ustar ohiraohira#ifndef STR_H #define STR_H extern unsigned int str_copy(char *,char *); extern int str_diff(char *,char *); extern int str_diffn(char *,char *,unsigned int); extern unsigned int str_len(char *); extern unsigned int str_chr(char *,int); extern unsigned int str_rchr(char *,int); extern int str_start(char *,char *); #define str_equal(s,t) (!str_diff((s),(t))) #endif checkpw-1.02/run-multipw=s0000644000175000017500000000000007306651510014545 0ustar ohiraohiracheckpw-1.02/open_read.c0000644000175000017500000000017607232241104014145 0ustar ohiraohira#include #include #include "open.h" int open_read(char *fn) { return open(fn,O_RDONLY | O_NDELAY); } checkpw-1.02/README0000644000175000017500000000165010631177432012734 0ustar ohiraohiracheckpw-1.02 20070605 OHIRA, Shinya shinya_ohira@users.sourceforge.net http://checkpw.sourceforge.net/checkpw/ checkpw is a simple and flexible checkpassword interface package. checkpw checks password which is stored in a file in the Maildir directory. The file has read and write permissions to the user only. checkpw checks real user's password. For virtual users, vucheckpw is available http://checkpw.sourceforge.net/vucheckpw/ o checkpw allows POP authentication. o checkapoppw allows APOP authentication. o Multiple maildirs per POP3 user are supported. o Multiple password per maildir are supported. Before invoking following program, checkpw and checkapoppw set up $USER, $EXT, $HOME, $SHELL, its supplementary groups, its gid, its uid, and its working directory. INSTALL says how to set up. The code is in the public domain. The original checkpassword program is written by D.J.Bernstein: http://cr.yp.to/checkpwd.html checkpw-1.02/auto_home.h0000644000175000017500000000012007232253462014175 0ustar ohiraohira#ifndef AUTO_HOME_H #define AUTO_HOME_H extern const char auto_home[]; #endif checkpw-1.02/TARGETS0000644000175000017500000000150007307046476013113 0ustar ohiraohirait load prog auto_patrn.c auto_patrn.o compile checkapoppw.o check env.o auto_password.c auto_password.o setup open_read.o selectcheckpw auto_home.c auto_home.o checkapoppw auto-str alloc_re.o run-multidir run-pop makelib openreadclose.o run-apop run-both str_start.o instcheck.o auto_maildir.c auto_maildir.o open_trunc.o error.o strerr_die.o buffer_get.o fmt_ulong.o buffer_put.o strerr_sys.o stralloc_catb.o stralloc_cats.o buffer_copy.o stralloc_eady.o byte.a run-multipw pathexec_env.o systype hier.o pathexec_run.o substdo.o md5c.o byte_cr.o stralloc_pend.o stralloc_opyb.o stralloc_opys.o prot.o auto-str.o buffer.o auto-int8 unix.a checkpw.o readclose.o alloc.o loginlog stralloc_cat.o run-rules buffer_2.o byte_copy.o byte_diff.o install auto-int8.o error_str.o checkpw install.o instcheck str_chr.o scan_8long.o str_len.o checkpw-1.02/run-rules=s0000644000175000017500000000000007306651231014176 0ustar ohiraohiracheckpw-1.02/gen_allocdefs.h0000644000175000017500000000224007232241106014777 0ustar ohiraohira#ifndef GEN_ALLOC_DEFS_H #define GEN_ALLOC_DEFS_H #define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \ int ta_ready(register ta *x,register unsigned int n) \ { register unsigned int i; \ if (x->field) { \ i = x->a; \ if (n > i) { \ x->a = base + n + (n >> 3); \ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ x->a = i; return 0; } \ return 1; } \ x->len = 0; \ return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } #define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \ int ta_rplus(register ta *x,register unsigned int n) \ { register unsigned int i; \ if (x->field) { \ i = x->a; n += x->len; \ if (n > i) { \ x->a = base + n + (n >> 3); \ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ x->a = i; return 0; } \ return 1; } \ x->len = 0; \ return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } #define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \ int ta_append(register ta *x,register type *i) \ { if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; } #endif checkpw-1.02/auto_maildir.c.do0000644000175000017500000000023007306610754015267 0ustar ohiraohiradependon auto-str conf-maildir formake './auto-str auto_maildir `head -1 conf-maildir` > auto_maildir.c' ./auto-str auto_maildir `head -1 conf-maildir` checkpw-1.02/warn-auto.sh0000644000175000017500000000010007232241077014312 0ustar ohiraohira#!/bin/sh # WARNING: This file was auto-generated. Do not edit! checkpw-1.02/stralloc.h0000644000175000017500000000212107232241100014025 0ustar ohiraohira#ifndef STRALLOC_H #define STRALLOC_H #include "gen_alloc.h" GEN_ALLOC_typedef(stralloc,char,s,len,a) extern int stralloc_ready(stralloc *,unsigned int); extern int stralloc_readyplus(stralloc *,unsigned int); extern int stralloc_copy(stralloc *,stralloc *); extern int stralloc_cat(stralloc *,stralloc *); extern int stralloc_copys(stralloc *,char *); extern int stralloc_cats(stralloc *,char *); extern int stralloc_copyb(stralloc *,char *,unsigned int); extern int stralloc_catb(stralloc *,char *,unsigned int); extern int stralloc_append(stralloc *,char *); /* beware: this takes a pointer to 1 char */ extern int stralloc_starts(stralloc *,char *); #define stralloc_0(sa) stralloc_append(sa,"") extern int stralloc_catulong0(stralloc *,unsigned long,unsigned int); extern int stralloc_catlong0(stralloc *,long,unsigned int); #define stralloc_catlong(sa,l) (stralloc_catlong0((sa),(l),0)) #define stralloc_catuint0(sa,i,n) (stralloc_catulong0((sa),(i),(n))) #define stralloc_catint0(sa,i,n) (stralloc_catlong0((sa),(i),(n))) #define stralloc_catint(sa,i) (stralloc_catlong0((sa),(i),0)) #endif checkpw-1.02/alloc_re.c0000644000175000017500000000032607232241101013763 0ustar ohiraohira#include "alloc.h" #include "byte.h" int alloc_re(x,m,n) char **x; unsigned int m; unsigned int n; { char *y; y = alloc(n); if (!y) return 0; byte_copy(y,m,*x); alloc_free(*x); *x = y; return 1; } checkpw-1.02/auto_home.c.do0000644000175000017500000000020607232254111014566 0ustar ohiraohiradependon auto-str conf-home formake './auto-str auto_home `head -1 conf-home` > auto_home.c' ./auto-str auto_home `head -1 conf-home` checkpw-1.02/trycpp.c0000644000175000017500000000013707232241100013523 0ustar ohiraohiramain() { #ifdef NeXT printf("nextstep\n"); exit(0); #endif printf("unknown\n"); exit(0); } checkpw-1.02/openreadclose.c0000644000175000017500000000051207232244422015034 0ustar ohiraohira#include "error.h" #include "open.h" #include "readclose.h" #include "openreadclose.h" int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize) { int fd; fd = open_read(fn); if (fd == -1) { if (errno == error_noent) return 0; return -1; } if (readclose(fd,sa,bufsize) == -1) return -1; return 1; } checkpw-1.02/openreadclose.h0000644000175000017500000000022007232244422015035 0ustar ohiraohira#ifndef OPENREADCLOSE_H #define OPENREADCLOSE_H #include "stralloc.h" extern int openreadclose(const char *,stralloc *,unsigned int); #endif checkpw-1.02/run-apop=s0000644000175000017500000000000007306650704014007 0ustar ohiraohiracheckpw-1.02/auto_password.c.do0000644000175000017500000000023607232242076015512 0ustar ohiraohiradependon auto-str conf-password formake './auto-str auto_password `head -1 conf-password` > auto_password.c' ./auto-str auto_password `head -1 conf-password` checkpw-1.02/run-both=s0000644000175000017500000000000007306651254014005 0ustar ohiraohiracheckpw-1.02/str_start.c0000644000175000017500000000052007232243320014231 0ustar ohiraohira#include "str.h" int str_start(register char *s,register char *t) { register char x; for (;;) { x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; } } checkpw-1.02/run-rules.sh0000644000175000017500000000032007416231057014336 0ustar ohiraohiraexec 2>&1 exec tcpserver -DRHv -xrules.cdb -llocalhost 0 110 \ softlimit -m 3000000 \ QMAIL/bin/qmail-popup `cat QMAIL/control/me` \ HOME/bin/selectcheckpw \ HOME/bin/loginlog \ QMAIL/bin/qmail-pop3d MAILDIR checkpw-1.02/instcheck.c0000644000175000017500000000437007232260340014167 0ustar ohiraohira#include #include #include "strerr.h" #include "error.h" #include "readwrite.h" #include "exit.h" extern void hier(); #define FATAL "instcheck: fatal: " #define WARNING "instcheck: warning: " void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode) char *prefix1; char *prefix2; char *prefix3; char *file; int type; int uid; int gid; int mode; { struct stat st; if (stat(file,&st) == -1) { if (errno == error_noent) strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0); else strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys); return; } if ((uid != -1) && (st.st_uid != uid)) strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0); if ((gid != -1) && (st.st_gid != gid)) strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0); if ((st.st_mode & 07777) != mode) strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong permissions",0); if ((st.st_mode & S_IFMT) != type) strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0); } void h(home,uid,gid,mode) char *home; int uid; int gid; int mode; { perm("","","",home,S_IFDIR,uid,gid,mode); } void d(home,subdir,uid,gid,mode) char *home; char *subdir; int uid; int gid; int mode; { if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); perm("",home,"/",subdir,S_IFDIR,uid,gid,mode); } void p(home,fifo,uid,gid,mode) char *home; char *fifo; int uid; int gid; int mode; { if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); perm("",home,"/",fifo,S_IFIFO,uid,gid,mode); } void c(home,subdir,file,uid,gid,mode) char *home; char *subdir; char *file; int uid; int gid; int mode; { if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); if (chdir(subdir) == -1) strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode); } void z(home,file,len,uid,gid,mode) char *home; char *file; int len; int uid; int gid; int mode; { if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); perm("",home,"/",file,S_IFREG,uid,gid,mode); } main() { hier(); _exit(0); } checkpw-1.02/instcheck=x0000644000175000017500000000004107232260312014221 0ustar ohiraohirahier.o auto_home.o unix.a byte.a checkpw-1.02/auto_maildir.h0000644000175000017500000000012307306611032014662 0ustar ohiraohira#ifndef AUTO_MAILDIR_H #define AUTO_MAILDIR_H extern char auto_maildir[]; #endif checkpw-1.02/open_trunc.c0000644000175000017500000000023007232241104014354 0ustar ohiraohira#include #include #include "open.h" int open_trunc(char *fn) { return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); } checkpw-1.02/error.c0000644000175000017500000000217507232241103013342 0ustar ohiraohira#include #include "error.h" /* warning: as coverage improves here, should update error_{str,temp} */ int error_intr = #ifdef EINTR EINTR; #else -1; #endif int error_nomem = #ifdef ENOMEM ENOMEM; #else -2; #endif int error_noent = #ifdef ENOENT ENOENT; #else -3; #endif int error_txtbsy = #ifdef ETXTBSY ETXTBSY; #else -4; #endif int error_io = #ifdef EIO EIO; #else -5; #endif int error_exist = #ifdef EEXIST EEXIST; #else -6; #endif int error_timeout = #ifdef ETIMEDOUT ETIMEDOUT; #else -7; #endif int error_inprogress = #ifdef EINPROGRESS EINPROGRESS; #else -8; #endif int error_wouldblock = #ifdef EWOULDBLOCK EWOULDBLOCK; #else -9; #endif int error_again = #ifdef EAGAIN EAGAIN; #else -10; #endif int error_pipe = #ifdef EPIPE EPIPE; #else -11; #endif int error_perm = #ifdef EPERM EPERM; #else -12; #endif int error_acces = #ifdef EACCES EACCES; #else -13; #endif int error_nodevice = #ifdef ENXIO ENXIO; #else -14; #endif int error_proto = #ifdef EPROTO EPROTO; #else -15; #endif int error_isdir = #ifdef EISDIR EISDIR; #else -16; #endif int error_connrefused = #ifdef ECONNREFUSED ECONNREFUSED; #else -17; #endif checkpw-1.02/error.h0000644000175000017500000000103710021241503013335 0ustar ohiraohira#ifndef ERROR_H #define ERROR_H #include extern int error_intr; extern int error_nomem; extern int error_noent; extern int error_txtbsy; extern int error_io; extern int error_exist; extern int error_timeout; extern int error_inprogress; extern int error_wouldblock; extern int error_again; extern int error_pipe; extern int error_perm; extern int error_acces; extern int error_nodevice; extern int error_proto; extern int error_isdir; extern int error_connrefused; extern char *error_str(int); extern int error_temp(int); #endif checkpw-1.02/qmail-popup-auth.patch0000644000175000017500000000351007232255064016276 0ustar ohiraohiradiff -c qmail-1.03/Makefile qmail-1.03-authenv/Makefile *** qmail-1.03/Makefile Mon Jun 15 19:53:16 1998 --- qmail-1.03-authenv/Makefile Wed May 3 13:43:39 2000 *************** *** 1288,1298 **** qmail-popup: \ load qmail-popup.o commands.o timeoutread.o timeoutwrite.o now.o \ ! case.a fd.a sig.a wait.a stralloc.a alloc.a substdio.a error.a str.a \ fs.a socket.lib ./load qmail-popup commands.o timeoutread.o timeoutwrite.o \ now.o case.a fd.a sig.a wait.a stralloc.a alloc.a \ ! substdio.a error.a str.a fs.a `cat socket.lib` qmail-popup.0: \ qmail-popup.8 --- 1288,1298 ---- qmail-popup: \ load qmail-popup.o commands.o timeoutread.o timeoutwrite.o now.o \ ! case.a fd.a sig.a wait.a stralloc.a alloc.a env.a substdio.a error.a str.a \ fs.a socket.lib ./load qmail-popup commands.o timeoutread.o timeoutwrite.o \ now.o case.a fd.a sig.a wait.a stralloc.a alloc.a \ ! env.a substdio.a error.a str.a fs.a `cat socket.lib` qmail-popup.0: \ qmail-popup.8 diff -c qmail-1.03/qmail-popup.c qmail-1.03-authenv/qmail-popup.c *** qmail-1.03/qmail-popup.c Mon Jun 15 19:53:16 1998 --- qmail-1.03-authenv/qmail-popup.c Wed May 3 13:44:35 2000 *************** *** 13,18 **** --- 13,19 ---- #include "readwrite.h" #include "timeoutread.h" #include "timeoutwrite.h" + #include "env.h" void die() { _exit(1); } *************** *** 145,150 **** --- 146,152 ---- { if (!seenuser) { err_wantuser(); return; } if (!*arg) { err_syntax(); return; } + if (!env_put("AUTH=pop")) die_nomem(); doanddie(username.s,username.len,arg); } void pop3_apop(arg) char *arg; *************** *** 153,158 **** --- 155,161 ---- space = arg + str_chr(arg,' '); if (!*space) { err_syntax(); return; } *space++ = 0; + if (!env_put("AUTH=apop")) die_nomem(); doanddie(arg,space - arg,space); } checkpw-1.02/strerr_die.c0000644000175000017500000000140007232241107014345 0ustar ohiraohira#include "buffer.h" #include "exit.h" #include "strerr.h" void strerr_warn(char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) { strerr_sysinit(); if (x1) buffer_puts(buffer_2,x1); if (x2) buffer_puts(buffer_2,x2); if (x3) buffer_puts(buffer_2,x3); if (x4) buffer_puts(buffer_2,x4); if (x5) buffer_puts(buffer_2,x5); if (x6) buffer_puts(buffer_2,x6); while(se) { if (se->x) buffer_puts(buffer_2,se->x); if (se->y) buffer_puts(buffer_2,se->y); if (se->z) buffer_puts(buffer_2,se->z); se = se->who; } buffer_puts(buffer_2,"\n"); buffer_flush(buffer_2); } void strerr_die(int e,char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) { strerr_warn(x1,x2,x3,x4,x5,x6,se); _exit(e); } checkpw-1.02/auto_patrn.c.do0000644000175000017500000000021707232247101014765 0ustar ohiraohiradependon auto-int8 conf-patrn formake './auto-int8 auto_patrn `head -1 conf-patrn` > auto_patrn.c' ./auto-int8 auto_patrn `head -1 conf-patrn` checkpw-1.02/buffer_get.c0000644000175000017500000000234107232241102014313 0ustar ohiraohira#include "buffer.h" #include "byte.h" #include "error.h" static int oneread(int (*op)(),int fd,char *buf,unsigned int len) { int r; for (;;) { r = op(fd,buf,len); if (r == -1) if (errno == error_intr) continue; return r; } } static int getthis(buffer *s,char *buf,unsigned int len) { if (len > s->p) len = s->p; s->p -= len; byte_copy(buf,len,s->x + s->n); s->n += len; return len; } int buffer_feed(buffer *s) { int r; if (s->p) return s->p; r = oneread(s->op,s->fd,s->x,s->n); if (r <= 0) return r; s->p = r; s->n -= r; if (s->n > 0) byte_copyr(s->x + s->n,r,s->x); return r; } int buffer_bget(buffer *s,char *buf,unsigned int len) { int r; if (s->p > 0) return getthis(s,buf,len); if (s->n <= len) return oneread(s->op,s->fd,buf,s->n); r = buffer_feed(s); if (r <= 0) return r; return getthis(s,buf,len); } int buffer_get(buffer *s,char *buf,unsigned int len) { int r; if (s->p > 0) return getthis(s,buf,len); if (s->n <= len) return oneread(s->op,s->fd,buf,len); r = buffer_feed(s); if (r <= 0) return r; return getthis(s,buf,len); } char *buffer_peek(buffer *s) { return s->x + s->n; } void buffer_seek(buffer *s,unsigned int len) { s->n += len; s->p -= len; } checkpw-1.02/fmt_ulong.c0000644000175000017500000000047207232262067014215 0ustar ohiraohira#include "fmt.h" unsigned int fmt_ulong(register char *s,register unsigned long u) { register unsigned int len; register unsigned long q; len = 1; q = u; while (q > 9) { ++len; q /= 10; } if (s) { s += len; do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */ } return len; } checkpw-1.02/buffer_put.c0000644000175000017500000000331507232241103014347 0ustar ohiraohira#include "buffer.h" #include "str.h" #include "byte.h" #include "error.h" static int allwrite(int (*op)(),int fd,char *buf,unsigned int len) { int w; while (len) { w = op(fd,buf,len); if (w == -1) { if (errno == error_intr) continue; return -1; /* note that some data may have been written */ } if (w == 0) ; /* luser's fault */ buf += w; len -= w; } return 0; } int buffer_flush(buffer *s) { int p; p = s->p; if (!p) return 0; s->p = 0; return allwrite(s->op,s->fd,s->x,p); } int buffer_putalign(buffer *s,char *buf,unsigned int len) { unsigned int n; while (len > (n = s->n - s->p)) { byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n; if (buffer_flush(s) == -1) return -1; } /* now len <= s->n - s->p */ byte_copy(s->x + s->p,len,buf); s->p += len; return 0; } int buffer_put(buffer *s,char *buf,unsigned int len) { unsigned int n; n = s->n; if (len > n - s->p) { if (buffer_flush(s) == -1) return -1; /* now s->p == 0 */ if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE; while (len > s->n) { if (n > len) n = len; if (allwrite(s->op,s->fd,buf,n) == -1) return -1; buf += n; len -= n; } } /* now len <= s->n - s->p */ byte_copy(s->x + s->p,len,buf); s->p += len; return 0; } int buffer_putflush(buffer *s,char *buf,unsigned int len) { if (buffer_flush(s) == -1) return -1; return allwrite(s->op,s->fd,buf,len); } int buffer_putsalign(buffer *s,char *buf) { return buffer_putalign(s,buf,str_len(buf)); } int buffer_puts(buffer *s,char *buf) { return buffer_put(s,buf,str_len(buf)); } int buffer_putsflush(buffer *s,char *buf) { return buffer_putflush(s,buf,str_len(buf)); } checkpw-1.02/strerr_sys.c0000644000175000017500000000030407232241110014416 0ustar ohiraohira#include "error.h" #include "strerr.h" struct strerr strerr_sys; void strerr_sysinit(void) { strerr_sys.who = 0; strerr_sys.x = error_str(errno); strerr_sys.y = ""; strerr_sys.z = ""; } checkpw-1.02/stralloc_catb.c0000644000175000017500000000046607232241106015031 0ustar ohiraohira#include "stralloc.h" #include "byte.h" int stralloc_catb(stralloc *sa,char *s,unsigned int n) { if (!sa->s) return stralloc_copyb(sa,s,n); if (!stralloc_readyplus(sa,n + 1)) return 0; byte_copy(sa->s + sa->len,n,s); sa->len += n; sa->s[sa->len] = 'Z'; /* ``offensive programming'' */ return 1; } checkpw-1.02/stralloc_cats.c0000644000175000017500000000021707232241106015044 0ustar ohiraohira#include "byte.h" #include "str.h" #include "stralloc.h" int stralloc_cats(stralloc *sa,char *s) { return stralloc_catb(sa,s,str_len(s)); } checkpw-1.02/global.h0000644000175000017500000000142010631175725013463 0ustar ohiraohira/* GLOBAL.H - RSAREF types and constants */ #include /* PROTOTYPES should be set to one if and only if the compiler supports function argument prototyping. The following makes PROTOTYPES default to 0 if it has not already been defined with C compiler flags. */ #ifndef PROTOTYPES #define PROTOTYPES 0 #endif /* POINTER defines a generic pointer type */ typedef unsigned char *POINTER; /* UINT2 defines a two byte word */ typedef uint16_t UINT2; /* UINT4 defines a four byte word */ typedef uint32_t UINT4; /* PROTO_LIST is defined depending on how PROTOTYPES is defined above. If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it returns an empty list. */ #if PROTOTYPES #define PROTO_LIST(list) list #else #define PROTO_LIST(list) () #endif checkpw-1.02/buffer_copy.c0000644000175000017500000000042407232241102014506 0ustar ohiraohira#include "buffer.h" int buffer_copy(buffer *bout,buffer *bin) { int n; char *x; for (;;) { n = buffer_feed(bin); if (n < 0) return -2; if (!n) return 0; x = buffer_PEEK(bin); if (buffer_put(bout,x,n) == -1) return -3; buffer_SEEK(bin,n); } } checkpw-1.02/stralloc_eady.c0000644000175000017500000000031307232241106015031 0ustar ohiraohira#include "alloc.h" #include "stralloc.h" #include "gen_allocdefs.h" GEN_ALLOC_ready(stralloc,char,s,len,a,i,n,x,30,stralloc_ready) GEN_ALLOC_readyplus(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus) checkpw-1.02/byte.h0000644000175000017500000000040107232241101013145 0ustar ohiraohira#ifndef BYTE_H #define BYTE_H extern unsigned int byte_chr(); extern unsigned int byte_rchr(); extern void byte_copy(); extern void byte_copyr(); extern int byte_diff(); extern void byte_zero(); #define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) #endif checkpw-1.02/byte=l0000644000175000017500000000010207232243266013204 0ustar ohiraohirabyte_copy.o byte_cr.o byte_diff.o str_chr.o str_len.o str_start.o checkpw-1.02/exit.h0000644000175000017500000000007407232241107013167 0ustar ohiraohira#ifndef EXIT_H #define EXIT_H extern void _exit(); #endif checkpw-1.02/pathexec_env.c0000644000175000017500000000237707232241104014667 0ustar ohiraohira#include "stralloc.h" #include "alloc.h" #include "str.h" #include "byte.h" #include "env.h" #include "pathexec.h" static stralloc plus; static stralloc tmp; int pathexec_env(char *s,char *t) { if (!s) return 1; if (!stralloc_copys(&tmp,s)) return 0; if (t) { if (!stralloc_cats(&tmp,"=")) return 0; if (!stralloc_cats(&tmp,t)) return 0; } if (!stralloc_0(&tmp)) return 0; return stralloc_cat(&plus,&tmp); } void pathexec(char **argv) { char *path; char **e; unsigned int elen; unsigned int i; unsigned int j; unsigned int split; unsigned int t; if (!stralloc_cats(&plus,"")) return; elen = 0; for (i = 0;environ[i];++i) ++elen; for (i = 0;i < plus.len;++i) if (!plus.s[i]) ++elen; e = (char **) alloc((elen + 1) * sizeof(char *)); if (!e) return; elen = 0; for (i = 0;environ[i];++i) e[elen++] = environ[i]; j = 0; for (i = 0;i < plus.len;++i) if (!plus.s[i]) { split = str_chr(plus.s + j,'='); for (t = 0;t < elen;++t) if (byte_equal(plus.s + j,split,e[t])) if (e[t][split] == '=') { --elen; e[t] = e[elen]; break; } if (plus.s[j + split]) e[elen++] = plus.s + j; j = i + 1; } e[elen] = 0; pathexec_run(*argv,argv,e); alloc_free(e); } checkpw-1.02/hier.c0000644000175000017500000000033707306653611013153 0ustar ohiraohira#include "auto_home.h" void hier() { c(auto_home,"bin","checkpw",-1,-1,0700); c(auto_home,"bin","checkapoppw",-1,-1,0700); c(auto_home,"bin","selectcheckpw",-1,-1,0700); c(auto_home,"bin","loginlog",-1,-1,0755); } checkpw-1.02/run-multidir.sh0000644000175000017500000000040207416231027015033 0ustar ohiraohiraexec 2>&1 exec tcpserver -DRHv -llocalhost 0 110 \ softlimit -m 3000000 \ QMAIL/bin/qmail-popup `cat QMAIL/control/me` \ HOME/bin/checkpw \ HOME/bin/loginlog \ sh -c ' if [ -n "$EXT" ]; then dashext=-"$EXT"; fi exec QMAIL/bin/qmail-pop3d MAILDIR"$dashext" ' checkpw-1.02/pathexec_run.c0000644000175000017500000000172407232241105014677 0ustar ohiraohira#include "error.h" #include "stralloc.h" #include "str.h" #include "env.h" #include "pathexec.h" static stralloc tmp; void pathexec_run(char *file,char **argv,char **envp) { char *path; unsigned int split; int savederrno; if (file[str_chr(file,'/')]) { execve(file,argv,envp); return; } path = env_get("PATH"); if (!path) path = "/bin:/usr/bin"; savederrno = 0; for (;;) { split = str_chr(path,':'); if (!stralloc_copyb(&tmp,path,split)) return; if (!split) if (!stralloc_cats(&tmp,".")) return; if (!stralloc_cats(&tmp,"/")) return; if (!stralloc_cats(&tmp,file)) return; if (!stralloc_0(&tmp)) return; execve(tmp.s,argv,envp); if (errno != error_noent) { savederrno = errno; if ((errno != error_acces) && (errno != error_perm) && (errno != error_isdir)) return; } if (!path[split]) { if (savederrno) errno = savederrno; return; } path += split; path += 1; } } checkpw-1.02/run-pop.sh0000644000175000017500000000027607416231047014013 0ustar ohiraohiraexec 2>&1 exec tcpserver -DRHv -llocalhost 0 110 \ softlimit -m 3000000 \ QMAIL/bin/qmail-popup `cat QMAIL/control/me` \ HOME/bin/checkpw \ HOME/bin/loginlog \ QMAIL/bin/qmail-pop3d MAILDIR checkpw-1.02/substdo.c0000644000175000017500000000374507232262066013713 0ustar ohiraohira#include "substdio.h" #include "str.h" #include "byte.h" #include "error.h" static int allwrite(op,fd,buf,len) register int (*op)(); register int fd; register char *buf; register int len; { register int w; while (len) { w = op(fd,buf,len); if (w == -1) { if (errno == error_intr) continue; return -1; /* note that some data may have been written */ } if (w == 0) ; /* luser's fault */ buf += w; len -= w; } return 0; } int substdio_flush(s) register substdio *s; { register int p; p = s->p; if (!p) return 0; s->p = 0; return allwrite(s->op,s->fd,s->x,p); } int substdio_bput(s,buf,len) register substdio *s; register char *buf; register int len; { register int n; while (len > (n = s->n - s->p)) { byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n; if (substdio_flush(s) == -1) return -1; } /* now len <= s->n - s->p */ byte_copy(s->x + s->p,len,buf); s->p += len; return 0; } int substdio_put(s,buf,len) register substdio *s; register char *buf; register int len; { register int n; n = s->n; if (len > n - s->p) { if (substdio_flush(s) == -1) return -1; /* now s->p == 0 */ if (n < SUBSTDIO_OUTSIZE) n = SUBSTDIO_OUTSIZE; while (len > s->n) { if (n > len) n = len; if (allwrite(s->op,s->fd,buf,n) == -1) return -1; buf += n; len -= n; } } /* now len <= s->n - s->p */ byte_copy(s->x + s->p,len,buf); s->p += len; return 0; } int substdio_putflush(s,buf,len) register substdio *s; register char *buf; register int len; { if (substdio_flush(s) == -1) return -1; return allwrite(s->op,s->fd,buf,len); } int substdio_bputs(s,buf) register substdio *s; register char *buf; { return substdio_bput(s,buf,str_len(buf)); } int substdio_puts(s,buf) register substdio *s; register char *buf; { return substdio_put(s,buf,str_len(buf)); } int substdio_putsflush(s,buf) register substdio *s; register char *buf; { return substdio_putflush(s,buf,str_len(buf)); } checkpw-1.02/md5c.c0000644000175000017500000002426707232252642013061 0ustar ohiraohira/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing this software or this function. License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing the derived work. RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. */ #include "global.h" #include "md5.h" /* Constants for MD5Transform routine. */ #define S11 7 #define S12 12 #define S13 17 #define S14 22 #define S21 5 #define S22 9 #define S23 14 #define S24 20 #define S31 4 #define S32 11 #define S33 16 #define S34 23 #define S41 6 #define S42 10 #define S43 15 #define S44 21 static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int)); static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int)); static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* F, G, H and I are basic MD5 functions. */ #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | (~z))) /* ROTATE_LEFT rotates x left n bits. */ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation. */ #define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } /* MD5 initialization. Begins an MD5 operation, writing a new context. */ void MD5Init (context) MD5_CTX *context; /* context */ { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; } /* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ void MD5Update (context, input, inputLen) MD5_CTX *context; /* context */ unsigned char *input; /* input block */ unsigned int inputLen; /* length of input block */ { unsigned int i, index, partLen; /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3)) context->count[1]++; context->count[1] += ((UINT4)inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { MD5_memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen); MD5Transform (context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) MD5Transform (context->state, &input[i]); index = 0; } else i = 0; /* Buffer remaining input */ MD5_memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); } /* MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context. */ void MD5Final (digest, context) unsigned char digest[16]; /* message digest */ MD5_CTX *context; /* context */ { unsigned char bits[8]; unsigned int index, padLen; /* Save number of bits */ Encode (bits, context->count, 8); /* Pad out to 56 mod 64. */ index = (unsigned int)((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); MD5Update (context, PADDING, padLen); /* Append length (before padding) */ MD5Update (context, bits, 8); /* Store state in digest */ Encode (digest, context->state, 16); /* Zeroize sensitive information. */ MD5_memset ((POINTER)context, 0, sizeof (*context)); } /* MD5 basic transformation. Transforms state based on block. */ static void MD5Transform (state, block) UINT4 state[4]; unsigned char block[64]; { UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; Decode (x, block, 64); /* Round 1 */ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ /* Round 2 */ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ /* Round 3 */ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ /* Round 4 */ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; /* Zeroize sensitive information. */ MD5_memset ((POINTER)x, 0, sizeof (x)); } /* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4. */ static void Encode (output, input, len) unsigned char *output; UINT4 *input; unsigned int len; { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) { output[j] = (unsigned char)(input[i] & 0xff); output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); } } /* Decodes input (unsigned char) into output (UINT4). Assumes len is a multiple of 4. */ static void Decode (output, input, len) UINT4 *output; unsigned char *input; unsigned int len; { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } /* Note: Replace "for loop" with standard memcpy if possible. */ static void MD5_memcpy (output, input, len) POINTER output; POINTER input; unsigned int len; { unsigned int i; for (i = 0; i < len; i++) output[i] = input[i]; } /* Note: Replace "for loop" with standard memset if possible. */ static void MD5_memset (output, value, len) POINTER output; int value; unsigned int len; { unsigned int i; for (i = 0; i < len; i++) ((char *)output)[i] = (char)value; } checkpw-1.02/byte_cr.c0000644000175000017500000000050407232243317013643 0ustar ohiraohira#include "byte.h" void byte_copyr(to,n,from) register char *to; register unsigned int n; register char *from; { to += n; from += n; for (;;) { if (!n) return; *--to = *--from; --n; if (!n) return; *--to = *--from; --n; if (!n) return; *--to = *--from; --n; if (!n) return; *--to = *--from; --n; } } checkpw-1.02/conf-password0000644000175000017500000000005407306610665014566 0ustar ohiraohira.password This is the plain passowrd file. checkpw-1.02/stralloc_pend.c0000644000175000017500000000023107232241107015035 0ustar ohiraohira#include "alloc.h" #include "stralloc.h" #include "gen_allocdefs.h" GEN_ALLOC_append(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus,stralloc_append) checkpw-1.02/stralloc_opyb.c0000644000175000017500000000036507232241107015070 0ustar ohiraohira#include "stralloc.h" #include "byte.h" int stralloc_copyb(stralloc *sa,char *s,unsigned int n) { if (!stralloc_ready(sa,n + 1)) return 0; byte_copy(sa->s,n,s); sa->len = n; sa->s[n] = 'Z'; /* ``offensive programming'' */ return 1; } checkpw-1.02/stralloc_opys.c0000644000175000017500000000022107232241107015100 0ustar ohiraohira#include "byte.h" #include "str.h" #include "stralloc.h" int stralloc_copys(stralloc *sa,char *s) { return stralloc_copyb(sa,s,str_len(s)); } checkpw-1.02/open.h0000644000175000017500000000030107232241212013145 0ustar ohiraohira#ifndef OPEN_H #define OPEN_H extern int open_read(char *); extern int open_excl(char *); extern int open_append(char *); extern int open_trunc(char *); extern int open_write(char *); #endif checkpw-1.02/prot.c0000644000175000017500000000056507232241105013200 0ustar ohiraohira#include "hasshsgr.h" #include "prot.h" int prot_gid(int gid) { #ifdef HASSHORTSETGROUPS short x[2]; x[0] = gid; x[1] = 73; /* catch errors */ if (setgroups(1,x) == -1) return -1; #else if (setgroups(1,&gid) == -1) return -1; #endif return setgid(gid); /* _should_ be redundant, but on some systems it isn't */ } int prot_uid(int uid) { return setuid(uid); } checkpw-1.02/prot.h0000644000175000017500000000013307232241105013174 0ustar ohiraohira#ifndef PROT_H #define PROT_H extern int prot_gid(int); extern int prot_uid(int); #endif checkpw-1.02/selectcheckpw.sh0000644000175000017500000000020107306651056015227 0ustar ohiraohiracase "$AUTH" in apop) exec HOME/bin/checkapoppw $* ;; pop) exec HOME/bin/checkpw $* ;; *) exit 1 ;; esac checkpw-1.02/conf-patrn0000644000175000017500000000006707232242323014042 0ustar ohiraohira077 These stat bits are not allowed in password file. checkpw-1.02/conf-qmail0000644000175000017500000000101107306647061014021 0ustar ohiraohira/var/qmail This is the qmail home directory. It must be a local directory, not shared among machines. This is where qmail queues all mail messages. The queue (except for bounce message contents) is crashproof, if the filesystem guarantees that single-byte writes are atomic and that directory operations are synchronous. These guarantees are provided by fixed-block filesystems such as UFS and by journaling filesystems. Under Linux, make sure that all mail-handling filesystems are mounted with synchronous metadata. checkpw-1.02/auto-str.c0000644000175000017500000000132007232261061013763 0ustar ohiraohira#include "buffer.h" #include "readwrite.h" #include "exit.h" char bspace[256]; buffer b = BUFFER_INIT(write,1,bspace,sizeof bspace); void puts(char *s) { if (buffer_puts(&b,s) == -1) _exit(111); } main(int argc,char **argv) { char *name; char *value; unsigned char ch; char octal[4]; name = argv[1]; if (!name) _exit(100); value = argv[2]; if (!value) _exit(100); puts("const char "); puts(name); puts("[] = \"\\\n"); while (ch = *value++) { puts("\\"); octal[3] = 0; octal[2] = '0' + (ch & 7); ch >>= 3; octal[1] = '0' + (ch & 7); ch >>= 3; octal[0] = '0' + (ch & 7); puts(octal); } puts("\\\n\";\n"); if (buffer_flush(&b) == -1) _exit(111); _exit(0); } checkpw-1.02/auto-str=x0000644000175000017500000000001607232261345014035 0ustar ohiraohiraunix.a byte.a checkpw-1.02/buffer.c0000644000175000017500000000024707232241101013456 0ustar ohiraohira#include "buffer.h" void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len) { s->x = buf; s->fd = fd; s->op = op; s->p = 0; s->n = len; } checkpw-1.02/buffer.h0000644000175000017500000000267407232241101013471 0ustar ohiraohira#ifndef BUFFER_H #define BUFFER_H typedef struct buffer { char *x; unsigned int p; unsigned int n; int fd; int (*op)(); } buffer; #define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } #define BUFFER_INSIZE 8192 #define BUFFER_OUTSIZE 8192 extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int); extern int buffer_flush(buffer *); extern int buffer_put(buffer *,char *,unsigned int); extern int buffer_putalign(buffer *,char *,unsigned int); extern int buffer_putflush(buffer *,char *,unsigned int); extern int buffer_puts(buffer *,char *); extern int buffer_putsalign(buffer *,char *); extern int buffer_putsflush(buffer *,char *); #define buffer_PUTC(s,c) \ ( ((s)->n != (s)->p) \ ? ( (s)->x[(s)->p++] = (c), 0 ) \ : buffer_put((s),&(c),1) \ ) extern int buffer_get(buffer *,char *,unsigned int); extern int buffer_bget(buffer *,char *,unsigned int); extern int buffer_feed(buffer *); extern char *buffer_peek(buffer *); extern void buffer_seek(buffer *,unsigned int); #define buffer_PEEK(s) ( (s)->x + (s)->n ) #define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) #define buffer_GETC(s,c) \ ( ((s)->p > 0) \ ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ : buffer_get((s),(c),1) \ ) extern int buffer_copy(buffer *,buffer *); extern buffer *buffer_0; extern buffer *buffer_0small; extern buffer *buffer_1; extern buffer *buffer_1small; extern buffer *buffer_2; #endif checkpw-1.02/default.do0000644000175000017500000001017107307044437014026 0ustar ohiraohiraif test -r $1=x then dependon $1=x libs=`grep '\.lib *$' "$1=x"` libscat='' for i in $libs do libscat="$libscat "'`'"cat $i"'`' done objs=`grep -v '\.lib *$' "$1=x"` dependon load $1.o $objs $libs directtarget formake ./load $1 $objs "$libscat" eval ./load $1 $objs $libscat exit 0 fi if test -r $1=X then dependon $1=X libs=`grep '\.lib *$' "$1=X"` libscat='' for i in $libs do libscat="$libscat "'`'"cat $i"'`' done objs=`grep -v '\.lib *$' "$1=X"` dependon loads $1.o $objs $libs directtarget formake ./loads $1 $objs "$libscat" eval ./loads $1 $objs $libscat exit 0 fi if test -r $1=s then dependon $1=s warn-auto.sh $1.sh conf-home formake cat warn-auto.sh $1.sh '\' formake '| sed s}HOME}"`head -1 conf-home`"}g \' formake '| sed s}QMAIL}"`head -1 conf-qmail`"}g \' formake '| sed s}MAILDIR}"`head -1 conf-maildir`"}g \' formake '>' $1 formake chmod 755 $1 cat warn-auto.sh cat $1.sh \ | sed s}HOME}"`head -1 conf-home`"}g \ | sed s}QMAIL}"`head -1 conf-qmail`"}g \ | sed s}MAILDIR}"`head -1 conf-maildir`"}g chmod 755 $3 exit 0 fi case $1 in check) dependon it instcheck formake ./instcheck ./instcheck directtarget exit 0 ;; compile) dependon warn-auto.sh conf-cc formake "( cat warn-auto.sh; \\" formake echo exec '"`head -1 conf-cc`"' \''-c $${1+"$$@"}'\' "\\" formake ") > compile" formake "chmod 755 compile" ( cat warn-auto.sh echo exec "`head -1 conf-cc`" '-c ${1+"$@"}' ) chmod 755 $3 exit 0 ;; it) dependon prog install instcheck directtarget exit 0 ;; load) dependon warn-auto.sh conf-ld formake "( cat warn-auto.sh; \\" formake echo "'"'main="$$1"; shift'"'""; \\" formake echo exec '"`head -1 conf-ld`"' "\\" formake "'"'-o "$$main" "$$main".o $${1+"$$@"}'"'" "\\" formake ") > load" formake "chmod 755 load" cat warn-auto.sh echo 'main="$1"; shift' echo exec "`head -1 conf-ld`" '-o "$main" "$main".o ${1+"$@"}' chmod 755 $3 exit 0 ;; loads) dependon warn-auto.sh conf-lds formake "( cat warn-auto.sh; \\" formake echo "'"'main="$$1"; shift'"'""; \\" formake echo exec '"`head -1 conf-lds`"' "\\" formake "'"'-o "$$main" "$$main".o $${1+"$$@"}'"'" "\\" formake ") > loads" formake "chmod 755 loads" cat warn-auto.sh echo 'main="$1"; shift' echo exec "`head -1 conf-lds`" '-o "$main" "$main".o ${1+"$@"}' chmod 755 $3 exit 0 ;; makelib) dependon warn-auto.sh systype formake "( cat warn-auto.sh; \\" formake echo \''main="$$1"; shift'\'"; \\" formake echo \''rm -f "$$main"'\'"; \\" formake echo \''ar cr "$$main" $${1+"$$@"}'\'"; \\" formake 'case "`cat systype`" in \' formake "sunos-5.*) ;; \\" formake "unix_sv*) ;; \\" formake "irix64-*) ;; \\" formake "irix-*) ;; \\" formake "dgux-*) ;; \\" formake "hp-ux-*) ;; \\" formake "sco*) ;; \\" formake "*)" echo \''ranlib "$$main"'\'" ;; \\" formake "esac \\" formake ") > makelib" formake "chmod 755 makelib" ( cat warn-auto.sh; echo 'main="$1"; shift'; echo 'rm -f "$main"'; echo 'ar cr "$main" ${1+"$@"}'; case "`cat systype`" in sunos-5.*) ;; unix_sv*) ;; irix64-*) ;; irix-*) ;; dgux-*) ;; hp-ux-*) ;; sco*) ;; *) echo 'ranlib "$main"' ;; esac ) chmod 755 $3 exit 0 ;; setup) dependon it install formake ./install ./install directtarget exit 0 ;; systype) dependon find-systype.sh conf-cc conf-ld trycpp.c x86cpuid.c formake "( cat warn-auto.sh; \\" formake echo CC="\\'"'`head -1 conf-cc`'"\\'; \\" formake echo LD="\\'"'`head -1 conf-ld`'"\\'; \\" formake "cat find-systype.sh; \\" formake ") | sh > systype" ( cat warn-auto.sh echo CC=\'\"`head -1 conf-cc`\"\' echo LD=\'\"`head -1 conf-ld`\"\' cat find-systype.sh ) | sh exit 0 ;; test) dependon prog rts rts.tests rts.exp formake './rts | cmp - rts.exp >&2' ./rts | cmp - rts.exp >&2 directtarget exit 0 ;; esac nosuchtarget checkpw-1.02/scan.h0000644000175000017500000000255707232261062013154 0ustar ohiraohira#ifndef SCAN_H #define SCAN_H extern unsigned int scan_uint(const char *,unsigned int *); extern unsigned int scan_xint(const char *,unsigned int *); extern unsigned int scan_nbbint(const char *,unsigned int,unsigned int,unsigned int,unsigned int *); extern unsigned int scan_ushort(const char *,unsigned short *); extern unsigned int scan_xshort(const char *,unsigned short *); extern unsigned int scan_nbbshort(const char *,unsigned int,unsigned int,unsigned int,unsigned short *); extern unsigned int scan_ulong(const char *,unsigned long *); extern unsigned int scan_xlong(const char *,unsigned long *); extern unsigned int scan_nbblong(const char *,unsigned int,unsigned int,unsigned int,unsigned long *); extern unsigned int scan_plusminus(const char *,int *); extern unsigned int scan_0x(const char *,unsigned int *); extern unsigned int scan_whitenskip(const char *,unsigned int); extern unsigned int scan_nonwhitenskip(const char *,unsigned int); extern unsigned int scan_charsetnskip(const char *,const char *,unsigned int); extern unsigned int scan_noncharsetnskip(const char *,const char *,unsigned int); extern unsigned int scan_strncmp(const char *,const char *,unsigned int); extern unsigned int scan_memcmp(const char *,const char *,unsigned int); extern unsigned int scan_long(const char *,long *); extern unsigned int scan_8long(const char *,unsigned long *); #endif checkpw-1.02/run-apop.sh0000644000175000017500000000030207416231005014134 0ustar ohiraohiraexec 2>&1 exec tcpserver -DRHv -llocalhost 0 110 \ softlimit -m 3000000 \ QMAIL/bin/qmail-popup `cat QMAIL/control/me` \ HOME/bin/checkapoppw \ HOME/bin/loginlog \ QMAIL/bin/qmail-pop3d MAILDIR checkpw-1.02/conf-maildir0000644000175000017500000000005007306610476014341 0ustar ohiraohiraMaildir This is the maildir directory. checkpw-1.02/readwrite.h0000644000175000017500000000013007232241102014170 0ustar ohiraohira#ifndef READWRITE_H #define READWRITE_H extern int read(); extern int write(); #endif checkpw-1.02/unix=l0000644000175000017500000000055707232262062013235 0ustar ohiraohiraalloc.o alloc_re.o buffer.o buffer_2.o buffer_copy.o buffer_get.o buffer_put.o env.o error.o error_str.o open_read.o open_trunc.o openreadclose.o readclose.o pathexec_env.o pathexec_run.o prot.o stralloc_cat.o stralloc_catb.o stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o stralloc_pend.o strerr_die.o strerr_sys.o substdo.o scan_8long.o fmt_ulong.o checkpw-1.02/hasshsgr.h0000644000175000017500000000003607232241105014034 0ustar ohiraohira/* sysdep: -shortsetgroups */ checkpw-1.02/checkpw.c0000644000175000017500000000467007416246407013657 0ustar ohiraohira#include #include "error.h" #include "pathexec.h" #include "prot.h" #include "stralloc.h" #include "openreadclose.h" #include "env.h" #include "auto_maildir.h" #include "auto_password.h" #include "auto_patrn.h" #include static struct passwd *pw; static char up[513]; static int uplen; static stralloc stored = {0}; static stralloc pwfile = {0}; void cleanup() { int i; for (i = 0;i < sizeof(up);++i) up[i] = 0; for (i = 0;i < stored.len;++i) stored.s[i] = 0; } void die(int x) { cleanup(); _exit(x); } main(int argc,char **argv) { char *login; char *dash; char *ext; char *password; struct stat st; int r; int i; if (!argv[1]) _exit(2); dash = env_get("DASH"); uplen = 0; for (;;) { do r = read(3,up + uplen,sizeof(up) - uplen); while ((r == -1) && (errno == error_intr)); if (r == -1) _exit(111); if (r == 0) break; uplen += r; if (uplen >= sizeof(up)) _exit(1); } close(3); i = 0; if (i >= uplen) _exit(2); login = up + i; while (up[i++]) if (i >= uplen) _exit(2); password = up + i; if (i >= uplen) _exit(2); while (up[i++]) if (i >= uplen) _exit(2); i = 0; ext = login + str_len(login); for (;;) { pw = getpwnam(login); if (pw) break; if (errno == error_txtbsy) die(111); for (; ext != login && *ext != '-'; --ext); if (ext == login) die(1); if (i) login[i] = '-'; i = ext - login; login[i] = 0; ++ext; } if (chdir(pw->pw_dir) == -1) die(111); if (!stralloc_copys(&pwfile, auto_maildir)) die(111); if (dash && *ext) { if (!stralloc_cats(&pwfile, dash)) die(111); if (!stralloc_cats(&pwfile, ext)) die(111); } if (!stralloc_append(&pwfile, "/")) die(111); if (!stralloc_cats(&pwfile, auto_password)) die(111); if (!stralloc_0(&pwfile)) die(111); if (stat(pwfile.s,&st) == -1) die(1); if (st.st_uid != pw->pw_uid) die(1); if (st.st_mode & auto_patrn) die(111); if (openreadclose(pwfile.s,&stored,32) != 1) die(111); if (!stralloc_0(&stored)) die(111); stored.s[str_chr(stored.s,'\n')] = 0; if (!*stored.s || strcmp(password,stored.s)) die(1); if (prot_gid((int) pw->pw_gid) == -1) die(1); if (prot_uid((int) pw->pw_uid) == -1) die(1); if (!pathexec_env("USER",pw->pw_name)) die(111); if (!pathexec_env("EXT",ext)) die(111); if (!pathexec_env("HOME",pw->pw_dir)) die(111); if (!pathexec_env("SHELL",pw->pw_shell)) die(111); cleanup(); pathexec(argv + 1); _exit(111); } checkpw-1.02/checkpw=x0000644000175000017500000000007207306611052013701 0ustar ohiraohiraauto_maildir.o auto_password.o auto_patrn.o unix.a byte.a checkpw-1.02/readclose.c0000644000175000017500000000102707232244422014154 0ustar ohiraohira#include #include "error.h" #include "readclose.h" int readclose_append(int fd,stralloc *sa,unsigned int bufsize) { int r; for (;;) { if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; } r = read(fd,sa->s + sa->len,bufsize); if (r == -1) if (errno == error_intr) continue; if (r <= 0) { close(fd); return r; } sa->len += r; } } int readclose(int fd,stralloc *sa,unsigned int bufsize) { if (!stralloc_copys(sa,"")) { close(fd); return -1; } return readclose_append(fd,sa,bufsize); } checkpw-1.02/readclose.h0000644000175000017500000000026507232244422014164 0ustar ohiraohira#ifndef READCLOSE_H #define READCLOSE_H #include "stralloc.h" extern int readclose_append(int,stralloc *,unsigned int); extern int readclose(int,stralloc *,unsigned int); #endif checkpw-1.02/alloc.c0000644000175000017500000000150107232241101013271 0ustar ohiraohira#include "alloc.h" #include "error.h" extern char *malloc(); extern void free(); #define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ #define SPACE 2048 /* must be multiple of ALIGNMENT */ typedef union { char irrelevant[ALIGNMENT]; double d; } aligned; static aligned realspace[SPACE / ALIGNMENT]; #define space ((char *) realspace) static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ /*@null@*//*@out@*/char *alloc(n) unsigned int n; { char *x; n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ if (n <= avail) { avail -= n; return space + avail; } x = malloc(n); if (!x) errno = error_nomem; return x; } void alloc_free(x) char *x; { if (x >= space) if (x < space + SPACE) return; /* XXX: assuming that pointers are flat */ free(x); } checkpw-1.02/alloc.h0000644000175000017500000000020307232241101013274 0ustar ohiraohira#ifndef ALLOC_H #define ALLOC_H extern /*@null@*//*@out@*/char *alloc(); extern void alloc_free(); extern int alloc_re(); #endif checkpw-1.02/pathexec.h0000644000175000017500000000025007232241105014011 0ustar ohiraohira#ifndef PATHEXEC_H #define PATHEXEC_H extern void pathexec_run(char *,char **,char **); extern int pathexec_env(char *,char *); extern void pathexec(char **); #endif checkpw-1.02/gen_alloc.h0000644000175000017500000000025507232241104014137 0ustar ohiraohira#ifndef GEN_ALLOC_H #define GEN_ALLOC_H #define GEN_ALLOC_typedef(ta,type,field,len,a) \ typedef struct ta { type *field; unsigned int len; unsigned int a; } ta; #endif checkpw-1.02/stralloc_cat.c0000644000175000017500000000022307232241105014655 0ustar ohiraohira#include "byte.h" #include "stralloc.h" int stralloc_cat(stralloc *sato,stralloc *safrom) { return stralloc_catb(sato,safrom->s,safrom->len); } checkpw-1.02/run-pop=s0000644000175000017500000000000007306650414013644 0ustar ohiraohiracheckpw-1.02/INSTALL0000644000175000017500000000510307436337035013110 0ustar ohiraohiraLike any other piece of software (and information generally), checkpw comes with NO WARRANTY. Things you have to decide before starting: * The checkpw home directory, normally /. To change this directory, edit conf-home now. * The qmail home directory, normally /var/qmail. To change this directory, edit conf-qmail now. * The maildir directory, normally Maildir. To change this name, edit conf-maildir now. * The password file, normally .password. To change this name, edit conf-password now. How to install: 1. Compile the programs: % make 2. Install the programs: # make setup check How to set password: 3. Create password file: % echo 'YOURPASSWORD' > ~/Maildir/.password % chmod 600 ~/Maildir/.password Replace YOURPASSWORD with your plain password. How to setup service: o POP service Use checkpw instead of checkpassword. run-pop is the sample run script. o APOP service Use checkapoppw instead of checkpassword. run-apop is the sample run script. o Selective authenticate method per client address Set $AUTH with "pop" or "apop". tcpserver can set environment variables per client address. For example 10.:allow,AUTH="pop" :allow,AUTH="apop" then use selectcheckpw instead of checkpassword. run-rules is the sample run script. o Both POP and APOP service Activate POP and APOP services on the different port. o Both POP and APOP service on the same port Patch qmail-popup-auth.patch against qmail-1.03, then use selectcheckpw instead of checkpassword. run-both is the sample run script. o Multiple Maildirs per POP3 user If login name contains extension, checkpw sets up $EXT. For example, if login name is foo-bar, checkpw checks ~foo/Maildir/.password and sets up $USER="foo" and $EXT="bar". So you can set maildir before invoking qmail-pop3d. run-multidir is the sample run script. o Multiple password per maildir If $DASH is set and login name contains extension, checkpw checks ~user/Maildir$DASH$EXT/.password. For example, if $DASH is "-" and login name is foo-bar, checkpw checks ~foo/Maildir-bar/.password and sets up $USER="foo" and $EXT="bar". In this case, you should set maildir before invoking qmail-pop3d. run-multipw is the sample run script. o POP before SMTP Use relay-ctrl if you want to control SMTP access to relaying for users that authenticate using POP or APOP. http://untroubled.org/relay-ctrl/ o Virtual users Use vucheckpw if you don't like having services which are running as root. http://checkpw.sourceforge.net/vucheckpw/ checkpw-1.02/find-systype.sh0000644000175000017500000000640407232241100015033 0ustar ohiraohira# oper-:arch-:syst-:chip-:kern- # oper = operating system type; e.g., sunos-4.1.4 # arch = machine language; e.g., sparc # syst = which binaries can run; e.g., sun4 # chip = chip model; e.g., micro-2-80 # kern = kernel version; e.g., sun4m # dependence: arch --- chip # \ \ # oper --- syst --- kern # so, for example, syst is interpreted in light of oper, but chip is not. # anyway, no slashes, no extra colons, no uppercase letters. # the point of the extra -'s is to ease parsing: can add hierarchies later. # e.g., *:i386-*:*:pentium-*:* would handle pentium-100 as well as pentium, # and i386-486 (486s do have more instructions, you know) as well as i386. # the idea here is to include ALL useful available information. exec 2>/dev/null sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`" if [ x"$sys" != x ] then unamer="`uname -r | tr /: ..`" unamem="`uname -m | tr /: ..`" unamev="`uname -v | tr /: ..`" case "$sys" in bsd.os|freebsd|netbsd|openbsd) # in bsd 4.4, uname -v does not have useful info. # in bsd 4.4, uname -m is arch, not chip. oper="$sys-$unamer" arch="$unamem" syst="" chip="`sysctl -n hw.model`" # hopefully kern="" ;; linux) # as in bsd 4.4, uname -v does not have useful info. oper="$sys-$unamer" syst="" chip="$unamem" kern="" case "$chip" in i386|i486|i586|i686) arch="i386" ;; alpha) arch="alpha" ;; esac ;; aix) # naturally IBM has to get uname -r and uname -v backwards. dorks. oper="$sys-$unamev-$unamer" arch="`arch | tr /: ..`" syst="" chip="$unamem" kern="" ;; sunos) oper="$sys-$unamer-$unamev" arch="`(uname -p || mach) | tr /: ..`" syst="`arch | tr /: ..`" chip="$unamem" # this is wrong; is there any way to get the real info? kern="`arch -k | tr /: ..`" ;; unix_sv) oper="$sys-$unamer-$unamev" arch="`uname -m`" syst="" chip="$unamem" kern="" ;; *) oper="$sys-$unamer-$unamev" arch="`arch | tr /: ..`" syst="" chip="$unamem" kern="" ;; esac else gcc -c trycpp.c gcc -o trycpp trycpp.o case `./trycpp` in nextstep) oper="nextstep-`hostinfo | sed -n 's/^[ ]*NeXT Mach \([^:]*\):.*$/\1/p'`" arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`" syst="" chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`" kern="" ;; *) oper="unknown" arch="" syst="" chip="" kern="" ;; esac rm -f trycpp.o trycpp fi case "$chip" in 80486) # let's try to be consistent here. (BSD/OS) chip=i486 ;; i486DX) # respect the hyphen hierarchy. (FreeBSD) chip=i486-dx ;; i486.DX2) # respect the hyphen hierarchy. (FreeBSD) chip=i486-dx2 ;; Intel.586) # no, you nitwits, there is no such chip. (NeXTStep) chip=pentium ;; i586) # no, you nitwits, there is no such chip. (Linux) chip=pentium ;; i686) # STOP SAYING THAT! (Linux) chip=ppro esac if gcc -c x86cpuid.c then if gcc -o x86cpuid x86cpuid.o then x86cpuid="`./x86cpuid | tr /: ..`" case "$x86cpuid" in ?*) chip="$x86cpuid" ;; esac fi fi rm -f x86cpuid x86cpuid.o echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]' checkpw-1.02/run-both.sh0000644000175000017500000000030407416231016014135 0ustar ohiraohiraexec 2>&1 exec tcpserver -DRHv -llocalhost 0 110 \ softlimit -m 3000000 \ QMAIL/bin/qmail-popup `cat QMAIL/control/me` \ HOME/bin/selectcheckpw \ HOME/bin/loginlog \ QMAIL/bin/qmail-pop3d MAILDIR checkpw-1.02/buffer_2.c0000644000175000017500000000025407232241102013676 0ustar ohiraohira#include "readwrite.h" #include "buffer.h" char buffer_2_space[256]; static buffer it = BUFFER_INIT(write,2,buffer_2_space,sizeof buffer_2_space); buffer *buffer_2 = ⁢ checkpw-1.02/substdio.h0000644000175000017500000000171407232261061014055 0ustar ohiraohira#ifndef SUBSTDIO_H #define SUBSTDIO_H typedef struct substdio { char *x; int p; int n; int fd; int (*op)(); } substdio; #define SUBSTDIO_FDBUF(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } extern void substdio_fdbuf(); extern int substdio_flush(); extern int substdio_put(); extern int substdio_bput(); extern int substdio_putflush(); extern int substdio_puts(); extern int substdio_bputs(); extern int substdio_putsflush(); extern int substdio_get(); extern int substdio_bget(); extern int substdio_feed(); extern char *substdio_peek(); extern void substdio_seek(); #define substdio_fileno(s) ((s)->fd) #define SUBSTDIO_INSIZE 8192 #define SUBSTDIO_OUTSIZE 8192 #define substdio_PEEK(s) ( (s)->x + (s)->n ) #define substdio_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) #define substdio_BPUTC(s,c) \ ( ((s)->n != (s)->p) \ ? ( (s)->x[(s)->p++] = (c), 0 ) \ : substdio_bput((s),&(c),1) \ ) extern int substdio_copy(); #endif checkpw-1.02/run-multidir=s0000644000175000017500000000000007306651343014701 0ustar ohiraohiracheckpw-1.02/run-multipw.sh0000644000175000017500000000043007416231037014705 0ustar ohiraohiraexport DASH="-" exec 2>&1 exec tcpserver -DRHv -llocalhost 0 110 \ softlimit -m 3000000 \ QMAIL/bin/qmail-popup `cat QMAIL/control/me` \ HOME/bin/checkpw \ HOME/bin/loginlog \ sh -c ' if [ -n "$EXT" ]; then dashext="$DASH""$EXT"; fi exec QMAIL/bin/qmail-pop3d MAILDIR"$dashext" ' checkpw-1.02/byte_copy.c0000644000175000017500000000045307232243317014214 0ustar ohiraohira#include "byte.h" void byte_copy(to,n,from) register char *to; register unsigned int n; register char *from; { for (;;) { if (!n) return; *to++ = *from++; --n; if (!n) return; *to++ = *from++; --n; if (!n) return; *to++ = *from++; --n; if (!n) return; *to++ = *from++; --n; } } checkpw-1.02/byte_diff.c0000644000175000017500000000070507232243320014144 0ustar ohiraohira#include "byte.h" int byte_diff(s,n,t) register char *s; register unsigned int n; register char *t; { for (;;) { if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; } return ((int)(unsigned int)(unsigned char) *s) - ((int)(unsigned int)(unsigned char) *t); } checkpw-1.02/loginlog.sh0000644000175000017500000000015307306646670014231 0ustar ohiraohiraecho "$TCPREMOTEIP" "$TCPLOCALPORT" "$USER" | QMAIL/bin/splogger login 2 pop="$1"; shift; exec "$pop" "$@" checkpw-1.02/auto-int8.c0000644000175000017500000000122407232261061014040 0ustar ohiraohira#include "substdio.h" #include "readwrite.h" #include "exit.h" #include "scan.h" #include "fmt.h" char buf1[256]; substdio ss1 = SUBSTDIO_FDBUF(write,1,buf1,sizeof(buf1)); void puts(s) char *s; { if (substdio_puts(&ss1,s) == -1) _exit(111); } void main(argc,argv) int argc; char **argv; { char *name; char *value; unsigned long num; char strnum[FMT_ULONG]; name = argv[1]; if (!name) _exit(100); value = argv[2]; if (!value) _exit(100); scan_8long(value,&num); strnum[fmt_ulong(strnum,num)] = 0; puts("int "); puts(name); puts(" = "); puts(strnum); puts(";\n"); if (substdio_flush(&ss1) == -1) _exit(111); _exit(0); } checkpw-1.02/auto-int8=x0000644000175000017500000000001607232261355014110 0ustar ohiraohiraunix.a byte.a checkpw-1.02/error_str.c0000644000175000017500000001256307232241103014234 0ustar ohiraohira#include #include "error.h" #define X(e,s) if (i == e) return s; char *error_str(int i) { X(0,"no error") X(error_intr,"interrupted system call") X(error_nomem,"out of memory") X(error_noent,"file does not exist") X(error_txtbsy,"text busy") X(error_io,"input/output error") X(error_exist,"file already exists") X(error_timeout,"timed out") X(error_inprogress,"operation in progress") X(error_again,"temporary failure") X(error_wouldblock,"input/output would block") X(error_pipe,"broken pipe") X(error_perm,"permission denied") X(error_acces,"access denied") X(error_nodevice,"device not configured") X(error_proto,"protocol error") X(error_isdir,"is a directory") X(error_connrefused,"connection refused") #ifdef ESRCH X(ESRCH,"no such process") #endif #ifdef E2BIG X(E2BIG,"argument list too long") #endif #ifdef ENOEXEC X(ENOEXEC,"exec format error") #endif #ifdef EBADF X(EBADF,"file descriptor not open") #endif #ifdef ECHILD X(ECHILD,"no child processes") #endif #ifdef EDEADLK X(EDEADLK,"operation would cause deadlock") #endif #ifdef EFAULT X(EFAULT,"bad address") #endif #ifdef ENOTBLK X(ENOTBLK,"not a block device") #endif #ifdef EBUSY X(EBUSY,"device busy") #endif #ifdef EXDEV X(EXDEV,"cross-device link") #endif #ifdef ENODEV X(ENODEV,"device does not support operation") #endif #ifdef ENOTDIR X(ENOTDIR,"not a directory") #endif #ifdef EINVAL X(EINVAL,"invalid argument") #endif #ifdef ENFILE X(ENFILE,"system cannot open more files") #endif #ifdef EMFILE X(EMFILE,"process cannot open more files") #endif #ifdef ENOTTY X(ENOTTY,"not a tty") #endif #ifdef EFBIG X(EFBIG,"file too big") #endif #ifdef ENOSPC X(ENOSPC,"out of disk space") #endif #ifdef ESPIPE X(ESPIPE,"unseekable descriptor") #endif #ifdef EROFS X(EROFS,"read-only file system") #endif #ifdef EMLINK X(EMLINK,"too many links") #endif #ifdef EDOM X(EDOM,"input out of range") #endif #ifdef ERANGE X(ERANGE,"output out of range") #endif #ifdef EALREADY X(EALREADY,"operation already in progress") #endif #ifdef ENOTSOCK X(ENOTSOCK,"not a socket") #endif #ifdef EDESTADDRREQ X(EDESTADDRREQ,"destination address required") #endif #ifdef EMSGSIZE X(EMSGSIZE,"message too long") #endif #ifdef EPROTOTYPE X(EPROTOTYPE,"incorrect protocol type") #endif #ifdef ENOPROTOOPT X(ENOPROTOOPT,"protocol not available") #endif #ifdef EPROTONOSUPPORT X(EPROTONOSUPPORT,"protocol not supported") #endif #ifdef ESOCKTNOSUPPORT X(ESOCKTNOSUPPORT,"socket type not supported") #endif #ifdef EOPNOTSUPP X(EOPNOTSUPP,"operation not supported") #endif #ifdef EPFNOSUPPORT X(EPFNOSUPPORT,"protocol family not supported") #endif #ifdef EAFNOSUPPORT X(EAFNOSUPPORT,"address family not supported") #endif #ifdef EADDRINUSE X(EADDRINUSE,"address already used") #endif #ifdef EADDRNOTAVAIL X(EADDRNOTAVAIL,"address not available") #endif #ifdef ENETDOWN X(ENETDOWN,"network down") #endif #ifdef ENETUNREACH X(ENETUNREACH,"network unreachable") #endif #ifdef ENETRESET X(ENETRESET,"network reset") #endif #ifdef ECONNABORTED X(ECONNABORTED,"connection aborted") #endif #ifdef ECONNRESET X(ECONNRESET,"connection reset") #endif #ifdef ENOBUFS X(ENOBUFS,"out of buffer space") #endif #ifdef EISCONN X(EISCONN,"already connected") #endif #ifdef ENOTCONN X(ENOTCONN,"not connected") #endif #ifdef ESHUTDOWN X(ESHUTDOWN,"socket shut down") #endif #ifdef ETOOMANYREFS X(ETOOMANYREFS,"too many references") #endif #ifdef ELOOP X(ELOOP,"symbolic link loop") #endif #ifdef ENAMETOOLONG X(ENAMETOOLONG,"file name too long") #endif #ifdef EHOSTDOWN X(EHOSTDOWN,"host down") #endif #ifdef EHOSTUNREACH X(EHOSTUNREACH,"host unreachable") #endif #ifdef ENOTEMPTY X(ENOTEMPTY,"directory not empty") #endif #ifdef EPROCLIM X(EPROCLIM,"too many processes") #endif #ifdef EUSERS X(EUSERS,"too many users") #endif #ifdef EDQUOT X(EDQUOT,"disk quota exceeded") #endif #ifdef ESTALE X(ESTALE,"stale NFS file handle") #endif #ifdef EREMOTE X(EREMOTE,"too many levels of remote in path") #endif #ifdef EBADRPC X(EBADRPC,"RPC structure is bad") #endif #ifdef ERPCMISMATCH X(ERPCMISMATCH,"RPC version mismatch") #endif #ifdef EPROGUNAVAIL X(EPROGUNAVAIL,"RPC program unavailable") #endif #ifdef EPROGMISMATCH X(EPROGMISMATCH,"program version mismatch") #endif #ifdef EPROCUNAVAIL X(EPROCUNAVAIL,"bad procedure for program") #endif #ifdef ENOLCK X(ENOLCK,"no locks available") #endif #ifdef ENOSYS X(ENOSYS,"system call not available") #endif #ifdef EFTYPE X(EFTYPE,"bad file type") #endif #ifdef EAUTH X(EAUTH,"authentication error") #endif #ifdef ENEEDAUTH X(ENEEDAUTH,"not authenticated") #endif #ifdef ENOSTR X(ENOSTR,"not a stream device") #endif #ifdef ETIME X(ETIME,"timer expired") #endif #ifdef ENOSR X(ENOSR,"out of stream resources") #endif #ifdef ENOMSG X(ENOMSG,"no message of desired type") #endif #ifdef EBADMSG X(EBADMSG,"bad message type") #endif #ifdef EIDRM X(EIDRM,"identifier removed") #endif #ifdef ENONET X(ENONET,"machine not on network") #endif #ifdef ERREMOTE X(ERREMOTE,"object not local") #endif #ifdef ENOLINK X(ENOLINK,"link severed") #endif #ifdef EADV X(EADV,"advertise error") #endif #ifdef ESRMNT X(ESRMNT,"srmount error") #endif #ifdef ECOMM X(ECOMM,"communication error") #endif #ifdef EMULTIHOP X(EMULTIHOP,"multihop attempted") #endif #ifdef EREMCHG X(EREMCHG,"remote address changed") #endif return "unknown error"; } checkpw-1.02/strerr.h0000644000175000017500000000511207232241107013535 0ustar ohiraohira#ifndef STRERR_H #define STRERR_H struct strerr { struct strerr *who; char *x; char *y; char *z; } ; extern struct strerr strerr_sys; extern void strerr_sysinit(void); extern char *strerr(struct strerr *); extern void strerr_warn(char *,char *,char *,char *,char *,char *,struct strerr *); extern void strerr_die(int,char *,char *,char *,char *,char *,char *,struct strerr *); #define STRERR(r,se,a) \ { se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; } #define STRERR_SYS(r,se,a) \ { se.who = &strerr_sys; se.x = a; se.y = 0; se.z = 0; return r; } #define STRERR_SYS3(r,se,a,b,c) \ { se.who = &strerr_sys; se.x = a; se.y = b; se.z = c; return r; } #define strerr_warn6(x1,x2,x3,x4,x5,x6,se) \ strerr_warn((x1),(x2),(x3),(x4),(x5),(x6),(se)) #define strerr_warn5(x1,x2,x3,x4,x5,se) \ strerr_warn((x1),(x2),(x3),(x4),(x5),0,(se)) #define strerr_warn4(x1,x2,x3,x4,se) \ strerr_warn((x1),(x2),(x3),(x4),0,0,(se)) #define strerr_warn3(x1,x2,x3,se) \ strerr_warn((x1),(x2),(x3),0,0,0,(se)) #define strerr_warn2(x1,x2,se) \ strerr_warn((x1),(x2),0,0,0,0,(se)) #define strerr_warn1(x1,se) \ strerr_warn((x1),0,0,0,0,0,(se)) #define strerr_die6(e,x1,x2,x3,x4,x5,x6,se) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),(se)) #define strerr_die5(e,x1,x2,x3,x4,x5,se) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,(se)) #define strerr_die4(e,x1,x2,x3,x4,se) \ strerr_die((e),(x1),(x2),(x3),(x4),0,0,(se)) #define strerr_die3(e,x1,x2,x3,se) \ strerr_die((e),(x1),(x2),(x3),0,0,0,(se)) #define strerr_die2(e,x1,x2,se) \ strerr_die((e),(x1),(x2),0,0,0,0,(se)) #define strerr_die1(e,x1,se) \ strerr_die((e),(x1),0,0,0,0,0,(se)) #define strerr_die6sys(e,x1,x2,x3,x4,x5,x6) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),&strerr_sys) #define strerr_die5sys(e,x1,x2,x3,x4,x5) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,&strerr_sys) #define strerr_die4sys(e,x1,x2,x3,x4) \ strerr_die((e),(x1),(x2),(x3),(x4),0,0,&strerr_sys) #define strerr_die3sys(e,x1,x2,x3) \ strerr_die((e),(x1),(x2),(x3),0,0,0,&strerr_sys) #define strerr_die2sys(e,x1,x2) \ strerr_die((e),(x1),(x2),0,0,0,0,&strerr_sys) #define strerr_die1sys(e,x1) \ strerr_die((e),(x1),0,0,0,0,0,&strerr_sys) #define strerr_die6x(e,x1,x2,x3,x4,x5,x6) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),0) #define strerr_die5x(e,x1,x2,x3,x4,x5) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,0) #define strerr_die4x(e,x1,x2,x3,x4) \ strerr_die((e),(x1),(x2),(x3),(x4),0,0,0) #define strerr_die3x(e,x1,x2,x3) \ strerr_die((e),(x1),(x2),(x3),0,0,0,0) #define strerr_die2x(e,x1,x2) \ strerr_die((e),(x1),(x2),0,0,0,0,0) #define strerr_die1x(e,x1) \ strerr_die((e),(x1),0,0,0,0,0,0) #endif checkpw-1.02/install.c0000644000175000017500000000776307232253736013706 0ustar ohiraohira#include "buffer.h" #include "strerr.h" #include "error.h" #include "open.h" #include "readwrite.h" #include "exit.h" extern void hier(); #define FATAL "install: fatal: " int fdsourcedir = -1; void h(home,uid,gid,mode) char *home; int uid; int gid; int mode; { if (mkdir(home,0700) == -1) if (errno != error_exist) strerr_die4sys(111,FATAL,"unable to mkdir ",home,": "); if (chown(home,uid,gid) == -1) strerr_die4sys(111,FATAL,"unable to chown ",home,": "); if (chmod(home,mode) == -1) strerr_die4sys(111,FATAL,"unable to chmod ",home,": "); } void d(home,subdir,uid,gid,mode) char *home; char *subdir; int uid; int gid; int mode; { if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); if (mkdir(subdir,0700) == -1) if (errno != error_exist) strerr_die6sys(111,FATAL,"unable to mkdir ",home,"/",subdir,": "); if (chown(subdir,uid,gid) == -1) strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": "); if (chmod(subdir,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": "); } char inbuf[BUFFER_INSIZE]; char outbuf[BUFFER_OUTSIZE]; buffer ssin; buffer ssout; void c(home,subdir,file,uid,gid,mode) char *home; char *subdir; char *file; int uid; int gid; int mode; { int fdin; int fdout; if (fchdir(fdsourcedir) == -1) strerr_die2sys(111,FATAL,"unable to switch back to source directory: "); fdin = open_read(file); if (fdin == -1) strerr_die4sys(111,FATAL,"unable to read ",file,": "); buffer_init(&ssin,read,fdin,inbuf,sizeof inbuf); if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); if (chdir(subdir) == -1) strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); fdout = open_trunc(file); if (fdout == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); buffer_init(&ssout,write,fdout,outbuf,sizeof outbuf); switch(buffer_copy(&ssout,&ssin)) { case -2: strerr_die4sys(111,FATAL,"unable to read ",file,": "); case -3: strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); } close(fdin); if (buffer_flush(&ssout) == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (fsync(fdout) == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (close(fdout) == -1) /* NFS silliness */ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (chown(file,uid,gid) == -1) strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); if (chmod(file,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); } void z(home,subdir,file,len,uid,gid,mode) char *home; char *subdir; char *file; int len; int uid; int gid; int mode; { int fdout; if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); if (chdir(subdir) == -1) strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); fdout = open_trunc(file); if (fdout == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); buffer_init(&ssout,write,fdout,outbuf,sizeof outbuf); while (len-- > 0) if (buffer_put(&ssout,"",1) == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (buffer_flush(&ssout) == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (fsync(fdout) == -1) strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (close(fdout) == -1) /* NFS silliness */ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); if (chown(file,uid,gid) == -1) strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); if (chmod(file,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); } main() { fdsourcedir = open_read("."); if (fdsourcedir == -1) strerr_die2sys(111,FATAL,"unable to open current directory: "); umask(077); hier(); _exit(0); } checkpw-1.02/install=x0000644000175000017500000000004107232253777013735 0ustar ohiraohirahier.o auto_home.o unix.a byte.a checkpw-1.02/prog.do0000644000175000017500000000022607307043155013345 0ustar ohiraohiradependon auto-str auto-int8 checkpw checkapoppw dependon selectcheckpw loginlog dependon run-pop run-apop run-rules run-both run-multidir run-multipw checkpw-1.02/str_chr.c0000644000175000017500000000053007232243320013651 0ustar ohiraohira#include "str.h" unsigned int str_chr(register char *s,int c) { register char ch; register char *t; ch = c; t = s; for (;;) { if (!*t) break; if (*t == ch) break; ++t; if (!*t) break; if (*t == ch) break; ++t; if (!*t) break; if (*t == ch) break; ++t; if (!*t) break; if (*t == ch) break; ++t; } return t - s; } checkpw-1.02/scan_8long.c0000644000175000017500000000052607232262541014253 0ustar ohiraohira#include "scan.h" unsigned int scan_8long(register const char *s,register unsigned long *u) { register unsigned int pos; register unsigned long result; register unsigned long c; pos = 0; result = 0; while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 8) { result = result * 8 + c; ++pos; } *u = result; return pos; } checkpw-1.02/loginlog=s0000644000175000017500000000000007306650403014054 0ustar ohiraohiracheckpw-1.02/str_len.c0000644000175000017500000000034307232243320013655 0ustar ohiraohira#include "str.h" unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t; if (!*t) return t - s; ++t; if (!*t) return t - s; ++t; if (!*t) return t - s; ++t; } } checkpw-1.02/CHANGES0000644000175000017500000000070110631177313013041 0ustar ohiraohira20070605 portability problem: unsigned short int is not guaranteed to be an 16-bit integer. And unsigned long int is not guaranteed to be an 32-bit integer. impact: couldn't compile. fix: included inttypes.h and used uint16_t and uint32_t. Thanks, Wayne Marshall. 20040303 portability problem: errno is not guaranteed to be an int. impact: couldn't compile. fix: changed "extern int errno;" to "#include ".