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, "extension version", PHP_COURIERAUTH_VERSION
);
66 php_info_print_table_row(2, "courierauth version", courierauth_h_rcsid
);
67 php_info_print_table_end();
78 } php_courierauth_data
;
81 #define php_courierauth_data_init {return_value, tsrm_ls, 0, 0}
83 #define TSRMLS_SET_CTX(c)
84 #define TSRMLS_FETCH_FROM_CTX(c)
85 #define php_courierauth_data_init {return_value, 0, 0}
88 static int php_courierauth_callback(struct authinfo
*ai
, void *arg
)
90 php_courierauth_data
*pa
= (php_courierauth_data
*) arg
;
91 TSRMLS_FETCH_FROM_CTX(pa
->tsrm_ls
);
93 convert_to_object(pa
->rv
);
95 if (ai
->sysusername
) {
96 add_property_string(pa
->rv
, "sysusername", (char *) ai
->sysusername
, 1);
97 add_property_null(pa
->rv
, "sysuserid");
98 add_property_null(pa
->rv
, "sysgroupid");
99 } else if (ai
->sysuserid
) {
100 add_property_null(pa
->rv
, "sysusername");
101 add_property_long(pa
->rv
, "sysuserid", *ai
->sysuserid
);
102 add_property_long(pa
->rv
, "sysgroupid", ai
->sysgroupid
);
104 add_property_null(pa
->rv
, "sysusername");
105 add_property_null(pa
->rv
, "sysuserid");
106 add_property_null(pa
->rv
, "sysgroupid");
108 #define ADD_STRING(s) \
110 add_property_string(pa->rv, #s, (char *) ai->s, 1); \
112 add_property_null(pa->rv, #s); \
116 ADD_STRING(fullname
);
120 #if PHP_COURIERAUTH_SECURITY_RISK
121 ADD_STRING(clearpasswd
);
123 add_property_null(pa
->rv
, "clearpasswd");
130 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
)
133 struct authinfo ai
= {NULL
};
134 php_courierauth_data
*pa
= (php_courierauth_data
*) arg
;
135 TSRMLS_FETCH_FROM_CTX(pa
->tsrm_ls
);
137 if (!sysusername
&& !sysuserid
&& !homedir
&& !maildir
&& !options
) {
141 convert_to_array(array
);
142 MAKE_STD_ZVAL(entry
);
146 ai
.sysusername
= sysusername
;
147 ai
.sysuserid
= &sysuserid
;
148 ai
.homedir
= homedir
;
149 ai
.maildir
= maildir
;
150 ai
.options
= options
;
152 php_courierauth_callback(&ai
, (void *) pa
);
154 add_next_index_zval(array
, entry
);
159 /* {{{ proto object courierauth_login(string service, string user, string pass)
160 Login and return account info on success */
161 PHP_FUNCTION(courierauth_login
)
163 char *svc_str
, *user_str
, *pass_str
;
164 int svc_len
, user_len
, pass_len
;
165 php_courierauth_data ca
= php_courierauth_data_init
;
167 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sss", &svc_str
, &svc_len
, &user_str
, &user_len
, &pass_str
, &pass_len
)) {
171 if (0 != auth_login(svc_str
, user_str
, pass_str
, php_courierauth_callback
, &ca
)) {
177 /* {{{ proto object courierauth_getuserinfo(string service, string user)
178 Get account info for a user */
179 PHP_FUNCTION(courierauth_getuserinfo
)
181 char *svc_str
, *user_str
;
182 int svc_len
, user_len
;
183 php_courierauth_data ca
= php_courierauth_data_init
;
185 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss", &svc_str
, &svc_len
, &user_str
, &user_len
)) {
189 if (0 != auth_getuserinfo(svc_str
, user_str
, php_courierauth_callback
, &ca
)) {
195 /* {{{ proto array courierauth_enumerate(void)
197 PHP_FUNCTION(courierauth_enumerate
)
199 php_courierauth_data ca
= php_courierauth_data_init
;
201 zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "");
203 auth_enumerate(php_courierauth_enumeration_callback
, &ca
);
205 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
, "auth_enumerate() aborted or unavailable");
210 /* {{{ proto bool courierauth_passwd(string service, string user, string old_pass, string new_pass)
211 Change the password of a user */
212 PHP_FUNCTION(courierauth_passwd
)
214 char *svc_str
, *user_str
, *oldpw_str
, *newpw_str
;
215 int svc_len
, user_len
, oldpw_len
, newpw_len
;
217 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
)) {
221 RETURN_BOOL(0 == auth_passwd(svc_str
, user_str
, oldpw_str
, newpw_str
));
224 /* {{{ proto string courierauth_getoption(string options, string key)
225 Get the value of a key from options string */
226 PHP_FUNCTION(courierauth_getoption
)
228 char *opt_str
, *key_str
, *val_str
;
229 int opt_len
, key_len
;
231 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss", &opt_str
, &opt_len
, &key_str
, &key_len
)) {
235 if ((val_str
= auth_getoption(opt_str
, key_str
))) {
236 RETVAL_STRING(val_str
, 1);
249 * vim600: noet sw=4 ts=4 fdm=marker
250 * vim<600: noet sw=4 ts=4