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>
25 /* {{{ courierauth_functions[] */
26 zend_function_entry courierauth_functions
[] = {
27 PHP_FE(courierauth_login
, NULL
)
28 PHP_FE(courierauth_enumerate
, NULL
)
29 PHP_FE(courierauth_getuserinfo
, NULL
)
30 PHP_FE(courierauth_passwd
, NULL
)
31 PHP_FE(courierauth_getoption
, NULL
)
36 /* {{{ courierauth_module_entry
38 zend_module_entry courierauth_module_entry
= {
39 #if ZEND_MODULE_API_NO >= 20010901
40 STANDARD_MODULE_HEADER
,
43 courierauth_functions
,
48 PHP_MINFO(courierauth
),
49 #if ZEND_MODULE_API_NO >= 20010901
50 PHP_COURIERAUTH_VERSION
,
52 STANDARD_MODULE_PROPERTIES
56 #ifdef COMPILE_DL_COURIERAUTH
57 ZEND_GET_MODULE(courierauth
)
60 /* {{{ PHP_MINFO_FUNCTION */
61 PHP_MINFO_FUNCTION(courierauth
)
63 php_info_print_table_start();
64 php_info_print_table_header(2, "courierauth support", "enabled");
65 php_info_print_table_row(2, "courierauth version", courierauth_h_rcsid
);
66 php_info_print_table_end();
77 } php_courierauth_data
;
80 #define php_courierauth_data_init {return_value, tsrm_ls, 0, 0}
82 #define TSRMLS_SET_CTX(c)
83 #define TSRMLS_FETCH_FROM_CTX(c)
84 #define php_courierauth_data_init {return_value, 0, 0}
87 static int php_courierauth_callback(struct authinfo
*ai
, void *arg
)
89 php_courierauth_data
*pa
= (php_courierauth_data
*) arg
;
90 TSRMLS_FETCH_FROM_CTX(pa
->tsrm_ls
);
92 convert_to_object(pa
->rv
);
94 if (ai
->sysusername
) {
95 add_property_string(pa
->rv
, "sysusername", (char *) ai
->sysusername
, 1);
96 add_property_null(pa
->rv
, "sysuserid");
97 add_property_null(pa
->rv
, "sysgroupid");
98 } else if (ai
->sysuserid
) {
99 add_property_null(pa
->rv
, "sysusername");
100 add_property_long(pa
->rv
, "sysuserid", *ai
->sysuserid
);
101 add_property_long(pa
->rv
, "sysgroupid", ai
->sysgroupid
);
103 add_property_null(pa
->rv
, "sysusername");
104 add_property_null(pa
->rv
, "sysuserid");
105 add_property_null(pa
->rv
, "sysgroupid");
107 #define ADD_STRING(s) \
109 add_property_string(pa->rv, #s, (char *) ai->s, 1); \
111 add_property_null(pa->rv, #s); \
115 ADD_STRING(fullname
);
119 #if PHP_COURIERAUTH_SECURITY_RISK
120 ADD_STRING(clearpasswd
);
122 add_property_null(pa
->rv
, "clearpasswd");
129 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
)
132 struct authinfo ai
= {NULL
};
133 php_courierauth_data
*pa
= (php_courierauth_data
*) arg
;
134 TSRMLS_FETCH_FROM_CTX(pa
->tsrm_ls
);
136 if (!sysusername
&& !sysuserid
&& !homedir
&& !maildir
&& !options
) {
140 convert_to_array(array
);
141 MAKE_STD_ZVAL(entry
);
145 ai
.sysusername
= sysusername
;
146 ai
.sysuserid
= &sysuserid
;
147 ai
.homedir
= homedir
;
148 ai
.maildir
= maildir
;
149 ai
.options
= options
;
151 php_courierauth_callback(&ai
, (void *) pa
);
153 add_next_index_zval(array
, entry
);
158 /* {{{ proto object courierauth_login(string service, string user, string pass)
159 Login and return account info on success */
160 PHP_FUNCTION(courierauth_login
)
162 char *svc_str
, *user_str
, *pass_str
;
163 int svc_len
, user_len
, pass_len
;
164 php_courierauth_data ca
= php_courierauth_data_init
;
166 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sss", &svc_str
, &svc_len
, &user_str
, &user_len
, &pass_str
, &pass_len
)) {
170 if (0 != auth_login(svc_str
, user_str
, pass_str
, php_courierauth_callback
, &ca
)) {
176 /* {{{ proto object courierauth_getuserinfo(string service, string user)
177 Get account info for a user */
178 PHP_FUNCTION(courierauth_getuserinfo
)
180 char *svc_str
, *user_str
;
181 int svc_len
, user_len
;
182 php_courierauth_data ca
= php_courierauth_data_init
;
184 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss", &svc_str
, &svc_len
, &user_str
, &user_len
)) {
188 if (0 != auth_getuserinfo(svc_str
, user_str
, php_courierauth_callback
, &ca
)) {
194 /* {{{ proto array courierauth_enumerate(void)
196 PHP_FUNCTION(courierauth_enumerate
)
198 php_courierauth_data ca
= php_courierauth_data_init
;
200 zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "");
202 auth_enumerate(php_courierauth_enumeration_callback
, &ca
);
204 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
, "auth_enumerate() aborted or unavailable");
209 /* {{{ proto bool courierauth_passwd(string service, string user, string old_pass, string new_pass)
210 Change the password of a user */
211 PHP_FUNCTION(courierauth_passwd
)
213 char *svc_str
, *user_str
, *oldpw_str
, *newpw_str
;
214 int svc_len
, user_len
, oldpw_len
, newpw_len
;
216 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ssss", &svc_str
, &svc_len
, &user_str
, &user_len
, &oldpw_str
, &oldpw_len
, &newpw_str
, &newpw_len
)) {
220 RETURN_BOOL(0 == auth_passwd(svc_str
, user_str
, oldpw_str
, newpw_str
));
223 /* {{{ proto string courierauth_getoption(string options, string key)
224 Get the value of a key from options string */
225 PHP_FUNCTION(courierauth_getoption
)
227 char *opt_str
, *key_str
, *val_str
;
228 int opt_len
, key_len
;
230 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss", &opt_str
, &opt_len
, &key_str
, &key_len
)) {
234 if ((val_str
= auth_getoption(opt_str
, key_str
))) {
235 RETVAL_STRING(val_str
, 1);
248 * vim600: noet sw=4 ts=4 fdm=marker
249 * vim<600: noet sw=4 ts=4