- add courierauth
authorMichael Wallner <mike@php.net>
Sun, 10 Dec 2006 20:42:37 +0000 (20:42 +0000)
committerMichael Wallner <mike@php.net>
Sun, 10 Dec 2006 20:42:37 +0000 (20:42 +0000)
git-svn-id: http://svn.php.net/repository/pecl/courierauth/trunk@224794 c90b9560-bf6c-de11-be94-00142212c4b1

CREDITS [new file with mode: 0644]
EXPERIMENTAL [new file with mode: 0644]
LICENSE [new file with mode: 0644]
config.m4 [new file with mode: 0644]
courierauth.c [new file with mode: 0644]
package.xml [new file with mode: 0644]
package2.xml [new file with mode: 0644]
php_courierauth.h [new file with mode: 0644]

diff --git a/CREDITS b/CREDITS
new file mode 100644 (file)
index 0000000..2aa8881
--- /dev/null
+++ b/CREDITS
@@ -0,0 +1,2 @@
+courierauth
+Michael Wallner
diff --git a/EXPERIMENTAL b/EXPERIMENTAL
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..e916805
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2006, Michael Wallner <mike@iworks.at>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without 
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, 
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright 
+      notice, this list of conditions and the following disclaimer in the 
+      documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/config.m4 b/config.m4
new file mode 100644 (file)
index 0000000..682c1a7
--- /dev/null
+++ b/config.m4
@@ -0,0 +1,38 @@
+dnl $Id$
+dnl config.m4 for extension courierauth
+
+PHP_ARG_WITH(courierauth, for courierauth support,
+       [  --with-courierauth-config
+                          Path to courierauthconfig script])
+PHP_ARG_WITH(courierauth-security-risk, whether to enable passwd security risk,
+       [  --with-courierauth-security-risk
+                          Enable passwd security risk], no, no)
+
+if test "$PHP_COURIERAUTH" != "no"; then
+       AC_MSG_CHECKING(for courierauthconfig)
+       COURIERAUTHCONFIG=
+       for i in "$PHP_COURIERAUTH_CONFIG" /usr/local/bin/courierauthconfig /usr/bin/courierauthconfig "`which courierauthconfig`"; do
+               if test -x "$i"; then
+                       COURIERAUTHCONFIG="$i"
+                       break
+               fi
+       done
+       if test -z "$COURIERAUTHCONFIG"; then
+               AC_MSG_ERROR(not found)
+       else
+               AC_MSG_RESULT($COURIERAUTHCONFIG)
+       fi
+       
+       PHP_EVAL_LIBLINE("`$COURIERAUTHCONFIG --ldflags` -lcourierauth", COURIERAUTH_SHARED_LIBADD)
+       PHP_EVAL_INCLINE(`$COURIERAUTHCONFIG --cppflags`)
+       
+       if test "$PHP_COURIERAUTH_SECURITY_RISK" = "yes"; then
+               AC_DEFINE(PHP_COURIERAUTH_SECURITY_RISK, 1, [passwd security risk])
+       else
+               AC_DEFINE(PHP_COURIERAUTH_SECURITY_RISK, 0, [passwd security risk])
+       fi
+       
+       PHP_SUBST(COURIERAUTH_SHARED_LIBADD)
+       
+       PHP_NEW_EXTENSION(courierauth, courierauth.c, $ext_shared)
+fi
diff --git a/courierauth.c b/courierauth.c
new file mode 100644 (file)
index 0000000..2314c33
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+    +--------------------------------------------------------------------+
+    | PECL :: courierauth                                                |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted provided that the conditions mentioned |
+    | in the accompanying LICENSE file are met.                          |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2006, Michael Wallner <mike@php.net>                 |
+    +--------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "ext/standard/info.h"
+#include "php_courierauth.h"
+
+#include <courierauth.h>
+
+/* {{{ courierauth_functions[] */
+zend_function_entry courierauth_functions[] = {
+       PHP_FE(courierauth_login, NULL)
+       PHP_FE(courierauth_enumerate, NULL)
+       PHP_FE(courierauth_getuserinfo, NULL)
+       PHP_FE(courierauth_passwd, NULL)
+       PHP_FE(courierauth_getoption, NULL)
+       {NULL, NULL, NULL}
+};
+/* }}} */
+
+/* {{{ courierauth_module_entry
+ */
+zend_module_entry courierauth_module_entry = {
+#if ZEND_MODULE_API_NO >= 20010901
+       STANDARD_MODULE_HEADER,
+#endif
+       "courierauth",
+       courierauth_functions,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       PHP_MINFO(courierauth),
+#if ZEND_MODULE_API_NO >= 20010901
+       PHP_COURIERAUTH_VERSION,
+#endif
+       STANDARD_MODULE_PROPERTIES
+};
+/* }}} */
+
+#ifdef COMPILE_DL_COURIERAUTH
+ZEND_GET_MODULE(courierauth)
+#endif
+
+/* {{{ PHP_MINFO_FUNCTION */
+PHP_MINFO_FUNCTION(courierauth)
+{
+       php_info_print_table_start();
+       php_info_print_table_header(2, "courierauth support", "enabled");
+       php_info_print_table_row(2, "courierauth version", courierauth_h_rcsid);
+       php_info_print_table_end();
+}
+/* }}} */
+
+typedef struct {
+       zval *rv;
+#ifdef ZTS
+       void ***tsrm_ls;
+#endif
+       uint success:1;
+       uint _res:31;
+} php_courierauth_data;
+
+#ifdef ZTS
+#define php_courierauth_data_init {return_value, tsrm_ls, 0, 0}
+#else
+#define TSRMLS_SET_CTX(c)
+#define TSRMLS_FETCH_FROM_CTX(c)
+#define php_courierauth_data_init {return_value, 0, 0}
+#endif
+
+static int php_courierauth_callback(struct authinfo *ai, void *arg)
+{
+       php_courierauth_data *pa = (php_courierauth_data *) arg;
+       TSRMLS_FETCH_FROM_CTX(pa->tsrm_ls);
+       
+       convert_to_object(pa->rv);
+       
+       if (ai->sysusername) {
+               add_property_string(pa->rv, "sysusername", (char *) ai->sysusername, 1);
+               add_property_null(pa->rv, "sysuserid");
+               add_property_null(pa->rv, "sysgroupid");
+       } else if (ai->sysuserid) {
+               add_property_null(pa->rv, "sysusername");
+               add_property_long(pa->rv, "sysuserid", *ai->sysuserid);
+               add_property_long(pa->rv, "sysgroupid", ai->sysgroupid);
+       } else {
+               add_property_null(pa->rv, "sysusername");
+               add_property_null(pa->rv, "sysuserid");
+               add_property_null(pa->rv, "sysgroupid");
+       }
+#define ADD_STRING(s) \
+       if (ai->s) { \
+               add_property_string(pa->rv, #s, (char *) ai->s, 1); \
+       } else { \
+               add_property_null(pa->rv, #s); \
+       }
+       ADD_STRING(homedir);
+       ADD_STRING(address);
+       ADD_STRING(fullname);
+       ADD_STRING(maildir);
+       ADD_STRING(quota);
+       ADD_STRING(passwd);
+#if PHP_COURIERAUTH_SECURITY_RISK
+       ADD_STRING(clearpasswd);
+#else
+       add_property_null(pa->rv, "clearpasswd");
+#endif
+       ADD_STRING(options);
+       
+       return 0;
+}
+
+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)
+{
+       zval *entry, *array;
+       struct authinfo ai = {NULL};
+       php_courierauth_data *pa = (php_courierauth_data *) arg;
+       TSRMLS_FETCH_FROM_CTX(pa->tsrm_ls);
+       
+       if (!sysusername && !sysuserid && !homedir && !maildir && !options) {
+               pa->success = 1;
+       } else {
+               array = pa->rv;
+               convert_to_array(array);
+               MAKE_STD_ZVAL(entry);
+               ZVAL_NULL(entry);
+               pa->rv = entry;
+               
+               ai.sysusername = sysusername;
+               ai.sysuserid = &sysuserid;
+               ai.homedir = homedir;
+               ai.maildir = maildir;
+               ai.options = options;
+               
+               php_courierauth_callback(&ai, (void *) pa);
+               
+               add_next_index_zval(array, entry);
+               pa->rv = array;
+       }
+}
+
+/* {{{ proto object courierauth_login(string service, string user, string pass)
+   Login and return account info on success */
+PHP_FUNCTION(courierauth_login)
+{
+       char *svc_str, *user_str, *pass_str;
+       int svc_len, user_len, pass_len;
+       php_courierauth_data ca = php_courierauth_data_init;
+       
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &svc_str, &svc_len, &user_str, &user_len, &pass_str, &pass_len)) {
+               RETURN_FALSE;
+       }
+       
+       if (0 != auth_login(svc_str, user_str, pass_str, php_courierauth_callback, &ca)) {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
+/* {{{ proto object courierauth_getuserinfo(string service, string user)
+       Get account info for a user */
+PHP_FUNCTION(courierauth_getuserinfo)
+{
+       char *svc_str, *user_str;
+       int svc_len, user_len;
+       php_courierauth_data ca = php_courierauth_data_init;
+       
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &svc_str, &svc_len, &user_str, &user_len)) {
+               RETURN_FALSE;
+       }
+       
+       if (0 != auth_getuserinfo(svc_str, user_str, php_courierauth_callback, &ca)) {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
+/* {{{ proto array courierauth_enumerate(void)
+       List all users */
+PHP_FUNCTION(courierauth_enumerate)
+{
+       php_courierauth_data ca = php_courierauth_data_init;
+       
+       zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "");
+       
+       auth_enumerate(php_courierauth_enumeration_callback, &ca);
+       if (!ca.success) {
+               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "auth_enumerate() aborted or unavailable");
+       }
+}
+/* }}} */
+
+/* {{{ proto bool courierauth_passwd(string service, string user, string old_pass, string new_pass)
+       Change the password of a user */
+PHP_FUNCTION(courierauth_passwd)
+{
+       char *svc_str, *user_str, *oldpw_str, *newpw_str;
+       int svc_len, user_len, oldpw_len, newpw_len;
+       
+       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)) {
+               RETURN_FALSE;
+       }
+       
+       RETURN_BOOL(0 == auth_passwd(svc_str, user_str, oldpw_str, newpw_str));
+}
+
+/* {{{ proto string courierauth_getoption(string options, string key)
+       Get the value of a key from options string */
+PHP_FUNCTION(courierauth_getoption)
+{
+       char *opt_str, *key_str, *val_str;
+       int opt_len, key_len;
+       
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &opt_str, &opt_len, &key_str, &key_len)) {
+               RETURN_FALSE;
+       }
+       
+       if ((val_str = auth_getoption(opt_str, key_str))) {
+               RETVAL_STRING(val_str, 1);
+               free(val_str);
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
diff --git a/package.xml b/package.xml
new file mode 100644 (file)
index 0000000..e98c872
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
+<package version="1.0" packagerversion="1.4.11">
+ <name>courierauth</name>
+ <summary>courierauth binding</summary>
+ <description>Binding for the courierauth library.
+ </description>
+ <maintainers>
+  <maintainer>
+   <user>mike</user>
+   <name>Michael Wallner</name>
+   <email>mike@php.net</email>
+   <role>lead</role>
+  </maintainer>
+  </maintainers>
+ <release>
+  <version>0.1.0</version>
+  <date>2006-12-07</date>
+  <license>BSD, revised</license>
+  <state>beta</state>
+  <notes>* Initial release
+  </notes>
+  <deps>
+   <dep type="php" rel="ge" version="4.3"/>
+   <dep type="php" rel="le" version="6.0"/>
+  </deps>
+  <configureoptions>
+   <configureoption name="with-courierauth" default="yes" prompt="whether to enable courierauth support"/>
+   <configureoption name="with-courierauth-security-risk" default="no" prompt="whether to enable passwd security risk"/>
+  </configureoptions>
+  <filelist>
+   <file role="src" name="config.m4"/>
+   <file role="src" name="courierauth.c"/>
+   <file role="doc" name="CREDITS"/>
+   <file role="doc" name="EXPERIMENTAL"/>
+   <file role="doc" name="LICENSE"/>
+   <file role="src" name="php_courierauth.h"/>
+  </filelist>
+ </release>
+</package>
diff --git a/package2.xml b/package2.xml
new file mode 100644 (file)
index 0000000..1fd4d1a
--- /dev/null
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.11" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>courierauth</name>
+ <channel>pecl.php.net</channel>
+ <summary>courierauth binding</summary>
+ <description>Binding for the courierauth library. </description>
+ <lead>
+  <name>Michael Wallner</name>
+  <user>mike</user>
+  <email>mike@php.net</email>
+  <active>yes</active>
+ </lead>
+ <date>2006-12-07</date>
+ <version>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
+ </version>
+ <stability>
+  <release>beta</release>
+  <api>beta</api>
+ </stability>
+ <license>BSD, revised</license>
+ <notes><![CDATA[
+* Initial release
+]]></notes>
+ <contents>
+  <dir name="/">
+   <file role="src" name="config.m4" />
+   <file role="src" name="courierauth.c" />
+   <file role="src" name="php_courierauth.h" />
+   <file role="doc" name="CREDITS" />
+   <file role="doc" name="EXPERIMENTAL" />
+   <file role="doc" name="LICENSE" />
+  </dir>
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>4.3</min>
+    <max>6.0</max>
+    <exclude>6.0</exclude>
+   </php>
+   <pearinstaller>
+    <min>1.4.0b1</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <providesextension>courierauth</providesextension>
+ <extsrcrelease>
+  <configureoption default="yes" name="with-courierauth" prompt="whether to enable courierauth support" />
+  <configureoption default="no" name="with-courierauth-security-risk" prompt="whether to enable passwd security risk" />
+ </extsrcrelease>
+</package>
diff --git a/php_courierauth.h b/php_courierauth.h
new file mode 100644 (file)
index 0000000..39aca9b
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+    +--------------------------------------------------------------------+
+    | PECL :: courierauth                                                |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted provided that the conditions mentioned |
+    | in the accompanying LICENSE file are met.                          |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2006, Michael Wallner <mike@php.net>                 |
+    +--------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_COURIERAUTH_H
+#define PHP_COURIERAUTH_H
+
+#define PHP_COURIERAUTH_VERSION "0.1.0"
+
+extern zend_module_entry courierauth_module_entry;
+#define phpext_courierauth_ptr &courierauth_module_entry
+
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+
+PHP_MINFO_FUNCTION(courierauth);
+
+PHP_FUNCTION(courierauth_login);
+PHP_FUNCTION(courierauth_getuserinfo);
+PHP_FUNCTION(courierauth_enumerate);
+PHP_FUNCTION(courierauth_passwd);
+PHP_FUNCTION(courierauth_getoption);
+
+#endif /* PHP_COURIERAUTH_H */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */