Build courier-authlib 0.60.2-0hcoop5.
[hcoop/debian/courier-authlib.git] / authmoduser2.c
CommitLineData
d9898ee8 1/*
2** Copyright 2000-2004 Double Precision, Inc. See COPYING for
3** distribution information.
4*/
5
6#include "auth.h"
7#include "authstaticlist.h"
8#include "courierauthsasl.h"
9#include "authwait.h"
10#include "courierauthdebug.h"
11#include <stdlib.h>
12#include <stdio.h>
13#include <string.h>
14#include <signal.h>
15#include <unistd.h>
16#include <errno.h>
17#include <sys/time.h>
18#include <sys/select.h>
19#include "numlib/numlib.h"
20#include "authchangepwdir.h"
21
22static const char rcsid[]="$Id: authmoduser2.c,v 1.9 2004/11/17 01:16:00 mrsam Exp $";
23
24extern int authdaemondopasswd(char *, int);
25
26static int badstr(const char *p)
27{
28 if (!p) return 1;
29 while (*p)
30 {
31 if ((int)(unsigned char)*p < ' ')
32 return 1;
33 ++p;
34 }
35 return 0;
36}
37
38int auth_passwd(const char *service,
39 const char *uid,
40 const char *opwd,
41 const char *npwd)
42{
43 char *buf;
44
45 if (badstr(service) || badstr(uid) || badstr(opwd) || badstr(npwd))
46 {
47 errno=EINVAL;
48 return -1;
49 }
50
51 buf=malloc(strlen(service)+strlen(uid)+strlen(opwd)+
52 strlen(npwd)+20);
53
54 if (!buf)
55 return -1;
56
57 sprintf(buf, "PASSWD %s\t%s\t%s\t%s\n",
58 service, uid, opwd, npwd);
59
60 if (authdaemondopasswd(buf, strlen(buf)))
61 {
62 free(buf);
63 sleep(5);
64 return (-1);
65 }
66 free(buf);
67 return (0);
68}