cvs: php4 /ext/interbase interbase.c php_interbase.h

From: Date: Sun, 27 Jan 2002 15:31:15 +0000
Subject: cvs: php4 /ext/interbase interbase.c php_interbase.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9199@lists.php.net to get a copy of this message
aeschbacher Sun Jan 27 10:31:15 2002 EDT Modified files: /php4/ext/interbase interbase.c php_interbase.h Log: add ibase_add_user(), ibase_modify_user(), ibase_delete_use() Index: php4/ext/interbase/interbase.c diff -u php4/ext/interbase/interbase.c:1.74 php4/ext/interbase/interbase.c:1.75 --- php4/ext/interbase/interbase.c:1.74 Tue Dec 11 10:29:43 2001 +++ php4/ext/interbase/interbase.c Sun Jan 27 10:31:13 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: interbase.c,v 1.74 2001/12/11 15:29:43 sebastian Exp $ */ +/* $Id: interbase.c,v 1.75 2002/01/27 15:31:13 aeschbacher Exp $ */ /* TODO: Arrays, roles? @@ -103,6 +103,11 @@ PHP_FE(ibase_blob_echo, NULL) PHP_FE(ibase_blob_import, NULL) PHP_FE(ibase_errmsg, NULL) + + PHP_FE(ibase_add_user, NULL) + PHP_FE(ibase_modify_user, NULL) + PHP_FE(ibase_delete_user, NULL) + {NULL, NULL, NULL} }; @@ -589,7 +594,7 @@ php_info_print_table_start(); php_info_print_table_row(2, "Interbase Support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.74 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.75 $"); #ifdef COMPILE_DL_INTERBASE php_info_print_table_row(2, "Dynamic Module", "yes"); #endif @@ -2928,7 +2933,187 @@ } /* }}} */ -#endif +/* {{{ _php_ibase_user() */ +static void _php_ibase_user(INTERNAL_FUNCTION_PARAMETERS, int operation) +{ + pval **args[8]; + char *ib_server, *dba_user_name, *dba_password, *user_name, *user_password = NULL, + *first_name = NULL, *middle_name = NULL, *last_name = NULL; + char service_name_buffer[128], *service_name = service_name_buffer; + char spb_buffer[128], *spb = spb_buffer; + unsigned short spb_length; + isc_svc_handle service_handle = NULL; + + RESET_ERRMSG; + + switch (operation) { + case isc_action_svc_add_user: + case isc_action_svc_modify_user: + // 5 to 8 parameters for ADD or MODIFY operation + if(ZEND_NUM_ARGS() < 5 || ZEND_NUM_ARGS() > 8) { + WRONG_PARAM_COUNT; + } + break; + + case isc_action_svc_delete_user: + // 4 parameters for DELETE operation + if (ZEND_NUM_ARGS() != 4) { + WRONG_PARAM_COUNT; + } + } + + if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { + RETURN_FALSE; + } + + switch(ZEND_NUM_ARGS()) { + case 8: + convert_to_string_ex(args[7]); + last_name = (*args[7])->value.str.val; + /* fallout */ + case 7: + convert_to_string_ex(args[6]); + middle_name = (*args[6])->value.str.val; + /* fallout */ + case 6: + convert_to_string_ex(args[5]); + first_name = (*args[5])->value.str.val; + /* fallout */ + } + + if (operation != isc_action_svc_delete_user) { + // Parameter not available for DELETE operation + convert_to_string_ex(args[4]); + user_password = (*args[4])->value.str.val; + } + + convert_to_string_ex(args[3]); + user_name = (*args[3])->value.str.val; + + convert_to_string_ex(args[2]); + dba_password = (*args[2])->value.str.val; + + convert_to_string_ex(args[1]); + dba_user_name = (*args[1])->value.str.val; + + convert_to_string_ex(args[0]); + ib_server = (*args[0])->value.str.val; + +/* + zend_printf("server : %s<br>", ib_server); + zend_printf("admin : %s<br>", dba_user_name); + zend_printf("admin pwd: %s<br>", dba_password); + zend_printf("user : %s<br>", user_name); + zend_printf("user pwd : %s<br>", user_password); + zend_printf("fname : %s<br>", first_name); + zend_printf("mname : %s<br>", middle_name); + zend_printf("lname : %s<br>", last_name); +*/ + + // Build buffer for isc_service_attach() + *spb++ = isc_spb_version; + *spb++ = isc_spb_current_version; + *spb++ = isc_spb_user_name; + *spb++ = strlen(dba_user_name); + strcpy(spb, dba_user_name); + spb += strlen(dba_user_name); + *spb++ = isc_spb_password; + *spb++ = strlen(dba_password); + strcpy(spb, dba_password); + spb += strlen(dba_password); + spb_length = spb - spb_buffer; + + // Attach to the Service Manager + sprintf(service_name, "%s:service_mgr", ib_server); + if (isc_service_attach(IB_STATUS, 0, service_name, + &service_handle, spb_length, spb_buffer)) { + + _php_ibase_error(); + RETURN_FALSE; + } + else { + char request[128], *x, *p = request; + + // Identify cluster (here, isc_action_svc_*_user) + *p++ = operation; + + // Argument for username + *p++ = isc_spb_sec_username; + ADD_SPB_LENGTH(p, strlen(user_name)); + for (x = user_name ; *x; ) *p++ = *x++; + + // Argument for password + if (user_password) { + *p++ = isc_spb_sec_password; + ADD_SPB_LENGTH(p, strlen(user_password)); + for (x = user_password ; *x; ) *p++ = *x++; + } + + // Argument for first name + if (first_name) { + *p++ = isc_spb_sec_firstname; + ADD_SPB_LENGTH(p, strlen(first_name)); + for (x = first_name ; *x; ) *p++ = *x++; + } + + // Argument for middle name + if (middle_name) { + *p++ = isc_spb_sec_middlename; + ADD_SPB_LENGTH(p, strlen(middle_name)); + for (x = middle_name ; *x; ) *p++ = *x++; + } + + // Argument for last name + if (last_name) { + *p++ = isc_spb_sec_lastname; + ADD_SPB_LENGTH(p, strlen(last_name)); + for (x = last_name ; *x; ) *p++ = *x++; + } + + // Let's go update: start Service Manager + if (isc_service_start(IB_STATUS, &service_handle, + NULL, (unsigned short) (p - request), request)) { + + _php_ibase_error(); + isc_service_detach(IB_STATUS, &service_handle); + RETURN_FALSE; + } + else { + // Detach from Service Manager + isc_service_detach(IB_STATUS, &service_handle); + } + } + + + RETURN_TRUE; +} + + +/* {{{ proto int ibase_add_user(string server, string dba_user_name, string dba_password, string user_name, string password [, string first_name] [, string middle_name] [, string last_name]) + Add an user to security database */ +PHP_FUNCTION(ibase_add_user) +{ + _php_ibase_user(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_add_user); +} +/* }}} */ + + +/* {{{ proto int ibase_modify_user(string server, string dba_user_name, string dba_password, string user_name, string password [, string first_name] [, string middle_name] [, string last_name]) + Modify an user in security database */ +PHP_FUNCTION(ibase_modify_user) +{ + _php_ibase_user(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_modify_user); +} + + +/* {{{ proto int ibase_delete_user(string server, string dba_user_name, string dba_password, string username) + Delete an user from security database */ +PHP_FUNCTION(ibase_delete_user) +{ + _php_ibase_user(INTERNAL_FUNCTION_PARAM_PASSTHRU, isc_action_svc_delete_user); +} + +#endif /* HAVE_IBASE */ /* * Local variables: Index: php4/ext/interbase/php_interbase.h diff -u php4/ext/interbase/php_interbase.h:1.24 php4/ext/interbase/php_interbase.h:1.25 --- php4/ext/interbase/php_interbase.h:1.24 Tue Dec 11 10:29:44 2001 +++ php4/ext/interbase/php_interbase.h Sun Jan 27 10:31:15 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_interbase.h,v 1.24 2001/12/11 15:29:44 sebastian Exp $ */ +/* $Id: php_interbase.h,v 1.25 2002/01/27 15:31:15 aeschbacher Exp $ */ #ifndef PHP_INTERBASE_H #define PHP_INTERBASE_H @@ -68,6 +68,10 @@ PHP_FUNCTION(ibase_blob_echo); PHP_FUNCTION(ibase_blob_info); PHP_FUNCTION(ibase_blob_import); + +PHP_FUNCTION(ibase_add_user); +PHP_FUNCTION(ibase_modify_user); +PHP_FUNCTION(ibase_delete_user); PHP_FUNCTION(ibase_errmsg);

« previous php.cvs (#9199) next »