hcoop release
[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"
b0322a85 7#include "courierauthstaticlist.h"
d9898ee8 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
d9898ee8 22
23extern int authdaemondopasswd(char *, int);
24
25static int badstr(const char *p)
26{
27 if (!p) return 1;
28 while (*p)
29 {
30 if ((int)(unsigned char)*p < ' ')
31 return 1;
32 ++p;
33 }
34 return 0;
35}
36
37int auth_passwd(const char *service,
38 const char *uid,
39 const char *opwd,
40 const char *npwd)
41{
42 char *buf;
43
44 if (badstr(service) || badstr(uid) || badstr(opwd) || badstr(npwd))
45 {
46 errno=EINVAL;
47 return -1;
48 }
49
50 buf=malloc(strlen(service)+strlen(uid)+strlen(opwd)+
51 strlen(npwd)+20);
52
53 if (!buf)
54 return -1;
55
56 sprintf(buf, "PASSWD %s\t%s\t%s\t%s\n",
57 service, uid, opwd, npwd);
58
59 if (authdaemondopasswd(buf, strlen(buf)))
60 {
61 free(buf);
b0322a85 62 /*sleep(5);*/
d9898ee8 63 return (-1);
64 }
65 free(buf);
66 return (0);
67}