#include <u.h>
#include <libc.h>
#include <auth.h>
/*
* This should be a drop-in replacement for qmail's checkpassword.
* See http://cr.yp.to/checkpwd/interface.html
* We don't (yet?) set uid or environment. Test like:
* {echo -n name; unicode -t 0000;
* echo -n secret; unicode -t 0000;
* echo -n `{date -n}} |[3=1] 8.out /bin/echo foo
* Very lightly test only. Not robust in the face of misuse.
*/
void
main(int argc, char *argv[])
{
char *user;
char *pass;
char info[512], *pinfo;
AuthInfo *ai;
if(argc<=1)
exits("usage");
ARGBEGIN {
} ARGEND
readn(3, info, 512);
user = strtok(info, "\0");
pinfo=info+strlen(user)+1;
pass = strtok(pinfo, "\0");
print("%s %s\n", user, pass);
if(user==nil || pass==nil)
exits("usage");
ai=auth_userpasswd(user, pass);
if(ai == nil || ai->cap == nil)
exits("badpass");
exec(argv[0],argv++);
}
/* Stupid unix. */
int
exitcode(char *msg)
{
int n;
if(strcmp(msg, "badpass"))
n=1;
else if(strcmp(msg, "tempfail"))
n=111;
else
n=2;
return n;
}
|