2 ** Copyright 1998 - 2005 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
15 #include "numlib/numlib.h"
17 #include "courierauth.h"
18 #include "courierauthstaticlist.h"
19 #include "courierauthdebug.h"
21 #include "authpipelib.h"
22 #include "authpiperc.h"
24 extern int _authdaemondopasswd(int wrfd
, int rdfd
, char *buffer
, int bufsiz
);
25 extern int _authdaemondo(int wrfd
, int rdfd
, const char *authreq
,
26 int (*func
)(struct authinfo
*, void *), void *arg
);
27 extern int _auth_enumerate(int wrfd
, int rdfd
,
28 void(*cb_func
)(const char *name
,
37 static int disabled_flag
;
39 /* modelled on auth_generic() in authdaemon.c */
40 int auth_pipe(const char *service
, const char *authtype
, char *authdata
,
41 int (*callback_func
)(struct authinfo
*, void *),
44 char tbuf
[NUMBUFSIZE
];
45 size_t l
=strlen(service
)+strlen(authtype
)+strlen(authdata
)+2;
46 char *n
=libmail_str_size_t(l
, tbuf
);
47 char *buf
=malloc(strlen(n
)+l
+20);
59 strcat(strcat(strcpy(buf
, "AUTH "), n
), "\n");
60 strcat(strcat(buf
, service
), "\n");
61 strcat(strcat(buf
, authtype
), "\n");
62 strcat(buf
, authdata
);
64 if (getPipe(&rdfd
, &wrfd
))
69 rc
=_authdaemondo(wrfd
, rdfd
, buf
, callback_func
, callback_arg
);
71 if (rc
> 0) closePipe();
76 /* modelled on auth_getuserinfo() in preauthdaemon.c (but note first
77 * two args are reversed) */
78 int auth_pipe_pre(const char *uid
, const char *service
,
79 int (*callback
)(struct authinfo
*, void *),
88 buf
=malloc(strlen(service
)+strlen(uid
)+20);
92 strcat(strcat(strcat(strcat(strcpy(buf
, "PRE . "), service
), " "),
95 if (getPipe(&rdfd
, &wrfd
))
100 rc
=_authdaemondo(wrfd
, rdfd
, buf
, callback
, arg
);
102 if (rc
> 0) closePipe();
107 /* modelled on auth_passwd() in authmoduser2.c */
108 int auth_pipe_chgpwd(const char *service
,
119 buf
=malloc(strlen(service
)+strlen(uid
)+strlen(opwd
)+
124 sprintf(buf
, "PASSWD %s\t%s\t%s\t%s\n",
125 service
, uid
, opwd
, npwd
);
127 if (getPipe(&rdfd
, &wrfd
))
132 rc
= _authdaemondopasswd(wrfd
, rdfd
, buf
, strlen(buf
));
134 if (rc
> 0) closePipe();
139 void auth_pipe_idle()
141 /* don't need to do anything when idle */
145 void auth_pipe_close()
150 void auth_pipe_enumerate(void(*cb_func
)(const char *name
,
164 if (getPipe(&rdfd
, &wrfd
))
166 rc
= _auth_enumerate(wrfd
, rdfd
, cb_func
, void_arg
);
167 if (rc
> 0) closePipe();
170 static struct authstaticinfo authpipe_info
={
177 auth_pipe_enumerate
};
179 struct authstaticinfo
*courier_authpipe_init()
181 disabled_flag
=access(PIPE_PROGRAM
, X_OK
);
184 DPRINTF("authpipe: disabled: failed to stat pipe program %s: %s",
185 PIPE_PROGRAM
, strerror(errno
));
187 return &authpipe_info
;