2 +--------------------------------------------------------------------+
3 | PECL :: courierauth |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
20 #include "ext/standard/info.h"
21 #include "php_courierauth.h"
23 #include <courierauth.h>
29 } php_courierauth_data
;
31 #define php_courierauth_data_init {return_value, 0, 0}
33 static int php_courierauth_callback(struct authinfo
*ai
, void *arg
)
35 php_courierauth_data
*pa
= (php_courierauth_data
*) arg
;
37 convert_to_object(pa
->rv
);
39 if (ai
->sysusername
) {
40 add_property_string(pa
->rv
, "sysusername", ai
->sysusername
);
41 add_property_null(pa
->rv
, "sysuserid");
42 add_property_null(pa
->rv
, "sysgroupid");
43 } else if (ai
->sysuserid
) {
44 add_property_null(pa
->rv
, "sysusername");
45 add_property_long(pa
->rv
, "sysuserid", *ai
->sysuserid
);
46 add_property_long(pa
->rv
, "sysgroupid", ai
->sysgroupid
);
48 add_property_null(pa
->rv
, "sysusername");
49 add_property_null(pa
->rv
, "sysuserid");
50 add_property_null(pa
->rv
, "sysgroupid");
52 #define ADD_STRING(s) \
54 add_property_string(pa->rv, #s, ai->s); \
56 add_property_null(pa->rv, #s); \
64 #if PHP_COURIERAUTH_SECURITY_RISK
65 ADD_STRING(clearpasswd
);
67 add_property_null(pa
->rv
, "clearpasswd");
74 static void php_courierauth_enumeration_callback(const char *sysusername
, uid_t sysuserid
, gid_t sysgroupid
, const char *homedir
, const char *maildir
, const char *options
, void *arg
)
76 struct authinfo ai
= {NULL
};
77 php_courierauth_data
*pa
= (php_courierauth_data
*) arg
;
79 if (!sysusername
&& !sysuserid
&& !homedir
&& !maildir
&& !options
) {
88 ai
.sysusername
= sysusername
;
89 ai
.sysuserid
= &sysuserid
;
94 php_courierauth_callback(&ai
, (void *) pa
);
96 add_next_index_zval(array
, pa
->rv
);
101 /* {{{ proto object courierauth_login(string service, string user, string pass)
102 Login and return account info on success */
103 static PHP_FUNCTION(courierauth_login
)
105 char *svc_str
, *user_str
, *pass_str
;
106 size_t svc_len
, user_len
, pass_len
;
107 php_courierauth_data ca
= php_courierauth_data_init
;
109 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS(), "sss", &svc_str
, &svc_len
, &user_str
, &user_len
, &pass_str
, &pass_len
)) {
113 if (0 != auth_login(svc_str
, user_str
, pass_str
, php_courierauth_callback
, &ca
)) {
119 /* {{{ proto object courierauth_getuserinfo(string service, string user)
120 Get account info for a user */
121 static PHP_FUNCTION(courierauth_getuserinfo
)
123 char *svc_str
, *user_str
;
124 size_t svc_len
, user_len
;
125 php_courierauth_data ca
= php_courierauth_data_init
;
127 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &svc_str
, &svc_len
, &user_str
, &user_len
)) {
131 if (0 != auth_getuserinfo(svc_str
, user_str
, php_courierauth_callback
, &ca
)) {
137 /* {{{ proto array courierauth_enumerate(void)
139 static PHP_FUNCTION(courierauth_enumerate
)
141 php_courierauth_data ca
= php_courierauth_data_init
;
143 zend_parse_parameters_none();
145 array_init(return_value
);
146 auth_enumerate(php_courierauth_enumeration_callback
, &ca
);
148 php_error_docref(NULL
, E_NOTICE
, "auth_enumerate() aborted or unavailable");
153 /* {{{ proto bool courierauth_passwd(string service, string user, string old_pass, string new_pass)
154 Change the password of a user */
155 static PHP_FUNCTION(courierauth_passwd
)
157 char *svc_str
, *user_str
, *oldpw_str
, *newpw_str
;
158 size_t svc_len
, user_len
, oldpw_len
, newpw_len
;
160 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS(), "ssss", &svc_str
, &svc_len
, &user_str
, &user_len
, &oldpw_str
, &oldpw_len
, &newpw_str
, &newpw_len
)) {
164 RETURN_BOOL(0 == auth_passwd(svc_str
, user_str
, oldpw_str
, newpw_str
));
167 /* {{{ proto string courierauth_getoption(string options, string key)
168 Get the value of a key from options string */
169 static PHP_FUNCTION(courierauth_getoption
)
171 char *opt_str
, *key_str
, *val_str
;
172 size_t opt_len
, key_len
;
174 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &opt_str
, &opt_len
, &key_str
, &key_len
)) {
178 if ((val_str
= auth_getoption(opt_str
, key_str
))) {
179 RETVAL_STRING(val_str
);
187 /* {{{ courierauth_functions[] */
188 static zend_function_entry courierauth_functions
[] = {
189 PHP_FE(courierauth_login
, NULL
)
190 PHP_FE(courierauth_enumerate
, NULL
)
191 PHP_FE(courierauth_getuserinfo
, NULL
)
192 PHP_FE(courierauth_passwd
, NULL
)
193 PHP_FE(courierauth_getoption
, NULL
)
198 /* {{{ PHP_MINFO_FUNCTION */
199 static PHP_MINFO_FUNCTION(courierauth
)
201 php_info_print_table_start();
202 php_info_print_table_header(2, "courierauth support", "enabled");
203 php_info_print_table_row(2, "extension version", PHP_COURIERAUTH_VERSION
);
204 php_info_print_table_row(2, "courierauth version", "unknown");
205 php_info_print_table_end();
209 /* {{{ courierauth_module_entry
211 zend_module_entry courierauth_module_entry
= {
212 STANDARD_MODULE_HEADER
,
214 courierauth_functions
,
219 PHP_MINFO(courierauth
),
220 PHP_COURIERAUTH_VERSION
,
221 STANDARD_MODULE_PROPERTIES
225 #ifdef COMPILE_DL_COURIERAUTH
226 ZEND_GET_MODULE(courierauth
)
234 * vim600: noet sw=4 ts=4 fdm=marker
235 * vim<600: noet sw=4 ts=4