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 "authstaticlist.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
))
66 rc
=_authdaemondo(wrfd
, rdfd
, buf
, callback_func
, callback_arg
);
68 if (rc
> 0) closePipe();
73 /* modelled on auth_getuserinfo() in preauthdaemon.c (but note first
74 * two args are reversed) */
75 int auth_pipe_pre(const char *uid
, const char *service
,
76 int (*callback
)(struct authinfo
*, void *),
85 buf
=malloc(strlen(service
)+strlen(uid
)+20);
89 strcat(strcat(strcat(strcat(strcpy(buf
, "PRE . "), service
), " "),
92 if (getPipe(&rdfd
, &wrfd
))
97 rc
=_authdaemondo(wrfd
, rdfd
, buf
, callback
, arg
);
99 if (rc
> 0) closePipe();
104 /* modelled on auth_passwd() in authmoduser2.c */
105 int auth_pipe_chgpwd(const char *service
,
116 buf
=malloc(strlen(service
)+strlen(uid
)+strlen(opwd
)+
121 sprintf(buf
, "PASSWD %s\t%s\t%s\t%s\n",
122 service
, uid
, opwd
, npwd
);
124 if (getPipe(&rdfd
, &wrfd
))
129 rc
= _authdaemondopasswd(wrfd
, rdfd
, buf
, strlen(buf
));
131 if (rc
> 0) closePipe();
136 void auth_pipe_idle()
138 /* don't need to do anything when idle */
142 void auth_pipe_close()
147 void auth_pipe_enumerate(void(*cb_func
)(const char *name
,
161 if (getPipe(&rdfd
, &wrfd
))
163 rc
= _auth_enumerate(wrfd
, rdfd
, cb_func
, void_arg
);
164 if (rc
> 0) closePipe();
167 static struct authstaticinfo authpipe_info
={
174 auth_pipe_enumerate
};
176 struct authstaticinfo
*courier_authpipe_init()
178 disabled_flag
=access(PIPE_PROGRAM
, X_OK
);
181 DPRINTF("authpipe: disabled: failed to stat pipe program %s: %s",
182 PIPE_PROGRAM
, strerror(errno
));
184 return &authpipe_info
;