home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxldp021.zip / rxldap.c < prev    next >
C/C++ Source or Header  |  2001-11-26  |  132KB  |  4,499 lines

  1. #include <ctype.h>
  2. #include <search.h>
  3. #include <stdio.h>                       
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/time.h>
  7.  
  8. #define INCL_DOSERRORS
  9. #define INCL_DOSMEMMGR
  10. #include <os2.h>
  11.  
  12. #include <uconv.h>
  13.  
  14. #define INCL_RXFUNC
  15. #define INCL_RXSHV
  16. #include <rexxsaa.h>
  17.  
  18. #include <ldap.h>
  19.  
  20. #include "rxstring.h"
  21.  
  22. #define CallingValid 0
  23. #define CallingInvalid 40
  24. #define Good 0
  25. #define Bad 40
  26.  
  27. #define RxldapDll "RXLDAP"
  28. #define RxldapVer "0.21" 
  29.  
  30. #define SetSignedInt2Rx(rxvar, intval) rxset_length( &(rxvar), strlen( _ltoa( (ULONG)intval, RXSTRPTR(rxvar), 10 ) ) )
  31. #define SetUnsignedInt2Rx(rxvar, intval) rxset_length( &(rxvar), strlen( _ultoa( (ULONG)intval, RXSTRPTR(rxvar), 10 ) ) )
  32. #define SetRetStr(rxvar, str) rxreturn_value(&(rxvar), (unsigned char*)str, strlen(str))
  33. #define SetLdapCode(rxstr, code) setcodename( rxstr, code, LdapReturnCodes, sizeof(LdapReturnCodes) / sizeof(Name2Int), 0 )
  34. #define SetIntFromName( n, t, v, i, o ) \
  35.    v = findintfromname( n, t, sizeof(t) / sizeof(Name2Int), 1 ); \
  36.    if ( !v ) { \
  37.       return ( CallingInvalid ); \
  38.    } /* endif */ \
  39.    i = v->intval; \
  40.    o = &i;
  41.  
  42. extern const char *RxldapDate;
  43. extern const char *RxldapTime;
  44.  
  45. RexxFunctionHandler RxldapDropFuncs;
  46. RexxFunctionHandler RxldapLoadFuncs;
  47. RexxFunctionHandler RxldapVersion;
  48. RexxFunctionHandler RxldapToUTF8;
  49. RexxFunctionHandler RxldapFromUTF8;
  50. RexxFunctionHandler Rxldap_abandon;
  51. RexxFunctionHandler Rxldap_abandon_ext;
  52. RexxFunctionHandler Rxldap_add;
  53. RexxFunctionHandler Rxldap_add_ext;
  54. RexxFunctionHandler Rxldap_add_ext_s;
  55. RexxFunctionHandler Rxldap_add_s;
  56. RexxFunctionHandler Rxldap_ber_free;
  57. RexxFunctionHandler Rxldap_compare;
  58. RexxFunctionHandler Rxldap_compare_ext;
  59. RexxFunctionHandler Rxldap_compare_ext_s;
  60. RexxFunctionHandler Rxldap_compare_s;
  61. RexxFunctionHandler Rxldap_count_entries;
  62. RexxFunctionHandler Rxldap_count_messages;
  63. RexxFunctionHandler Rxldap_count_references;
  64. RexxFunctionHandler Rxldap_delete;
  65. RexxFunctionHandler Rxldap_delete_ext;
  66. RexxFunctionHandler Rxldap_delete_ext_s;
  67. RexxFunctionHandler Rxldap_delete_s;
  68. RexxFunctionHandler Rxldap_err2string;
  69. RexxFunctionHandler Rxldap_explode_dn;
  70. RexxFunctionHandler Rxldap_first_attribute;
  71. RexxFunctionHandler Rxldap_first_entry;
  72. RexxFunctionHandler Rxldap_first_message;
  73. RexxFunctionHandler Rxldap_first_reference;
  74. RexxFunctionHandler Rxldap_get_dn;
  75. RexxFunctionHandler Rxldap_get_errno;
  76. RexxFunctionHandler Rxldap_get_option;
  77. RexxFunctionHandler Rxldap_get_values;
  78. RexxFunctionHandler Rxldap_get_values_len;
  79. RexxFunctionHandler Rxldap_init;
  80. RexxFunctionHandler Rxldap_is_ldap_url;
  81. RexxFunctionHandler Rxldap_modify;
  82. RexxFunctionHandler Rxldap_modify_ext;
  83. RexxFunctionHandler Rxldap_modify_ext_s;
  84. RexxFunctionHandler Rxldap_modify_s;
  85. RexxFunctionHandler Rxldap_msgfree;
  86. RexxFunctionHandler Rxldap_msgid;
  87. RexxFunctionHandler Rxldap_msgtype;
  88. RexxFunctionHandler Rxldap_next_attribute;
  89. RexxFunctionHandler Rxldap_next_entry;
  90. RexxFunctionHandler Rxldap_next_message;
  91. RexxFunctionHandler Rxldap_next_reference;
  92. RexxFunctionHandler Rxldap_parse_result;
  93. RexxFunctionHandler Rxldap_rename;
  94. RexxFunctionHandler Rxldap_rename_s;
  95. RexxFunctionHandler Rxldap_result;
  96. RexxFunctionHandler Rxldap_search;
  97. RexxFunctionHandler Rxldap_search_ext;
  98. RexxFunctionHandler Rxldap_search_ext_s;
  99. RexxFunctionHandler Rxldap_search_s;
  100. RexxFunctionHandler Rxldap_search_st;
  101. RexxFunctionHandler Rxldap_set_option;
  102. RexxFunctionHandler Rxldap_simple_bind;
  103. RexxFunctionHandler Rxldap_simple_bind_s;
  104. RexxFunctionHandler Rxldap_unbind;
  105. RexxFunctionHandler Rxldap_unbind_s;
  106. RexxFunctionHandler Rxldap_url_parse;
  107. RexxFunctionHandler Rxldap_url_search;
  108. RexxFunctionHandler Rxldap_url_search_s;
  109. RexxFunctionHandler Rxldap_url_search_st;
  110. RexxFunctionHandler Rxldap_version;
  111.  
  112. static const PSZ RxldapFuncsTable[] = {
  113.    "RxldapDropFuncs",
  114.    "RxldapFromUTF8",
  115.    "RxldapLoadFuncs",
  116.    "RxldapToUTF8",
  117.    "RxldapVersion",
  118.    "Rxldap_abandon",
  119.    "Rxldap_abandon_ext",
  120.    "Rxldap_add",
  121.    "Rxldap_add_ext",
  122.    "Rxldap_add_ext_s",
  123.    "Rxldap_add_s",
  124.    "Rxldap_ber_free",
  125.    "Rxldap_compare",
  126.    "Rxldap_compare_ext",
  127.    "Rxldap_compare_ext_s",
  128.    "Rxldap_compare_s",
  129.    "Rxldap_count_entries",
  130.    "Rxldap_count_messages",
  131.    "Rxldap_count_references",
  132.    "Rxldap_delete",
  133.    "Rxldap_delete_ext",
  134.    "Rxldap_delete_ext_s",
  135.    "Rxldap_delete_s",
  136.    "Rxldap_err2string",
  137.    "Rxldap_explode_dn",
  138.    "Rxldap_first_attribute",
  139.    "Rxldap_first_entry",
  140.    "Rxldap_first_message",
  141.    "Rxldap_first_reference",
  142.    "Rxldap_get_dn",
  143.    "Rxldap_get_errno",
  144.    "Rxldap_get_option",
  145.    "Rxldap_get_values",
  146.    "Rxldap_get_values_len",
  147.    "Rxldap_init",
  148.    "Rxldap_is_ldap_url",
  149.    "Rxldap_modify",
  150.    "Rxldap_modify_ext",
  151.    "Rxldap_modify_ext_s",
  152.    "Rxldap_modify_s",
  153.    "Rxldap_msgfree",
  154.    "Rxldap_msgid",
  155.    "Rxldap_msgtype",
  156.    "Rxldap_next_attribute",
  157.    "Rxldap_next_entry",
  158.    "Rxldap_next_message",
  159.    "Rxldap_next_reference",
  160.    "Rxldap_parse_result",
  161.    "Rxldap_rename",
  162.    "Rxldap_rename_s",
  163.    "Rxldap_result",
  164.    "Rxldap_search",
  165.    "Rxldap_search_ext",
  166.    "Rxldap_search_ext_s",
  167.    "Rxldap_search_s",
  168.    "Rxldap_search_st",
  169.    "Rxldap_set_option",
  170.    "Rxldap_simple_bind",
  171.    "Rxldap_simple_bind_s",
  172.    "Rxldap_unbind",
  173.    "Rxldap_unbind_s",
  174.    "Rxldap_url_parse",
  175.    "Rxldap_url_search",
  176.    "Rxldap_url_search_s",
  177.    "Rxldap_url_search_st",
  178.    "Rxldap_version",
  179. };
  180.  
  181. typedef struct {
  182.    char *name;
  183.    int intval;
  184. } Name2Int;   
  185.  
  186. typedef struct {
  187.    char *name;
  188.    char *strval;
  189. } Name2Str;   
  190.  
  191. static const Name2Int ResAllNames[] = {
  192.    {"LDAP_MSG_ALL", LDAP_MSG_ALL},
  193.    {"LDAP_MSG_ONE", LDAP_MSG_ONE},
  194.    {"LDAP_MSG_RECEIVED", LDAP_MSG_RECEIVED},
  195. };   
  196.  
  197. static const Name2Int OpNames[] = {
  198.    {"LDAP_MOD_ADD", LDAP_MOD_ADD},
  199.    {"LDAP_MOD_ADD|LDAP_MOD_BVALUES", LDAP_MOD_ADD|LDAP_MOD_BVALUES},
  200.    {"LDAP_MOD_DELETE", LDAP_MOD_DELETE},
  201.    {"LDAP_MOD_DELETE|LDAP_MOD_BVALUES", LDAP_MOD_DELETE|LDAP_MOD_BVALUES},
  202.    {"LDAP_MOD_REPLACE", LDAP_MOD_REPLACE},
  203.    {"LDAP_MOD_REPLACE|LDAP_MOD_BVALUES", LDAP_MOD_REPLACE|LDAP_MOD_BVALUES},
  204. };
  205.  
  206. static const Name2Int ScopeNames[] = {
  207.    {"LDAP_SCOPE_DEFAULT", LDAP_SCOPE_DEFAULT},
  208.    {"LDAP_SCOPE_BASE", LDAP_SCOPE_BASE},
  209.    {"LDAP_SCOPE_ONELEVEL", LDAP_SCOPE_ONELEVEL},
  210.    {"LDAP_SCOPE_SUBTREE", LDAP_SCOPE_SUBTREE}
  211. };   
  212.  
  213. static const Name2Int ResultTypes[] = {
  214.    {"LDAP_RES_ANY", LDAP_RES_ANY},
  215.    {"LDAP_RES_UNSOLICITED", LDAP_RES_UNSOLICITED},
  216.    {"LDAP_RES_BIND", LDAP_RES_BIND},
  217.    {"LDAP_RES_SEARCH_ENTRY", LDAP_RES_SEARCH_ENTRY},
  218.    {"LDAP_RES_SEARCH_RESULT", LDAP_RES_SEARCH_RESULT},
  219.    {"LDAP_RES_MODIFY", LDAP_RES_MODIFY},
  220.    {"LDAP_RES_ADD", LDAP_RES_ADD},
  221.    {"LDAP_RES_DELETE", LDAP_RES_DELETE},
  222.    {"LDAP_RES_RENAME", LDAP_RES_MODRDN},
  223.    {"LDAP_RES_COMPARE", LDAP_RES_COMPARE},
  224.    {"LDAP_RES_SEARCH_REFERENCE", LDAP_RES_SEARCH_REFERENCE},
  225.    {"LDAP_RES_EXTENDED", LDAP_RES_EXTENDED},
  226.    {"LDAP_RES_EXTENDED_PARTIAL", LDAP_RES_EXTENDED_PARTIAL},
  227. };   
  228.  
  229. static const Name2Int LdapReturnCodes[] = {
  230.    {"LDAP_SUCCESS", LDAP_SUCCESS},
  231.    {"LDAP_OPERATIONS_ERROR", LDAP_OPERATIONS_ERROR},
  232.    {"LDAP_PROTOCOL_ERROR", LDAP_PROTOCOL_ERROR},
  233.    {"LDAP_TIMELIMIT_EXCEEDED", LDAP_TIMELIMIT_EXCEEDED},
  234.    {"LDAP_SIZELIMIT_EXCEEDED", LDAP_SIZELIMIT_EXCEEDED},
  235.    {"LDAP_COMPARE_FALSE", LDAP_COMPARE_FALSE},
  236.    {"LDAP_COMPARE_TRUE", LDAP_COMPARE_TRUE},
  237.    {"LDAP_AUTH_METHOD_NOT_SUPPORTED", LDAP_AUTH_METHOD_NOT_SUPPORTED},
  238.    {"LDAP_STRONG_AUTH_REQUIRED", LDAP_STRONG_AUTH_REQUIRED},
  239.    {"LDAP_PARTIAL_RESULTS", LDAP_PARTIAL_RESULTS},
  240.    {"LDAP_REFERRAL", LDAP_REFERRAL},
  241.    {"LDAP_ADMINLIMIT_EXCEEDED", LDAP_ADMINLIMIT_EXCEEDED},
  242.    {"LDAP_UNAVAILABLE_CRITICAL_EXTENSION", LDAP_UNAVAILABLE_CRITICAL_EXTENSION},
  243.    {"LDAP_CONFIDENTIALITY_REQUIRED", LDAP_CONFIDENTIALITY_REQUIRED},
  244.    {"LDAP_SASL_BIND_IN_PROGRESS", LDAP_SASL_BIND_IN_PROGRESS},
  245.    {"LDAP_NO_SUCH_ATTRIBUTE", LDAP_NO_SUCH_ATTRIBUTE},
  246.    {"LDAP_UNDEFINED_TYPE", LDAP_UNDEFINED_TYPE},
  247.    {"LDAP_INAPPROPRIATE_MATCHING", LDAP_INAPPROPRIATE_MATCHING},
  248.    {"LDAP_CONSTRAINT_VIOLATION", LDAP_CONSTRAINT_VIOLATION},
  249.    {"LDAP_TYPE_OR_VALUE_EXISTS", LDAP_TYPE_OR_VALUE_EXISTS},
  250.    {"LDAP_INVALID_SYNTAX", LDAP_INVALID_SYNTAX},
  251.    {"LDAP_NO_SUCH_OBJECT", LDAP_NO_SUCH_OBJECT},
  252.    {"LDAP_ALIAS_PROBLEM", LDAP_ALIAS_PROBLEM},
  253.    {"LDAP_INVALID_DN_SYNTAX", LDAP_INVALID_DN_SYNTAX},
  254.    {"LDAP_IS_LEAF", LDAP_IS_LEAF},
  255.    {"LDAP_ALIAS_DEREF_PROBLEM", LDAP_ALIAS_DEREF_PROBLEM},
  256.    {"LDAP_INAPPROPRIATE_AUTH", LDAP_INAPPROPRIATE_AUTH},
  257.    {"LDAP_INVALID_CREDENTIALS", LDAP_INVALID_CREDENTIALS},
  258.    {"LDAP_INSUFFICIENT_ACCESS", LDAP_INSUFFICIENT_ACCESS},
  259.    {"LDAP_BUSY", LDAP_BUSY},
  260.    {"LDAP_UNAVAILABLE", LDAP_UNAVAILABLE},
  261.    {"LDAP_UNWILLING_TO_PERFORM", LDAP_UNWILLING_TO_PERFORM},
  262.    {"LDAP_LOOP_DETECT", LDAP_LOOP_DETECT},
  263.    {"LDAP_NAMING_VIOLATION", LDAP_NAMING_VIOLATION},
  264.    {"LDAP_OBJECT_CLASS_VIOLATION", LDAP_OBJECT_CLASS_VIOLATION},
  265.    {"LDAP_NOT_ALLOWED_ON_NONLEAF", LDAP_NOT_ALLOWED_ON_NONLEAF},
  266.    {"LDAP_NOT_ALLOWED_ON_RDN", LDAP_NOT_ALLOWED_ON_RDN},
  267.    {"LDAP_ALREADY_EXISTS", LDAP_ALREADY_EXISTS},
  268.    {"LDAP_NO_OBJECT_CLASS_MODS", LDAP_NO_OBJECT_CLASS_MODS},
  269.    {"LDAP_RESULTS_TOO_LARGE", LDAP_RESULTS_TOO_LARGE},
  270.    {"LDAP_AFFECTS_MULTIPLE_DSAS", LDAP_AFFECTS_MULTIPLE_DSAS},
  271.    {"LDAP_OTHER", LDAP_OTHER},
  272.    {"LDAP_SERVER_DOWN", LDAP_SERVER_DOWN},
  273.    {"LDAP_LOCAL_ERROR", LDAP_LOCAL_ERROR},
  274.    {"LDAP_ENCODING_ERROR", LDAP_ENCODING_ERROR},
  275.    {"LDAP_DECODING_ERROR", LDAP_DECODING_ERROR},
  276.    {"LDAP_TIMEOUT", LDAP_TIMEOUT},
  277.    {"LDAP_AUTH_UNKNOWN", LDAP_AUTH_UNKNOWN},
  278.    {"LDAP_FILTER_ERROR", LDAP_FILTER_ERROR},
  279.    {"LDAP_USER_CANCELLED", LDAP_USER_CANCELLED},
  280.    {"LDAP_PARAM_ERROR", LDAP_PARAM_ERROR},
  281.    {"LDAP_NO_MEMORY", LDAP_NO_MEMORY},
  282.    {"LDAP_CONNECT_ERROR", LDAP_CONNECT_ERROR},
  283.    {"LDAP_NOT_SUPPORTED", LDAP_NOT_SUPPORTED},
  284.    {"LDAP_CONTROL_NOT_FOUND", LDAP_CONTROL_NOT_FOUND},
  285.    {"LDAP_NO_RESULTS_RETURNED", LDAP_NO_RESULTS_RETURNED},
  286.    {"LDAP_MORE_RESULTS_TO_RETURN", LDAP_MORE_RESULTS_TO_RETURN},
  287.    {"LDAP_CLIENT_LOOP", LDAP_CLIENT_LOOP},
  288.    {"LDAP_REFERRAL_LIMIT_EXCEEDED", LDAP_REFERRAL_LIMIT_EXCEEDED},
  289. };
  290.  
  291. static const Name2Int LdapOptNames[] = {
  292.    {"LDAP_OPT_API_FEATURE_INFO", LDAP_OPT_API_FEATURE_INFO},
  293.    {"LDAP_OPT_API_INFO", LDAP_OPT_API_INFO},
  294.    {"LDAP_OPT_CLIENT_CONTROLS", LDAP_OPT_CLIENT_CONTROLS},
  295.    {"LDAP_OPT_DEREF", LDAP_OPT_DEREF},
  296.    {"LDAP_OPT_ERROR_NUMBER", LDAP_OPT_ERROR_NUMBER},
  297.    {"LDAP_OPT_ERROR_STRING", LDAP_OPT_ERROR_STRING},
  298.    {"LDAP_OPT_HOST_NAME", LDAP_OPT_HOST_NAME},
  299.    {"LDAP_OPT_MATCHED_DN", LDAP_OPT_API_FEATURE_INFO},
  300.    {"LDAP_OPT_PROTOCOL_VERSION", LDAP_OPT_PROTOCOL_VERSION},
  301.    {"LDAP_OPT_REFERRALS", LDAP_OPT_REFERRALS},
  302.    {"LDAP_OPT_RESTART", LDAP_OPT_RESTART},
  303.    {"LDAP_OPT_SERVER_CONTROLS", LDAP_OPT_SERVER_CONTROLS},
  304.    {"LDAP_OPT_SIZELIMIT", LDAP_OPT_SIZELIMIT},
  305.    {"LDAP_OPT_TIMELIMIT", LDAP_OPT_TIMELIMIT},
  306. };
  307.  
  308. static const Name2Int LdapOptValDeref[] = {
  309.    {"LDAP_DEREF_ALWAYS", LDAP_DEREF_ALWAYS},
  310.    {"LDAP_DEREF_FINDING", LDAP_DEREF_FINDING},
  311.    {"LDAP_DEREF_NEVER", LDAP_DEREF_NEVER},
  312.    {"LDAP_DEREF_SEARCHING", LDAP_DEREF_SEARCHING},
  313. };   
  314.     
  315. static const Name2Int LdapOptValOnOff[] = {
  316.    {"LDAP_OPT_OFF", (int)LDAP_OPT_OFF},
  317.    {"LDAP_OPT_ON", (int)LDAP_OPT_ON},
  318. };   
  319.     
  320. static BOOL isnumstr( const PCHAR str );
  321. static VOID rxappendstr( PRXSTRING rxstr, const PCHAR str );
  322. static int getvalue( const PRXSTRING name, PRXSTRING value);
  323. static int setvalue( const PRXSTRING name, const PRXSTRING value);
  324. static int parsetimeval( const PRXSTRING rxstr, struct timeval *tv );
  325. static void setcodename( PRXSTRING rxstr, int code, const Name2Int *base, unsigned int num, int lflag );
  326. static int _Optlink compname2intname( const void *item1, const void *item2 );
  327. static int _Optlink compname2intint( const void *item1, const void *item2 );
  328. static int _Optlink compname2strstr( const void *item1, const void *item2 );
  329. static Name2Int *findintfromname( char *key, const Name2Int *base, unsigned int num, int lflag );
  330. static Name2Int *findnamefromint( int key, const Name2Int *base, unsigned int num, int lflag );
  331. static Name2Str *findnamefromstr( const char *key, const Name2Str *base, unsigned int num, int lflag );
  332. static void freestrs( char **a );
  333. static LDAPMod **getldapmods( PRXSTRING stemname );
  334. static char **getldapattrs( PRXSTRING stemname );
  335. static LDAPControl **getldapcontrols( PRXSTRING stemname );
  336. static int setstrs( PRXSTRING stemname, char **strs, int utf8 );
  337. static int setldapctrls( PRXSTRING stemname, LDAPControl **ldapctrl );
  338. static unsigned char *strtoutf8( const unsigned char *str );
  339. static unsigned char *utf8tostr( const unsigned char *utf8str );
  340. static void freemem( void *p );
  341.  
  342. ULONG _Export
  343. Rxldap_version(
  344. PUCHAR name, 
  345. ULONG argc,
  346. RXSTRING argv[],
  347. PSZ queuename,
  348. PRXSTRING retstr) {
  349.    int code = 0;
  350.    LDAPAPIInfo info;
  351.    RXSTRING varname;
  352.    RXSTRING stem;
  353.    RXSTRING value;
  354.    if ( argc != 1 ) {
  355.       return ( CallingInvalid );
  356.    } /* endif */
  357.    if ( RXNULLSTRING(argv[0]) ) {
  358.       return ( CallingInvalid );
  359.    } /* endif */
  360.    if ( !RXSTRLEN(argv[0]) ) {
  361.       return ( CallingInvalid );
  362.    } /* endif */
  363.    info.ldapai_info_version = LDAP_API_INFO_VERSION;
  364.    code = ldap_get_option( NULL, LDAP_OPT_API_INFO, &info );
  365.    varname = rxalloc( RXSTRLEN(argv[0]) + BUFSIZ );
  366.    if ( RXNULLSTRING( varname ) ) {
  367.       return ( CallingInvalid );
  368.    } /* endif */
  369.    stem = rxalloc( RXSTRLEN(argv[0]) + BUFSIZ );
  370.    if ( RXNULLSTRING( stem ) ) {
  371.       rxfree( varname );
  372.       return ( CallingInvalid );
  373.    } /* endif */
  374.    value = rxalloc( BUFSIZ );
  375.    if ( RXNULLSTRING( value ) ) {
  376.       rxfree( varname );
  377.       rxfree( stem );
  378.       return ( CallingInvalid );
  379.    } /* endif */
  380.    rxstrcpy( &stem, &argv[0] );
  381.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  382.       rxappendstr( &stem, "." );
  383.    } /* endif */
  384.    rxappendstr( &stem, "!" );
  385.    rxstrcpy( &varname, &stem );
  386.    rxappendstr( &varname, "SDK_VERSION" );
  387.    rxset_length( &value, strlen( _ltoa( (ULONG)info.ldapai_vendor_version, RXSTRPTR(value), 10 ) ) );
  388.    if ( setvalue( &varname, &value ) != Good ) {
  389.       rxfree( varname );
  390.       rxfree( stem );
  391.       rxfree( value );
  392.       return ( CallingInvalid );
  393.    } /* endif */
  394.    rxstrcpy( &varname, &stem );
  395.    rxappendstr( &varname, "PROTOCOL_VERSION" );
  396.    rxset_length( &value, strlen( _ltoa( (ULONG)info.ldapai_protocol_version, RXSTRPTR(value), 10 ) ) );
  397.    if ( setvalue( &varname, &value ) != Good ) {
  398.       rxfree( varname );
  399.       rxfree( stem );
  400.       rxfree( value );
  401.       return ( CallingInvalid );
  402.    } /* endif */
  403.    rxfree( varname );
  404.    rxfree( stem );
  405.    rxfree( value );
  406.    SetUnsignedInt2Rx( *retstr, code );
  407.    return ( CallingValid );
  408. }
  409.  
  410. ULONG _Export
  411. RxldapToUTF8(
  412. PUCHAR name, 
  413. ULONG argc,
  414. RXSTRING argv[],
  415. PSZ queuename,
  416. PRXSTRING retstr) {
  417.    unsigned char *utf8str = NULL;
  418.    if ( argc != 1 ) {
  419.       return ( CallingInvalid );
  420.    } /* endif */
  421.    if ( RXNULLSTRING(argv[0]) || !RXSTRLEN(argv[0]) ) {
  422.       return ( CallingInvalid );
  423.    } /* endif */
  424.    utf8str = strtoutf8( RXSTRPTR(argv[0]) );
  425.    if ( utf8str ) {
  426.       rxreturn_value( retstr, utf8str, strlen(utf8str) );
  427.       free( utf8str );
  428.    } else {
  429.       rxset_zerolen( retstr );
  430.    } /* endif */
  431.    return ( CallingValid );
  432. }
  433.  
  434. ULONG _Export
  435. RxldapFromUTF8(
  436. PUCHAR name, 
  437. ULONG argc,
  438. RXSTRING argv[],
  439. PSZ queuename,
  440. PRXSTRING retstr) {
  441.    unsigned char *str = NULL;
  442.    if ( argc != 1 ) {
  443.       return ( CallingInvalid );
  444.    } /* endif */
  445.    if ( RXNULLSTRING(argv[0]) || !RXSTRLEN(argv[0]) ) {
  446.       return ( CallingInvalid );
  447.    } /* endif */
  448.    str = utf8tostr( RXSTRPTR(argv[0]) );
  449.    if ( str ) {
  450.       rxreturn_value( retstr, str, strlen(str) );
  451.       free( str );
  452.    } else {
  453.       rxset_zerolen( retstr );
  454.    } /* endif */
  455.    return ( CallingValid );
  456. }
  457.  
  458. ULONG _Export
  459. Rxldap_init(
  460. PUCHAR name, 
  461. ULONG argc,
  462. RXSTRING argv[],
  463. PSZ queuename,
  464. PRXSTRING retstr) {
  465.    int port = LDAP_PORT;
  466.    LDAP *ld = NULL;
  467.    if ( argc < 1 || argc > 2 ) {
  468.       return ( CallingInvalid );
  469.    } /* endif */
  470.    if ( RXNULLSTRING(argv[0]) || !RXSTRLEN(argv[0]) ) {
  471.       return ( CallingInvalid );
  472.    } /* endif */
  473.    if ( 2 == argc && !isnumstr(RXSTRPTR(argv[1])) ) {
  474.       if ( !isnumstr(RXSTRPTR(argv[1])) ) {
  475.          return ( CallingInvalid );
  476.       } /* endif */
  477.       port = rxtoi( argv[1] );
  478.    } /* endif */
  479.    ld = ldap_init( RXSTRPTR(argv[0]), port );
  480.    SetUnsignedInt2Rx( *retstr, ld );
  481.    return ( CallingValid );
  482. }
  483.  
  484. ULONG _Export 
  485. RxldapLoadFuncs(
  486. PUCHAR name, 
  487. ULONG argc,
  488. RXSTRING argv[],
  489. PSZ queuename,
  490. PRXSTRING retstr) {
  491.    static const size_t n = sizeof(RxldapFuncsTable) / sizeof(RxldapFuncsTable[0]);
  492.    RXSTRING a;
  493.    int i = 0;
  494.    if ( argc > 0 ) {
  495.       return ( CallingInvalid );
  496.    } /* endif */
  497.    for ( i = 0; i < n; i += 1 ) {
  498.       ULONG code = RexxDeregisterFunction(RxldapFuncsTable[i]);
  499.       switch (code) {
  500.       case RXFUNC_OK:
  501.       case RXFUNC_DEFINED:
  502.       case RXFUNC_NOTREG:
  503.          break;
  504.       default:
  505.          return ( CallingInvalid );
  506.       } /* endswitch */
  507.       code = RexxRegisterFunctionDll(RxldapFuncsTable[i], RxldapDll, RxldapFuncsTable[i]);
  508.       if ( code != RXFUNC_OK ) {
  509.          return ( CallingInvalid );
  510.       } /* endif */
  511.    } /* endfor */
  512.    i = sprintf(RXSTRPTR(*retstr), "RXLDAP Version: %s (%s %s)", RxldapVer, RxldapDate, RxldapTime);
  513.    if ( i + 1 > RXSTRLEN(*retstr) ) {
  514.       return ( CallingInvalid );
  515.    } /* endif */
  516.    rxset_length( retstr, i );
  517.    return ( CallingValid );
  518. }
  519.  
  520. ULONG _Export  
  521. RxldapDropFuncs(
  522. PUCHAR name, 
  523. ULONG argc,
  524. RXSTRING argv[],
  525. PSZ queuename,
  526. PRXSTRING retstr) {
  527.    static const size_t n = sizeof(RxldapFuncsTable) / sizeof(RxldapFuncsTable[0]);
  528.    int i = 0;
  529.    if (argc > 0) {
  530.       return ( CallingInvalid );
  531.    } /* endif */
  532.    for ( i = 0; i < n; i += 1 ) {
  533.       ULONG code = RexxDeregisterFunction(RxldapFuncsTable[i]);
  534.       switch (code) {
  535.       case RXFUNC_OK:
  536.       case RXFUNC_DEFINED:
  537.       case RXFUNC_NOTREG:
  538.          break;
  539.       default:
  540.          return ( CallingInvalid );
  541.       } /* endswitch */
  542.    } /* endfor */
  543.    rxset_zerolen( retstr );
  544.    return ( CallingValid );
  545. }
  546.  
  547. ULONG _Export  
  548. RxldapVersion(
  549. PUCHAR name, 
  550. ULONG argc,
  551. RXSTRING argv[],
  552. PSZ queuename,
  553. PRXSTRING retstr) {
  554.    int i = 0;
  555.    if (argc > 0) {
  556.       return ( CallingInvalid );
  557.    } /* endif */
  558.    i = sprintf(RXSTRPTR(*retstr), "RXLDAP Version: %s (%s %s)", RxldapVer, RxldapDate, RxldapTime);
  559.    if ( i + 1 > RXSTRLEN(*retstr) ) {
  560.       return ( CallingInvalid );
  561.    } /* endif */
  562.    rxset_length( retstr, i );
  563.    return ( CallingValid );
  564. }
  565.  
  566. ULONG _Export
  567. Rxldap_simple_bind(
  568. PUCHAR name, 
  569. ULONG argc,
  570. RXSTRING argv[],
  571. PSZ queuename,
  572. PRXSTRING retstr) {
  573.    LDAP *ld = NULL;
  574.    char *dn = NULL;
  575.    char *passwd = NULL;
  576.    int code = 0;
  577.    int freedn = 0;
  578.    if ( argc < 1 || argc > 3 ) {
  579.       return ( CallingInvalid );
  580.    } /* endif */
  581.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  582.       return ( CallingInvalid );
  583.    } /* endif */
  584.    ld = (LDAP*)rxtoul( argv[0] );
  585.    if ( argc > 1 && !RXNULLSTRING(argv[1]) && RXSTRLEN(argv[1]) ) {
  586.       dn = strtoutf8(RXSTRPTR(argv[1]));
  587.       if ( dn ) {
  588.          freedn = 1;
  589.       } else {
  590.          dn = RXSTRPTR(argv[1]);
  591.       } /* endif */
  592.    } /* endif */
  593.    if ( argc > 2 && !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  594.       passwd = RXSTRPTR(argv[2]);
  595.    } /* endif */
  596.    code = ldap_simple_bind( ld, dn, passwd );
  597.    if ( freedn ) {
  598.       free( dn );
  599.    } /* endif */
  600.    SetSignedInt2Rx( *retstr, code );
  601.    return ( CallingValid );
  602. }   
  603.  
  604. ULONG _Export
  605. Rxldap_simple_bind_s(
  606. PUCHAR name, 
  607. ULONG argc,
  608. RXSTRING argv[],
  609. PSZ queuename,
  610. PRXSTRING retstr) {
  611.    LDAP *ld = NULL;
  612.    char *dn = NULL;
  613.    char *passwd = NULL;
  614.    int code = 0;
  615.    int freedn = 0;
  616.    if ( argc < 1 || argc > 3 ) {
  617.       return ( CallingInvalid );
  618.    } /* endif */
  619.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  620.       return ( CallingInvalid );
  621.    } /* endif */
  622.    ld = (LDAP*)rxtoul( argv[0] );
  623.    if ( argc > 1 && !RXNULLSTRING(argv[1]) && RXSTRLEN(argv[1]) ) {
  624.       dn = strtoutf8(RXSTRPTR(argv[1]));
  625.       if ( dn ) {
  626.          freedn = 1;
  627.       } else {
  628.          dn = RXSTRPTR(argv[1]);
  629.       } /* endif */
  630.    } /* endif */
  631.    if ( argc > 2 && !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  632.       passwd = RXSTRPTR(argv[2]);
  633.    } /* endif */
  634.    code = ldap_simple_bind_s( ld, dn, passwd );
  635.    if ( freedn ) {
  636.       free( dn );
  637.    } /* endif */
  638.    SetLdapCode( retstr, code );
  639.    return ( CallingValid );
  640. }   
  641.  
  642. ULONG _Export
  643. Rxldap_unbind(
  644. PUCHAR name, 
  645. ULONG argc,
  646. RXSTRING argv[],
  647. PSZ queuename,
  648. PRXSTRING retstr) {
  649.    LDAP *ld = NULL;
  650.    int code = 0;
  651.    if ( argc != 1 ) {
  652.       return ( CallingInvalid );
  653.    } /* endif */
  654.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  655.       return ( CallingInvalid );
  656.    } /* endif */
  657.    ld = (LDAP*)rxtoul( argv[0] );
  658.    code = ldap_unbind( ld );
  659.    SetSignedInt2Rx( *retstr, code );
  660.    return ( CallingValid );
  661. }   
  662.  
  663. ULONG _Export
  664. Rxldap_unbind_s(
  665. PUCHAR name, 
  666. ULONG argc,
  667. RXSTRING argv[],
  668. PSZ queuename,
  669. PRXSTRING retstr) {
  670.    LDAP *ld = NULL;
  671.    int code = 0;
  672.    if ( argc != 1 ) {
  673.       return ( CallingInvalid );
  674.    } /* endif */
  675.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  676.       return ( CallingInvalid );
  677.    } /* endif */
  678.    ld = (LDAP*)rxtoul( argv[0] );
  679.    code = ldap_unbind_s( ld );
  680.    SetLdapCode( retstr, code );
  681.    return ( CallingValid );
  682. }   
  683.  
  684. ULONG _Export
  685. Rxldap_rename(
  686. PUCHAR name, 
  687. ULONG argc,
  688. RXSTRING argv[],
  689. PSZ queuename,
  690. PRXSTRING retstr) {
  691.    LDAP *ld = NULL;
  692.    int code = 0;
  693.    char *newparent = NULL;
  694.    int deleteoldrdn = 0;
  695.    LDAPControl **serverctrls = NULL;
  696.    LDAPControl **clientctrls = NULL;
  697.    RXSTRING value;
  698.    int msgid = 0;
  699.    unsigned char *dn = NULL;
  700.    unsigned char *newrdn = NULL;
  701.    int freedn = 0;
  702.    int freenewrdn = 0;
  703.    int freenewparent = 0;
  704.    if ( argc != 8 ) {
  705.       return ( CallingInvalid );
  706.    } /* endif */
  707.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[7]) ) {
  708.       return ( CallingInvalid );
  709.    } /* endif */
  710.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[7]) ) {
  711.       return ( CallingInvalid );
  712.    } /* endif */
  713.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[4])) ) {
  714.       return ( CallingInvalid );
  715.    } /* endif */
  716.    ld = (LDAP *)rxtoul( argv[0] );
  717.    dn = strtoutf8(RXSTRPTR(argv[1]));
  718.    if ( dn ) {
  719.       freedn = 1;
  720.    } else {
  721.       dn = RXSTRPTR(argv[1]);
  722.    } /* endif */
  723.    newrdn = strtoutf8(RXSTRPTR(argv[2]));
  724.    if ( newrdn ) {
  725.       freenewrdn = 1;
  726.    } else {
  727.       newrdn = RXSTRPTR(argv[2]);
  728.    } /* endif */
  729.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  730.       newparent = strtoutf8(RXSTRPTR(argv[3]));
  731.       if ( newparent) {
  732.          freenewparent = 1;
  733.       } else {
  734.          newparent = RXSTRPTR(argv[3]);
  735.       } /* endif */
  736.    } /* endif */
  737.    deleteoldrdn = rxtoi( argv[4] );
  738.    if ( !RXNULLSTRING(argv[5]) && RXSTRLEN(argv[5]) ) {
  739.       serverctrls = getldapcontrols( &argv[5] );
  740.       if ( !serverctrls ) {
  741.          return ( CallingInvalid );
  742.       } /* endif */
  743.    } /* endif */
  744.    if ( !RXNULLSTRING(argv[6]) && RXSTRLEN(argv[6]) ) {
  745.       clientctrls = getldapcontrols( &argv[6] );
  746.       if ( !clientctrls ) {
  747.          return ( CallingInvalid );
  748.       } /* endif */
  749.    } /* endif */
  750.    code = ldap_rename( ld, dn, newrdn, newparent, deleteoldrdn, serverctrls, clientctrls, &msgid );
  751.    value = rxalloc( BUFSIZ );
  752.    if ( RXNULLSTRING( value ) ) {
  753.       if ( freedn ) {
  754.          free( dn );
  755.       } /* endif */
  756.       if ( freenewrdn ) {
  757.          free( newrdn );
  758.       } /* endif */
  759.       if ( freenewparent ) {
  760.          free( newparent );
  761.       } /* endif */
  762.       return ( CallingInvalid );
  763.    } /* endif */
  764.    SetUnsignedInt2Rx( value, msgid );
  765.    if ( setvalue( &argv[7], &value ) != Good ) {
  766.       rxfree( value );
  767.       if ( freedn ) {
  768.          free( dn );
  769.       } /* endif */
  770.       if ( freenewrdn ) {
  771.          free( newrdn );
  772.       } /* endif */
  773.       if ( freenewparent ) {
  774.          free( newparent );
  775.       } /* endif */
  776.       return ( CallingInvalid );
  777.    } /* endif */
  778.    rxfree( value );
  779.    ldap_controls_free( serverctrls );
  780.    ldap_controls_free( clientctrls );
  781.    if ( freedn ) {
  782.       free( dn );
  783.    } /* endif */
  784.    if ( freenewrdn ) {
  785.       free( newrdn );
  786.    } /* endif */
  787.    if ( freenewparent ) {
  788.       free( newparent );
  789.    } /* endif */
  790.    SetLdapCode( retstr, code );
  791.    return ( CallingValid );
  792. }   
  793.  
  794. ULONG _Export
  795. Rxldap_rename_s(
  796. PUCHAR name, 
  797. ULONG argc,
  798. RXSTRING argv[],
  799. PSZ queuename,
  800. PRXSTRING retstr) {
  801.    LDAP *ld = NULL;
  802.    int code = 0;
  803.    char *newparent = NULL;
  804.    int deleteoldrdn = 0;
  805.    LDAPControl **serverctrls = NULL;
  806.    LDAPControl **clientctrls = NULL;
  807.    unsigned char *dn = NULL;
  808.    unsigned char *newrdn = NULL;
  809.    int freedn = 0;
  810.    int freenewrdn = 0;
  811.    int freenewparent = 0;
  812.    if ( argc < 5 || argc > 7 ) {
  813.       return ( CallingInvalid );
  814.    } /* endif */
  815.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  816.       return ( CallingInvalid );
  817.    } /* endif */
  818.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  819.       return ( CallingInvalid );
  820.    } /* endif */
  821.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[4])) ) {
  822.       return ( CallingInvalid );
  823.    } /* endif */
  824.    ld = (LDAP *)rxtoul( argv[0] );
  825.    dn = strtoutf8(RXSTRPTR(argv[1]));
  826.    if ( dn ) {
  827.       freedn = 1;
  828.    } else {
  829.       dn = RXSTRPTR(argv[1]);
  830.    } /* endif */
  831.    newrdn = strtoutf8(RXSTRPTR(argv[2]));
  832.    if ( newrdn ) {
  833.       freenewrdn = 1;
  834.    } else {
  835.       newrdn = RXSTRPTR(argv[2]);
  836.    } /* endif */
  837.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  838.       newparent = strtoutf8(RXSTRPTR(argv[3]));
  839.       if ( newparent) {
  840.          freenewparent = 1;
  841.       } else {
  842.          newparent = RXSTRPTR(argv[3]);
  843.       } /* endif */
  844.    } /* endif */
  845.    deleteoldrdn = rxtoi( argv[4] );
  846.    if ( !RXNULLSTRING(argv[5]) && RXSTRLEN(argv[5]) ) {
  847.       serverctrls = getldapcontrols( &argv[5] );
  848.       if ( !serverctrls ) {
  849.          return ( CallingInvalid );
  850.       } /* endif */
  851.    } /* endif */
  852.    if ( !RXNULLSTRING(argv[6]) && RXSTRLEN(argv[6]) ) {
  853.       clientctrls = getldapcontrols( &argv[6] );
  854.       if ( !clientctrls ) {
  855.          return ( CallingInvalid );
  856.       } /* endif */
  857.    } /* endif */
  858.    code = ldap_rename_s( ld, dn, newrdn, newparent, deleteoldrdn, serverctrls, clientctrls );
  859.    if ( freedn ) {
  860.       free( dn );
  861.    } /* endif */
  862.    if ( freenewrdn ) {
  863.       free( newrdn );
  864.    } /* endif */
  865.    if ( freenewparent ) {
  866.       free( newparent );
  867.    } /* endif */
  868.    SetLdapCode( retstr, code );
  869.    return ( CallingValid );
  870. }   
  871.  
  872. ULONG _Export       
  873. Rxldap_add(
  874. PUCHAR name, 
  875. ULONG argc,
  876. RXSTRING argv[],
  877. PSZ queuename,
  878. PRXSTRING retstr) {
  879.    LDAP *ld = NULL;
  880.    LDAPMod **mods = NULL;
  881.    int code = 0;
  882.    if ( argc != 3 ) {
  883.       return ( CallingInvalid );
  884.    } /* endif */
  885.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  886.       return ( CallingInvalid );
  887.    } /* endif */
  888.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  889.       return ( CallingInvalid );
  890.    } /* endif */
  891.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  892.       return ( CallingInvalid );
  893.    } /* endif */
  894.    ld = (LDAP *)rxtoul( argv[0] );
  895.    mods = getldapmods( &argv[2] );
  896.    if ( !mods ) {
  897.       return ( CallingInvalid );
  898.    } /* endif */
  899.    code = ldap_add( ld, RXSTRPTR(argv[1]), mods );
  900.    ldap_mods_free( mods, 1 );
  901.    SetSignedInt2Rx( *retstr, code );
  902.    return ( CallingValid );
  903. }   
  904.  
  905. ULONG _Export       
  906. Rxldap_add_ext(
  907. PUCHAR name, 
  908. ULONG argc,
  909. RXSTRING argv[],
  910. PSZ queuename,
  911. PRXSTRING retstr) {
  912.    LDAP *ld = NULL;
  913.    LDAPMod **mods = NULL;
  914.    int code = 0;
  915.    LDAPControl **serverctrls = NULL;
  916.    LDAPControl **clientctrls = NULL;
  917.    int msgid = 0;
  918.    RXSTRING value;
  919.    if ( argc != 6 ) {
  920.       return ( CallingInvalid );
  921.    } /* endif */
  922.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[5]) ) {
  923.       return ( CallingInvalid );
  924.    } /* endif */
  925.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[5]) ) {
  926.       return ( CallingInvalid );
  927.    } /* endif */
  928.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  929.       return ( CallingInvalid );
  930.    } /* endif */
  931.    ld = (LDAP *)rxtoul( argv[0] );
  932.    mods = getldapmods( &argv[2] );
  933.    if ( !mods ) {
  934.       return ( CallingInvalid );
  935.    } /* endif */
  936.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  937.       serverctrls = getldapcontrols( &argv[6] );
  938.       if ( !serverctrls ) {
  939.          ldap_mods_free( mods, 1 );
  940.          return ( CallingInvalid );
  941.       } /* endif */
  942.    } /* endif */
  943.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  944.       clientctrls = getldapcontrols( &argv[7] );
  945.       if ( !clientctrls ) {
  946.          ldap_mods_free( mods, 1 );
  947.          return ( CallingInvalid );
  948.       } /* endif */
  949.    } /* endif */
  950.    code = ldap_add_ext( ld, RXSTRPTR(argv[1]), mods, serverctrls, clientctrls, &msgid );
  951.    ldap_mods_free( mods, 1 );
  952.    value = rxalloc( BUFSIZ );
  953.    if ( RXNULLSTRING( value ) ) {
  954.       return ( CallingInvalid );
  955.    } /* endif */
  956.    SetUnsignedInt2Rx( value, msgid );
  957.    if ( setvalue( &argv[5], &value ) != Good ) {
  958.       rxfree( value );
  959.       return ( CallingInvalid );
  960.    } /* endif */
  961.    rxfree( value );
  962.    ldap_controls_free( serverctrls );
  963.    ldap_controls_free( clientctrls );
  964.    SetLdapCode( retstr, code );
  965.    return ( CallingValid );
  966. }   
  967.  
  968. ULONG _Export       
  969. Rxldap_add_s(
  970. PUCHAR name, 
  971. ULONG argc,
  972. RXSTRING argv[],
  973. PSZ queuename,
  974. PRXSTRING retstr) {
  975.    LDAP *ld = NULL;
  976.    LDAPMod **mods = NULL;
  977.    int code = 0;
  978.    if ( argc != 3 ) {
  979.       return ( CallingInvalid );
  980.    } /* endif */
  981.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  982.       return ( CallingInvalid );
  983.    } /* endif */
  984.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  985.       return ( CallingInvalid );
  986.    } /* endif */
  987.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  988.       return ( CallingInvalid );
  989.    } /* endif */
  990.    ld = (LDAP *)rxtoul( argv[0] );
  991.    mods = getldapmods( &argv[2] );
  992.    if ( !mods ) {
  993.       return ( CallingInvalid );
  994.    } /* endif */
  995.    code = ldap_add_s( ld, RXSTRPTR(argv[1]), mods );
  996.    ldap_mods_free( mods, 1 );
  997.    SetLdapCode( retstr, code );
  998.    return ( CallingValid );
  999. }   
  1000.  
  1001. ULONG _Export       
  1002. Rxldap_add_ext_s(
  1003. PUCHAR name, 
  1004. ULONG argc,
  1005. RXSTRING argv[],
  1006. PSZ queuename,
  1007. PRXSTRING retstr) {
  1008.    LDAP *ld = NULL;
  1009.    LDAPMod **mods = NULL;
  1010.    int code = 0;
  1011.    LDAPControl **serverctrls = NULL;
  1012.    LDAPControl **clientctrls = NULL;
  1013.    if ( argc < 3 || argc > 5 ) {
  1014.       return ( CallingInvalid );
  1015.    } /* endif */
  1016.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  1017.       return ( CallingInvalid );
  1018.    } /* endif */
  1019.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1020.       return ( CallingInvalid );
  1021.    } /* endif */
  1022.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1023.       return ( CallingInvalid );
  1024.    } /* endif */
  1025.    ld = (LDAP *)rxtoul( argv[0] );
  1026.    mods = getldapmods( &argv[2] );
  1027.    if ( !mods ) {
  1028.       return ( CallingInvalid );
  1029.    } /* endif */
  1030.    if ( argc > 3 && !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  1031.       serverctrls = getldapcontrols( &argv[6] );
  1032.       if ( !serverctrls ) {
  1033.          ldap_mods_free( mods, 1 );
  1034.          return ( CallingInvalid );
  1035.       } /* endif */
  1036.    } /* endif */
  1037.    if ( argc > 4 && !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1038.       clientctrls = getldapcontrols( &argv[7] );
  1039.       if ( !clientctrls ) {
  1040.          ldap_mods_free( mods, 1 );
  1041.          return ( CallingInvalid );
  1042.       } /* endif */
  1043.    } /* endif */
  1044.    code = ldap_add_ext_s( ld, RXSTRPTR(argv[1]), mods, serverctrls, clientctrls );
  1045.    ldap_mods_free( mods, 1 );
  1046.    ldap_controls_free( serverctrls );
  1047.    ldap_controls_free( clientctrls );
  1048.    SetLdapCode( retstr, code );
  1049.    return ( CallingValid );
  1050. }   
  1051.  
  1052. ULONG _Export       
  1053. Rxldap_modify(
  1054. PUCHAR name, 
  1055. ULONG argc,
  1056. RXSTRING argv[],
  1057. PSZ queuename,
  1058. PRXSTRING retstr) {
  1059.    LDAP *ld = NULL;
  1060.    LDAPMod **mods = NULL;
  1061.    int code = 0;
  1062.    if ( argc != 3 ) {
  1063.       return ( CallingInvalid );
  1064.    } /* endif */
  1065.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  1066.       return ( CallingInvalid );
  1067.    } /* endif */
  1068.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1069.       return ( CallingInvalid );
  1070.    } /* endif */
  1071.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1072.       return ( CallingInvalid );
  1073.    } /* endif */
  1074.    ld = (LDAP *)rxtoul( argv[0] );
  1075.    mods = getldapmods( &argv[2] );
  1076.    if ( !mods ) {
  1077.       return ( CallingInvalid );
  1078.    } /* endif */
  1079.    code = ldap_modify( ld, RXSTRPTR(argv[1]), mods );
  1080.    ldap_mods_free( mods, 1 );
  1081.    SetSignedInt2Rx( *retstr, code );
  1082.    return ( CallingValid );
  1083. }   
  1084.  
  1085. ULONG _Export       
  1086. Rxldap_modify_ext(
  1087. PUCHAR name, 
  1088. ULONG argc,
  1089. RXSTRING argv[],
  1090. PSZ queuename,
  1091. PRXSTRING retstr) {
  1092.    LDAP *ld = NULL;
  1093.    LDAPMod **mods = NULL;
  1094.    int code = 0;
  1095.    LDAPControl **serverctrls = NULL;
  1096.    LDAPControl **clientctrls = NULL;
  1097.    int msgid = 0;
  1098.    RXSTRING value;
  1099.    if ( argc != 6 ) {
  1100.       return ( CallingInvalid );
  1101.    } /* endif */
  1102.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[5]) ) {
  1103.       return ( CallingInvalid );
  1104.    } /* endif */
  1105.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[5]) ) {
  1106.       return ( CallingInvalid );
  1107.    } /* endif */
  1108.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1109.       return ( CallingInvalid );
  1110.    } /* endif */
  1111.    ld = (LDAP *)rxtoul( argv[0] );
  1112.    mods = getldapmods( &argv[2] );
  1113.    if ( !mods ) {
  1114.       return ( CallingInvalid );
  1115.    } /* endif */
  1116.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  1117.       serverctrls = getldapcontrols( &argv[6] );
  1118.       if ( !serverctrls ) {
  1119.          ldap_mods_free( mods, 1 );
  1120.          return ( CallingInvalid );
  1121.       } /* endif */
  1122.    } /* endif */
  1123.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1124.       clientctrls = getldapcontrols( &argv[7] );
  1125.       if ( !clientctrls ) {
  1126.          ldap_mods_free( mods, 1 );
  1127.          return ( CallingInvalid );
  1128.       } /* endif */
  1129.    } /* endif */
  1130.    code = ldap_modify_ext( ld, RXSTRPTR(argv[1]), mods, serverctrls, clientctrls, &msgid );
  1131.    ldap_mods_free( mods, 1 );
  1132.    value = rxalloc( BUFSIZ );
  1133.    if ( RXNULLSTRING( value ) ) {
  1134.       return ( CallingInvalid );
  1135.    } /* endif */
  1136.    SetUnsignedInt2Rx( value, msgid );
  1137.    if ( setvalue( &argv[5], &value ) != Good ) {
  1138.       rxfree( value );
  1139.       return ( CallingInvalid );
  1140.    } /* endif */
  1141.    rxfree( value );
  1142.    ldap_controls_free( serverctrls );
  1143.    ldap_controls_free( clientctrls );
  1144.    SetLdapCode( retstr, code );
  1145.    return ( CallingValid );
  1146. }   
  1147.  
  1148. ULONG _Export       
  1149. Rxldap_modify_ext_s(
  1150. PUCHAR name, 
  1151. ULONG argc,
  1152. RXSTRING argv[],
  1153. PSZ queuename,
  1154. PRXSTRING retstr) {
  1155.    LDAP *ld = NULL;
  1156.    LDAPMod **mods = NULL;
  1157.    int code = 0;
  1158.    LDAPControl **serverctrls = NULL;
  1159.    LDAPControl **clientctrls = NULL;
  1160.    if ( argc < 3 || argc > 5 ) {
  1161.       return ( CallingInvalid );
  1162.    } /* endif */
  1163.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  1164.       return ( CallingInvalid );
  1165.    } /* endif */
  1166.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1167.       return ( CallingInvalid );
  1168.    } /* endif */
  1169.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1170.       return ( CallingInvalid );
  1171.    } /* endif */
  1172.    ld = (LDAP *)rxtoul( argv[0] );
  1173.    mods = getldapmods( &argv[2] );
  1174.    if ( !mods ) {
  1175.       return ( CallingInvalid );
  1176.    } /* endif */
  1177.    if ( argc > 3 && !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  1178.       serverctrls = getldapcontrols( &argv[6] );
  1179.       if ( !serverctrls ) {
  1180.          ldap_mods_free( mods, 1 );
  1181.          return ( CallingInvalid );
  1182.       } /* endif */
  1183.    } /* endif */
  1184.    if ( argc > 4 && !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1185.       clientctrls = getldapcontrols( &argv[7] );
  1186.       if ( !clientctrls ) {
  1187.          ldap_mods_free( mods, 1 );
  1188.          return ( CallingInvalid );
  1189.       } /* endif */
  1190.    } /* endif */
  1191.    code = ldap_modify_ext_s( ld, RXSTRPTR(argv[1]), mods, serverctrls, clientctrls );
  1192.    ldap_mods_free( mods, 1 );
  1193.    ldap_controls_free( serverctrls );
  1194.    ldap_controls_free( clientctrls );
  1195.    SetLdapCode( retstr, code );
  1196.    return ( CallingValid );
  1197. }   
  1198.  
  1199. ULONG _Export       
  1200. Rxldap_modify_s(
  1201. PUCHAR name, 
  1202. ULONG argc,
  1203. RXSTRING argv[],
  1204. PSZ queuename,
  1205. PRXSTRING retstr) {
  1206.    LDAP *ld = NULL;
  1207.    LDAPMod **mods = NULL;
  1208.    int code = 0;
  1209.    if ( argc != 3 ) {
  1210.       return ( CallingInvalid );
  1211.    } /* endif */
  1212.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  1213.       return ( CallingInvalid );
  1214.    } /* endif */
  1215.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1216.       return ( CallingInvalid );
  1217.    } /* endif */
  1218.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1219.       return ( CallingInvalid );
  1220.    } /* endif */
  1221.    ld = (LDAP *)rxtoul( argv[0] );
  1222.    mods = getldapmods( &argv[2] );
  1223.    if ( !mods ) {
  1224.       return ( CallingInvalid );
  1225.    } /* endif */
  1226.    code = ldap_modify_s( ld, RXSTRPTR(argv[1]), mods );
  1227.    ldap_mods_free( mods, 1 );
  1228.    SetLdapCode( retstr, code );
  1229.    return ( CallingValid );
  1230. }   
  1231.  
  1232. ULONG _Export
  1233. Rxldap_compare_s(
  1234. PUCHAR name, 
  1235. ULONG argc,
  1236. RXSTRING argv[],
  1237. PSZ queuename,
  1238. PRXSTRING retstr) {
  1239.    LDAP *ld = NULL;
  1240.    int code = 0;
  1241.    unsigned char *dn = NULL;
  1242.    unsigned char *va = NULL;
  1243.    int freedn = 0;
  1244.    int freeva = 0;
  1245.    if ( argc != 4 ) {
  1246.       return ( CallingInvalid );
  1247.    } /* endif */
  1248.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[3]) ) {
  1249.       return ( CallingInvalid );
  1250.    } /* endif */
  1251.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1252.       return ( CallingInvalid );
  1253.    } /* endif */
  1254.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1255.       return ( CallingInvalid );
  1256.    } /* endif */
  1257.    ld = (LDAP *)rxtoul( argv[0] );
  1258.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1259.    if ( dn ) {
  1260.       freedn = 1;
  1261.    } else {
  1262.       dn = RXSTRPTR(argv[1]);
  1263.    } /* endif */
  1264.    va = strtoutf8( RXSTRPTR(argv[3]) );
  1265.    if ( va ) {
  1266.       freeva = 1;
  1267.    } else {
  1268.       va = RXSTRPTR(argv[3]);
  1269.    } /* endif */
  1270.    code = ldap_compare_s( ld, dn, RXSTRPTR(argv[2]), va );
  1271.    if ( freedn ) {
  1272.       free( dn );
  1273.    } /* endif */
  1274.    if ( freeva ) {
  1275.       free( va );
  1276.    } /* endif */
  1277.    SetLdapCode( retstr, code );
  1278.    return ( CallingValid );
  1279. }   
  1280.  
  1281. ULONG _Export
  1282. Rxldap_compare(
  1283. PUCHAR name, 
  1284. ULONG argc,
  1285. RXSTRING argv[],
  1286. PSZ queuename,
  1287. PRXSTRING retstr) {
  1288.    LDAP *ld = NULL;
  1289.    int code = 0;
  1290.    unsigned char *dn = NULL;
  1291.    unsigned char *va = NULL;
  1292.    int freedn = 0;
  1293.    int freeva = 0;
  1294.    if ( argc != 4 ) {
  1295.       return ( CallingInvalid );
  1296.    } /* endif */
  1297.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[3]) ) {
  1298.       return ( CallingInvalid );
  1299.    } /* endif */
  1300.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1301.       return ( CallingInvalid );
  1302.    } /* endif */
  1303.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1304.       return ( CallingInvalid );
  1305.    } /* endif */
  1306.    ld = (LDAP *)rxtoul( argv[0] );
  1307.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1308.    if ( dn ) {
  1309.       freedn = 1;
  1310.    } else {
  1311.       dn = RXSTRPTR(argv[1]);
  1312.    } /* endif */
  1313.    va = strtoutf8( RXSTRPTR(argv[3]) );
  1314.    if ( va ) {
  1315.       freeva = 1;
  1316.    } else {
  1317.       va = RXSTRPTR(argv[3]);
  1318.    } /* endif */
  1319.    code = ldap_compare( ld, dn, RXSTRPTR(argv[2]), va );
  1320.    if ( freedn ) {
  1321.       free( dn );
  1322.    } /* endif */
  1323.    if ( freeva ) {
  1324.       free( va );
  1325.    } /* endif */
  1326.    SetSignedInt2Rx( *retstr, code );
  1327.    return ( CallingValid );
  1328. }   
  1329.           
  1330. ULONG _Export
  1331. Rxldap_compare_ext_s(
  1332. PUCHAR name, 
  1333. ULONG argc,
  1334. RXSTRING argv[],
  1335. PSZ queuename,
  1336. PRXSTRING retstr) {
  1337.    LDAP *ld = NULL;
  1338.    LDAPControl **serverctrls = NULL;
  1339.    LDAPControl **clientctrls = NULL;
  1340.    int code = 0;
  1341.    struct berval bvalue;
  1342.    unsigned char *dn = NULL;
  1343.    int freedn = 0;
  1344.    if ( argc < 4 || argc > 6 ) {
  1345.       return ( CallingInvalid );
  1346.    } /* endif */
  1347.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[3]) ) {
  1348.       return ( CallingInvalid );
  1349.    } /* endif */
  1350.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  1351.       return ( CallingInvalid );
  1352.    } /* endif */
  1353.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1354.       return ( CallingInvalid );
  1355.    } /* endif */
  1356.    ld = (LDAP *)rxtoul( argv[0] );
  1357.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1358.    if ( dn ) {
  1359.       freedn = 1;
  1360.    } else {
  1361.       dn = RXSTRPTR(argv[1]);
  1362.    } /* endif */
  1363.    bvalue.bv_val = RXSTRPTR(argv[3]);
  1364.    bvalue.bv_len = RXSTRLEN(argv[3]);
  1365.    if ( argc > 4 && !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1366.       serverctrls = getldapcontrols( &argv[4] );
  1367.       if ( !serverctrls ) {
  1368.          if ( freedn ) {
  1369.             free( dn );
  1370.          } /* endif */
  1371.          return ( CallingInvalid );
  1372.       } /* endif */
  1373.    } /* endif */
  1374.    if ( argc > 5 && !RXNULLSTRING(argv[5]) && RXSTRLEN(argv[5]) ) {
  1375.       clientctrls = getldapcontrols( &argv[5] );
  1376.       if ( !clientctrls ) {
  1377.          if ( freedn ) {
  1378.             free( dn );
  1379.          } /* endif */
  1380.          return ( CallingInvalid );
  1381.       } /* endif */
  1382.    } /* endif */
  1383.    code = ldap_compare_ext_s( ld, dn, RXSTRPTR(argv[2]), &bvalue, serverctrls, clientctrls );
  1384.    ldap_controls_free( serverctrls );
  1385.    ldap_controls_free( clientctrls );
  1386.    if ( freedn ) {
  1387.       free( dn );
  1388.    } /* endif */
  1389.    SetLdapCode( retstr, code );
  1390.    return ( CallingValid );
  1391. }   
  1392.           
  1393. ULONG _Export
  1394. Rxldap_compare_ext(
  1395. PUCHAR name, 
  1396. ULONG argc,
  1397. RXSTRING argv[],
  1398. PSZ queuename,
  1399. PRXSTRING retstr) {
  1400.    LDAP *ld = NULL;
  1401.    LDAPControl **serverctrls = NULL;
  1402.    LDAPControl **clientctrls = NULL;
  1403.    int code = 0;
  1404.    struct berval bvalue;
  1405.    RXSTRING value;
  1406.    int msgid = 0;
  1407.    unsigned char *dn = NULL;
  1408.    int freedn = 0;
  1409.    if ( argc != 7 ) {
  1410.       return ( CallingInvalid );
  1411.    } /* endif */
  1412.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[3]) || RXNULLSTRING(argv[6]) ) {
  1413.       return ( CallingInvalid );
  1414.    } /* endif */
  1415.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[6]) ) {
  1416.       return ( CallingInvalid );
  1417.    } /* endif */
  1418.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1419.       return ( CallingInvalid );
  1420.    } /* endif */
  1421.    ld = (LDAP *)rxtoul( argv[0] );
  1422.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1423.    if ( dn ) {
  1424.       freedn = 1;
  1425.    } else {
  1426.       dn = RXSTRPTR(argv[1]);
  1427.    } /* endif */
  1428.    bvalue.bv_val = RXSTRPTR(argv[3]);
  1429.    bvalue.bv_len = RXSTRLEN(argv[3]);
  1430.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1431.       serverctrls = getldapcontrols( &argv[4] );
  1432.       if ( !serverctrls ) {
  1433.          if ( freedn ) {
  1434.             free( dn );
  1435.          } /* endif */
  1436.          return ( CallingInvalid );
  1437.       } /* endif */
  1438.    } /* endif */
  1439.    if ( !RXNULLSTRING(argv[5]) && RXSTRLEN(argv[5]) ) {
  1440.       clientctrls = getldapcontrols( &argv[5] );
  1441.       if ( !clientctrls ) {
  1442.          if ( freedn ) {
  1443.             free( dn );
  1444.          } /* endif */
  1445.          return ( CallingInvalid );
  1446.       } /* endif */
  1447.    } /* endif */
  1448.    code = ldap_compare_ext( ld, dn, RXSTRPTR(argv[2]), &bvalue, serverctrls, clientctrls, &msgid );
  1449.    value = rxalloc( BUFSIZ );
  1450.    if ( RXNULLSTRING( value ) ) {
  1451.       if ( freedn ) {
  1452.          free( dn );
  1453.       } /* endif */
  1454.       return ( CallingInvalid );
  1455.    } /* endif */
  1456.    SetUnsignedInt2Rx( value, msgid );
  1457.    if ( setvalue( &argv[6], &value ) != Good ) {
  1458.       if ( freedn ) {
  1459.          free( dn );
  1460.       } /* endif */
  1461.       rxfree( value );
  1462.       return ( CallingInvalid );
  1463.    } /* endif */
  1464.    rxfree( value );
  1465.    ldap_controls_free( serverctrls );
  1466.    ldap_controls_free( clientctrls );
  1467.    if ( freedn ) {
  1468.       free( dn );
  1469.    } /* endif */
  1470.    SetLdapCode( retstr, code );
  1471.    return ( CallingValid );
  1472. }   
  1473.           
  1474. ULONG _Export
  1475. Rxldap_delete(
  1476. PUCHAR name, 
  1477. ULONG argc,
  1478. RXSTRING argv[],
  1479. PSZ queuename,
  1480. PRXSTRING retstr) {
  1481.    LDAP *ld = NULL;
  1482.    int code = 0;
  1483.    unsigned char *dn = NULL;
  1484.    int freedn = 0;
  1485.    if ( argc != 2 ) {
  1486.       return ( CallingInvalid );
  1487.    } /* endif */
  1488.    if ( RXNULLSTRING(argv[1]) ) {
  1489.       return ( CallingInvalid );
  1490.    } /* endif */
  1491.    if ( !RXSTRLEN(argv[1]) ) {
  1492.       return ( CallingInvalid );
  1493.    } /* endif */
  1494.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1495.       return ( CallingInvalid );
  1496.    } /* endif */
  1497.    ld = (LDAP *)rxtoul( argv[0] );
  1498.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1499.    if ( dn ) {
  1500.       freedn = 1;
  1501.    } else {
  1502.       dn = RXSTRPTR(argv[1]);
  1503.    } /* endif */
  1504.    code = ldap_delete( ld, dn );
  1505.    if ( freedn ) {
  1506.       free( dn );
  1507.    } /* endif */
  1508.    SetSignedInt2Rx( *retstr, code );
  1509.    return ( CallingValid );
  1510. }   
  1511.  
  1512. ULONG _Export
  1513. Rxldap_delete_s(
  1514. PUCHAR name, 
  1515. ULONG argc,
  1516. RXSTRING argv[],
  1517. PSZ queuename,
  1518. PRXSTRING retstr) {
  1519.    LDAP *ld = NULL;
  1520.    int code = 0;
  1521.    unsigned char *dn = NULL;
  1522.    int freedn = 0;
  1523.    if ( argc != 2 ) {
  1524.       return ( CallingInvalid );
  1525.    } /* endif */
  1526.    if ( RXNULLSTRING(argv[1]) ) {
  1527.       return ( CallingInvalid );
  1528.    } /* endif */
  1529.    if ( !RXSTRLEN(argv[1]) ) {
  1530.       return ( CallingInvalid );
  1531.    } /* endif */
  1532.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1533.       return ( CallingInvalid );
  1534.    } /* endif */
  1535.    ld = (LDAP *)rxtoul( argv[0] );
  1536.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1537.    if ( dn ) {
  1538.       freedn = 1;
  1539.    } else {
  1540.       dn = RXSTRPTR(argv[1]);
  1541.    } /* endif */
  1542.    code = ldap_delete_s( ld, dn );
  1543.    if ( freedn ) {
  1544.       free( dn );
  1545.    } /* endif */
  1546.    SetLdapCode( retstr, code );
  1547.    return ( CallingValid );
  1548. }   
  1549.  
  1550. ULONG _Export
  1551. Rxldap_delete_ext_s(
  1552. PUCHAR name, 
  1553. ULONG argc,
  1554. RXSTRING argv[],
  1555. PSZ queuename,
  1556. PRXSTRING retstr) {
  1557.    LDAP *ld = NULL;
  1558.    int code = 0;
  1559.    LDAPControl **serverctrls = NULL;
  1560.    LDAPControl **clientctrls = NULL;
  1561.    unsigned char *dn = NULL;
  1562.    int freedn = 0;
  1563.    if ( argc < 2 || argc > 4 ) {
  1564.       return ( CallingInvalid );
  1565.    } /* endif */
  1566.    if ( RXNULLSTRING(argv[1]) ) {
  1567.       return ( CallingInvalid );
  1568.    } /* endif */
  1569.    if ( !RXSTRLEN(argv[1]) ) {
  1570.       return ( CallingInvalid );
  1571.    } /* endif */
  1572.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1573.       return ( CallingInvalid );
  1574.    } /* endif */
  1575.    ld = (LDAP *)rxtoul( argv[0] );
  1576.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1577.    if ( dn ) {
  1578.       freedn = 1;
  1579.    } else {
  1580.       dn = RXSTRPTR(argv[1]);
  1581.    } /* endif */
  1582.    if ( argc > 2 && !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  1583.       serverctrls = getldapcontrols( &argv[2] );
  1584.       if ( !serverctrls ) {
  1585.          return ( CallingInvalid );
  1586.       } /* endif */
  1587.    } /* endif */
  1588.    if ( argc > 3 && !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  1589.       clientctrls = getldapcontrols( &argv[3] );
  1590.       if ( !clientctrls ) {
  1591.          return ( CallingInvalid );
  1592.       } /* endif */
  1593.    } /* endif */
  1594.    code = ldap_delete_ext_s( ld, dn, serverctrls, clientctrls );
  1595.    if ( freedn ) {
  1596.       free( dn );
  1597.    } /* endif */
  1598.    SetLdapCode( retstr, code );
  1599.    return ( CallingValid );
  1600. }   
  1601.  
  1602. ULONG _Export
  1603. Rxldap_delete_ext(
  1604. PUCHAR name, 
  1605. ULONG argc,
  1606. RXSTRING argv[],
  1607. PSZ queuename,
  1608. PRXSTRING retstr) {
  1609.    LDAP *ld = NULL;
  1610.    int code = 0;
  1611.    LDAPControl **serverctrls = NULL;
  1612.    LDAPControl **clientctrls = NULL;
  1613.    int msgid = 0;
  1614.    RXSTRING value;
  1615.    unsigned char *dn = NULL;
  1616.    int freedn = 0;
  1617.    if ( argc != 5 ) {
  1618.       return ( CallingInvalid );
  1619.    } /* endif */
  1620.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[4]) ) {
  1621.       return ( CallingInvalid );
  1622.    } /* endif */
  1623.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[4]) ) {
  1624.       return ( CallingInvalid );
  1625.    } /* endif */
  1626.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  1627.       return ( CallingInvalid );
  1628.    } /* endif */
  1629.    ld = (LDAP *)rxtoul( argv[0] );
  1630.    dn = strtoutf8( RXSTRPTR(argv[1]) );
  1631.    if ( dn ) {
  1632.       freedn = 1;
  1633.    } else {
  1634.       dn = RXSTRPTR(argv[1]);
  1635.    } /* endif */
  1636.    if ( !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  1637.       serverctrls = getldapcontrols( &argv[2] );
  1638.       if ( !serverctrls ) {
  1639.          if ( freedn ) {
  1640.             free( dn );
  1641.          } /* endif */
  1642.          return ( CallingInvalid );
  1643.       } /* endif */
  1644.    } /* endif */
  1645.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  1646.       clientctrls = getldapcontrols( &argv[3] );
  1647.       if ( !clientctrls ) {
  1648.          if ( freedn ) {
  1649.             free( dn );
  1650.          } /* endif */
  1651.          return ( CallingInvalid );
  1652.       } /* endif */
  1653.    } /* endif */
  1654.    code = ldap_delete_ext( ld, dn, serverctrls, clientctrls, &msgid );
  1655.    value = rxalloc( BUFSIZ );
  1656.    if ( RXNULLSTRING( value ) ) {
  1657.       if ( freedn ) {
  1658.          free( dn );
  1659.       } /* endif */
  1660.       return ( CallingInvalid );
  1661.    } /* endif */
  1662.    SetUnsignedInt2Rx( value, msgid );
  1663.    if ( setvalue( &argv[4], &value ) != Good ) {
  1664.       if ( freedn ) {
  1665.          free( dn );
  1666.       } /* endif */
  1667.       rxfree( value );
  1668.       return ( CallingInvalid );
  1669.    } /* endif */
  1670.    rxfree( value );
  1671.    ldap_controls_free( serverctrls );
  1672.    ldap_controls_free( clientctrls );
  1673.    if ( freedn ) {
  1674.       free( dn );
  1675.    } /* endif */
  1676.    SetLdapCode( retstr, code );
  1677.    return ( CallingValid );
  1678. }   
  1679.  
  1680. ULONG 
  1681. Rxldap_search_s(
  1682. PUCHAR name, 
  1683. ULONG argc,
  1684. RXSTRING argv[],
  1685. PSZ queuename,
  1686. PRXSTRING retstr) {
  1687.    LDAP *ld = NULL;
  1688.    int scope = 0;
  1689.    int attrsonly = 0;
  1690.    LDAPMessage *msg = NULL;
  1691.    int code = 0;
  1692.    char **attrs = NULL;
  1693.    Name2Int *v = NULL;
  1694.    RXSTRING value;
  1695.    unsigned char *basedn = NULL;
  1696.    unsigned char *filter = NULL;
  1697.    int freebasedn = 0;
  1698.    int freefilter = 0;
  1699.    if ( argc != 7 ) {
  1700.       return ( CallingInvalid );
  1701.    } /* endif */
  1702.    if ( RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[6]) ) {
  1703.       return ( CallingInvalid );
  1704.    } /* endif */
  1705.    if ( !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[6]) ) {
  1706.       return ( CallingInvalid );
  1707.    } /* endif */
  1708.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[5])) ) {
  1709.       return ( CallingInvalid );
  1710.    } /* endif */
  1711.    ld = (LDAP*)rxtoul( argv[0] );
  1712.    basedn = strtoutf8( RXSTRPTR(argv[1]) );
  1713.    if ( basedn ) {
  1714.       freebasedn = 1;
  1715.    } else {
  1716.       basedn = RXSTRPTR(argv[1]);
  1717.    } /* endif */
  1718.    v = findintfromname( RXSTRPTR(argv[2]), ScopeNames, sizeof(ScopeNames) / sizeof(Name2Int), 0 );
  1719.    if ( !v ) {
  1720.       return ( CallingInvalid );
  1721.    } /* endif */
  1722.    scope = v->intval;
  1723.    filter = strtoutf8( RXSTRPTR(argv[3]) );
  1724.    if ( filter ) {
  1725.       freefilter = 1;
  1726.    } else {
  1727.       filter = RXSTRPTR(argv[3]);
  1728.    } /* endif */
  1729.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1730.       attrs = getldapattrs( &argv[4] );
  1731.       if ( !attrs ) {
  1732.          return ( CallingInvalid );
  1733.       } /* endif */
  1734.    } /* endif */
  1735.    attrsonly = rxtoi( argv[5] );
  1736.    code = ldap_search_s( ld, basedn, scope, filter, attrs, attrsonly, &msg );
  1737.    freestrs( attrs );
  1738.    if ( freebasedn ) {
  1739.       free( basedn );
  1740.    } /* endif */
  1741.    if ( freefilter ) {
  1742.       free( filter );
  1743.    } /* endif */
  1744.    value = rxalloc( BUFSIZ );
  1745.    if ( RXNULLSTRING( value ) ) {
  1746.       return ( CallingInvalid );
  1747.    } /* endif */
  1748.    SetUnsignedInt2Rx( value, msg );
  1749.    if ( setvalue( &argv[6], &value ) != Good ) {
  1750.       rxfree( value );
  1751.       return ( CallingInvalid );
  1752.    } /* endif */
  1753.    rxfree( value );
  1754.    SetLdapCode( retstr, code );
  1755.    return ( CallingValid );
  1756. }
  1757.  
  1758. ULONG 
  1759. Rxldap_search_st(
  1760. PUCHAR name, 
  1761. ULONG argc,
  1762. RXSTRING argv[],
  1763. PSZ queuename,
  1764. PRXSTRING retstr) {
  1765.    LDAP *ld = NULL;
  1766.    int scope = 0;
  1767.    int attrsonly = 0;
  1768.    LDAPMessage *msg = NULL;
  1769.    int code = 0;
  1770.    RXSTRING value;
  1771.    Name2Int *v = NULL;
  1772.    char **attrs = NULL;
  1773.    struct timeval timeout;
  1774.    unsigned char *basedn = NULL;
  1775.    unsigned char *filter = NULL;
  1776.    int freebasedn = 0;
  1777.    int freefilter = 0;
  1778.    if ( argc != 8 ) {
  1779.       return ( CallingInvalid );
  1780.    } /* endif */
  1781.    if ( RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[6]) || RXNULLSTRING(argv[7])) {
  1782.       return ( CallingInvalid );
  1783.    } /* endif */
  1784.    if ( !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[6]) || !RXSTRLEN(argv[7])) {
  1785.       return ( CallingInvalid );
  1786.    } /* endif */
  1787.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[5])) ) {
  1788.       return ( CallingInvalid );
  1789.    } /* endif */
  1790.    ld = (LDAP*)rxtoul( argv[0] );
  1791.    basedn = strtoutf8( RXSTRPTR(argv[1]) );
  1792.    if ( basedn ) {
  1793.       freebasedn = 1;
  1794.    } else {
  1795.       basedn = RXSTRPTR(argv[1]);
  1796.    } /* endif */
  1797.    v = findintfromname( RXSTRPTR(argv[2]), ScopeNames, sizeof(ScopeNames) / sizeof(Name2Int), 0 );
  1798.    if ( !v ) {
  1799.       return ( CallingInvalid );
  1800.    } /* endif */
  1801.    scope = v->intval;
  1802.    filter = strtoutf8( RXSTRPTR(argv[3]) );
  1803.    if ( filter ) {
  1804.       freefilter = 1;
  1805.    } else {
  1806.       filter = RXSTRPTR(argv[3]);
  1807.    } /* endif */
  1808.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1809.       attrs = getldapattrs( &argv[4] );
  1810.       if ( !attrs ) {
  1811.          return ( CallingInvalid );
  1812.       } /* endif */
  1813.    } /* endif */
  1814.    attrsonly = rxtoi( argv[5] );
  1815.    if ( parsetimeval( &argv[6], &timeout ) != Good ) {
  1816.       freestrs( attrs );
  1817.       return ( CallingInvalid );
  1818.    } /* endif */
  1819.    code = ldap_search_st( ld, basedn, scope, filter, attrs, attrsonly, &timeout, &msg );
  1820.    freestrs( attrs );
  1821.    if ( freebasedn ) {
  1822.       free( basedn );
  1823.    } /* endif */
  1824.    if ( freefilter ) {
  1825.       free( filter );
  1826.    } /* endif */
  1827.    value = rxalloc( BUFSIZ );
  1828.    if ( RXNULLSTRING( value ) ) {
  1829.       return ( CallingInvalid );
  1830.    } /* endif */
  1831.    SetUnsignedInt2Rx( value, msg );
  1832.    if ( setvalue( &argv[7], &value ) != Good ) {
  1833.       rxfree( value );
  1834.       return ( CallingInvalid );
  1835.    } /* endif */
  1836.    rxfree( value );
  1837.    SetLdapCode( retstr, code );
  1838.    return ( CallingValid );
  1839. }
  1840.  
  1841. ULONG 
  1842. Rxldap_search(
  1843. PUCHAR name, 
  1844. ULONG argc,
  1845. RXSTRING argv[],
  1846. PSZ queuename,
  1847. PRXSTRING retstr) {
  1848.    LDAP *ld = NULL;
  1849.    int scope = 0;
  1850.    int attrsonly = 0;
  1851.    int code = 0;
  1852.    RXSTRING value;
  1853.    Name2Int *v = NULL;
  1854.    char **attrs = NULL;
  1855.    unsigned char *basedn = NULL;
  1856.    unsigned char *filter = NULL;
  1857.    int freebasedn = 0;
  1858.    int freefilter = 0;
  1859.    if ( argc != 6 ) {
  1860.       return ( CallingInvalid );
  1861.    } /* endif */
  1862.    if ( RXNULLSTRING(argv[2]) ) {
  1863.       return ( CallingInvalid );
  1864.    } /* endif */
  1865.    if ( !RXSTRLEN(argv[2]) ) {
  1866.       return ( CallingInvalid );
  1867.    } /* endif */
  1868.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[5])) ) {
  1869.       return ( CallingInvalid );
  1870.    } /* endif */
  1871.    ld = (LDAP*)rxtoul( argv[0] );
  1872.    basedn = strtoutf8( RXSTRPTR(argv[1]) );
  1873.    if ( basedn ) {
  1874.       freebasedn = 1;
  1875.    } else {
  1876.       basedn = RXSTRPTR(argv[1]);
  1877.    } /* endif */
  1878.    v = findintfromname( RXSTRPTR(argv[2]), ScopeNames, sizeof(ScopeNames) / sizeof(Name2Int), 0 );
  1879.    if ( !v ) {
  1880.       return ( CallingInvalid );
  1881.    } /* endif */
  1882.    scope = v->intval;
  1883.    filter = strtoutf8( RXSTRPTR(argv[3]) );
  1884.    if ( filter ) {
  1885.       freefilter = 1;
  1886.    } else {
  1887.       filter = RXSTRPTR(argv[3]);
  1888.    } /* endif */
  1889.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1890.       attrs = getldapattrs( &argv[4] );
  1891.       if ( !attrs ) {
  1892.          return ( CallingInvalid );
  1893.       } /* endif */
  1894.    } /* endif */
  1895.    attrsonly = rxtoi( argv[5] );
  1896.    code = ldap_search( ld, basedn, scope, filter, attrs, attrsonly );
  1897.    freestrs( attrs );
  1898.    if ( freebasedn ) {
  1899.       free( basedn );
  1900.    } /* endif */
  1901.    if ( freefilter ) {
  1902.       free( filter );
  1903.    } /* endif */
  1904.    SetSignedInt2Rx( *retstr, code );
  1905.    return ( CallingValid );
  1906. }
  1907.  
  1908. ULONG 
  1909. Rxldap_search_ext(
  1910. PUCHAR name, 
  1911. ULONG argc,
  1912. RXSTRING argv[],
  1913. PSZ queuename,
  1914. PRXSTRING retstr) {
  1915.    LDAP *ld = NULL;
  1916.    int scope = 0;
  1917.    int attrsonly = 0;
  1918.    int code = 0;
  1919.    RXSTRING value;
  1920.    Name2Int *v = NULL;
  1921.    char **attrs = NULL;
  1922.    LDAPControl **serverctrls = NULL;
  1923.    LDAPControl **clientctrls = NULL;
  1924.    struct timeval timeout;
  1925.    int sizelimit = 0;
  1926.    int msgid = 0;
  1927.    unsigned char *basedn = NULL;
  1928.    unsigned char *filter = NULL;
  1929.    int freebasedn = 0;
  1930.    int freefilter = 0;
  1931.    if ( argc != 11 ) {
  1932.       return ( CallingInvalid );
  1933.    } /* endif */
  1934.    if ( RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[9]) || RXNULLSTRING(argv[10]) ) {
  1935.       return ( CallingInvalid );
  1936.    } /* endif */
  1937.    if ( !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[9]) || !RXSTRLEN(argv[10]) ) {
  1938.       return ( CallingInvalid );
  1939.    } /* endif */
  1940.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[5])) || !isnumstr(RXSTRPTR(argv[9])) ) {
  1941.       return ( CallingInvalid );
  1942.    } /* endif */
  1943.    ld = (LDAP*)rxtoul( argv[0] );
  1944.    basedn = strtoutf8( RXSTRPTR(argv[1]) );
  1945.    if ( basedn ) {
  1946.       freebasedn = 1;
  1947.    } else {
  1948.       basedn = RXSTRPTR(argv[1]);
  1949.    } /* endif */
  1950.    v = findintfromname( RXSTRPTR(argv[2]), ScopeNames, sizeof(ScopeNames) / sizeof(Name2Int), 0 );
  1951.    if ( !v ) {
  1952.       if ( freebasedn ) {
  1953.          free( basedn );
  1954.       } /* endif */
  1955.       return ( CallingInvalid );
  1956.    } /* endif */
  1957.    scope = v->intval;
  1958.    filter = strtoutf8( RXSTRPTR(argv[3]) );
  1959.    if ( filter ) {
  1960.       freefilter = 1;
  1961.    } else {
  1962.       filter = RXSTRPTR(argv[3]);
  1963.    } /* endif */
  1964.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  1965.       attrs = getldapattrs( &argv[4] );
  1966.       if ( !attrs ) {
  1967.          if ( freebasedn ) {
  1968.             free( basedn );
  1969.          } /* endif */
  1970.          if ( freefilter ) {
  1971.             free( filter );
  1972.          } /* endif */
  1973.          return ( CallingInvalid );
  1974.       } /* endif */
  1975.    } /* endif */
  1976.    attrsonly = rxtoi( argv[5] );
  1977.    if ( !RXNULLSTRING(argv[6]) && RXSTRLEN(argv[6]) ) {
  1978.       serverctrls = getldapcontrols( &argv[6] );
  1979.       if ( !serverctrls ) {
  1980.          if ( freebasedn ) {
  1981.             free( basedn );
  1982.          } /* endif */
  1983.          if ( freefilter ) {
  1984.             free( filter );
  1985.          } /* endif */
  1986.          freestrs( attrs );
  1987.          return ( CallingInvalid );
  1988.       } /* endif */
  1989.    } /* endif */
  1990.    if ( !RXNULLSTRING(argv[7]) && RXSTRLEN(argv[7]) ) {
  1991.       clientctrls = getldapcontrols( &argv[7] );
  1992.       if ( !clientctrls ) {
  1993.          ldap_controls_free( serverctrls );
  1994.          if ( freebasedn ) {
  1995.             free( basedn );
  1996.          } /* endif */
  1997.          if ( freefilter ) {
  1998.             free( filter );
  1999.          } /* endif */
  2000.          freestrs( attrs );
  2001.          return ( CallingInvalid );
  2002.       } /* endif */
  2003.    } /* endif */
  2004.    if ( parsetimeval( &argv[8], &timeout ) != Good ) {
  2005.       ldap_controls_free( serverctrls );
  2006.       ldap_controls_free( clientctrls );
  2007.       if ( freebasedn ) {
  2008.          free( basedn );
  2009.       } /* endif */
  2010.       if ( freefilter ) {
  2011.          free( filter );
  2012.       } /* endif */
  2013.       freestrs( attrs );
  2014.       return ( CallingInvalid );
  2015.    } /* endif */
  2016.    sizelimit = rxtoi( argv[9] );
  2017.    code = ldap_search_ext( ld, basedn, scope, filter, attrs, attrsonly, serverctrls, clientctrls, &timeout, sizelimit, &msgid );
  2018.    freestrs( attrs );
  2019.    if ( freebasedn ) {
  2020.       free( basedn );
  2021.    } /* endif */
  2022.    if ( freefilter ) {
  2023.       free( filter );
  2024.    } /* endif */
  2025.    ldap_controls_free( serverctrls );
  2026.    ldap_controls_free( clientctrls );
  2027.    value = rxalloc( BUFSIZ );
  2028.    if ( RXNULLSTRING( value ) ) {
  2029.       return ( CallingInvalid );
  2030.    } /* endif */
  2031.    SetUnsignedInt2Rx( value, msgid );
  2032.    if ( setvalue( &argv[10], &value ) != Good ) {
  2033.       rxfree( value );
  2034.       return ( CallingInvalid );
  2035.    } /* endif */
  2036.    rxfree( value );
  2037.    SetLdapCode( retstr, code );
  2038.    return ( CallingValid );
  2039. }
  2040.  
  2041. ULONG 
  2042. Rxldap_search_ext_s(
  2043. PUCHAR name, 
  2044. ULONG argc,
  2045. RXSTRING argv[],
  2046. PSZ queuename,
  2047. PRXSTRING retstr) {
  2048.    LDAP *ld = NULL;
  2049.    int scope = 0;
  2050.    int attrsonly = 0;
  2051.    int code = 0;
  2052.    RXSTRING value;
  2053.    Name2Int *v = NULL;
  2054.    char **attrs = NULL;
  2055.    LDAPControl **serverctrls = NULL;
  2056.    LDAPControl **clientctrls = NULL;
  2057.    struct timeval timeout;
  2058.    int sizelimit = 0;
  2059.    LDAPMessage *msg = NULL;
  2060.    unsigned char *basedn = NULL;
  2061.    unsigned char *filter = NULL;
  2062.    int freebasedn = 0;
  2063.    int freefilter = 0;
  2064.    if ( argc != 11 ) {
  2065.       return ( CallingInvalid );
  2066.    } /* endif */
  2067.    if ( RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[9]) || RXNULLSTRING(argv[10]) ) {
  2068.       return ( CallingInvalid );
  2069.    } /* endif */
  2070.    if ( !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[9]) || !RXSTRLEN(argv[10]) ) {
  2071.       return ( CallingInvalid );
  2072.    } /* endif */
  2073.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[5])) || !isnumstr(RXSTRPTR(argv[9])) ) {
  2074.       return ( CallingInvalid );
  2075.    } /* endif */
  2076.    ld = (LDAP*)rxtoul( argv[0] );
  2077.    basedn = strtoutf8( RXSTRPTR(argv[1]) );
  2078.    if ( basedn ) {
  2079.       freebasedn = 1;
  2080.    } else {
  2081.       basedn = RXSTRPTR(argv[1]);
  2082.    } /* endif */
  2083.    v = findintfromname( RXSTRPTR(argv[2]), ScopeNames, sizeof(ScopeNames) / sizeof(Name2Int), 0 );
  2084.    if ( !v ) {
  2085.       if ( freebasedn ) {
  2086.          free( basedn );
  2087.       } /* endif */
  2088.       return ( CallingInvalid );
  2089.    } /* endif */
  2090.    scope = v->intval;
  2091.    filter = strtoutf8( RXSTRPTR(argv[3]) );
  2092.    if ( filter ) {
  2093.       freefilter = 1;
  2094.    } else {
  2095.       filter = RXSTRPTR(argv[3]);
  2096.    } /* endif */
  2097.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  2098.       attrs = getldapattrs( &argv[4] );
  2099.       if ( !attrs ) {
  2100.          if ( freebasedn ) {
  2101.             free( basedn );
  2102.          } /* endif */
  2103.          if ( freefilter ) {
  2104.             free( filter );
  2105.          } /* endif */
  2106.          return ( CallingInvalid );
  2107.       } /* endif */
  2108.    } /* endif */
  2109.    attrsonly = rxtoi( argv[5] );
  2110.    if ( !RXNULLSTRING(argv[6]) && RXSTRLEN(argv[6]) ) {
  2111.       serverctrls = getldapcontrols( &argv[6] );
  2112.       if ( !serverctrls ) {
  2113.          if ( freebasedn ) {
  2114.             free( basedn );
  2115.          } /* endif */
  2116.          if ( freefilter ) {
  2117.             free( filter );
  2118.          } /* endif */
  2119.          freestrs( attrs );
  2120.          return ( CallingInvalid );
  2121.       } /* endif */
  2122.    } /* endif */
  2123.    if ( !RXNULLSTRING(argv[7]) && RXSTRLEN(argv[7]) ) {
  2124.       clientctrls = getldapcontrols( &argv[7] );
  2125.       if ( !clientctrls ) {
  2126.          ldap_controls_free( serverctrls );
  2127.          if ( freebasedn ) {
  2128.             free( basedn );
  2129.          } /* endif */
  2130.          if ( freefilter ) {
  2131.             free( filter );
  2132.          } /* endif */
  2133.          freestrs( attrs );
  2134.          return ( CallingInvalid );
  2135.       } /* endif */
  2136.    } /* endif */
  2137.    if ( parsetimeval( &argv[8], &timeout ) != Good ) {
  2138.       ldap_controls_free( serverctrls );
  2139.       if ( freebasedn ) {
  2140.          free( basedn );
  2141.       } /* endif */
  2142.       if ( freefilter ) {
  2143.          free( filter );
  2144.       } /* endif */
  2145.       freestrs( attrs );
  2146.       return ( CallingInvalid );
  2147.    } /* endif */
  2148.    sizelimit = rxtoi( argv[9] );
  2149.    code = ldap_search_ext_s( ld, basedn, scope, filter, attrs, attrsonly, serverctrls, clientctrls, &timeout, sizelimit, &msg );
  2150.    freestrs( attrs );
  2151.    if ( freebasedn ) {
  2152.       free( basedn );
  2153.    } /* endif */
  2154.    if ( freefilter ) {
  2155.       free( filter );
  2156.    } /* endif */
  2157.    ldap_controls_free( serverctrls );
  2158.    ldap_controls_free( clientctrls );
  2159.    value = rxalloc( BUFSIZ );
  2160.    if ( RXNULLSTRING( value ) ) {
  2161.       return ( CallingInvalid );
  2162.    } /* endif */
  2163.    SetUnsignedInt2Rx( value, msg );
  2164.    if ( setvalue( &argv[10], &value ) != Good ) {
  2165.       rxfree( value );
  2166.       return ( CallingInvalid );
  2167.    } /* endif */
  2168.    rxfree( value );
  2169.    SetLdapCode( retstr, code );
  2170.    return ( CallingValid );
  2171. }
  2172.  
  2173. ULONG 
  2174. Rxldap_is_ldap_url(
  2175. PUCHAR name, 
  2176. ULONG argc,
  2177. RXSTRING argv[],
  2178. PSZ queuename,
  2179. PRXSTRING retstr) {
  2180.    int code = 0;
  2181.    if ( argc != 1 ) {
  2182.       return ( CallingInvalid );
  2183.    } /* endif */
  2184.    if ( RXNULLSTRING(argv[0]) ) {
  2185.       return ( CallingInvalid );
  2186.    } /* endif */
  2187.    if ( !RXSTRLEN(argv[0]) ) {
  2188.       return ( CallingInvalid );
  2189.    } /* endif */
  2190.    code = ldap_is_ldap_url( RXSTRPTR(argv[0]) );
  2191.    SetSignedInt2Rx( *retstr, code );
  2192.    return ( CallingValid );
  2193. }
  2194.  
  2195. ULONG 
  2196. Rxldap_url_parse(
  2197. PUCHAR name, 
  2198. ULONG argc,
  2199. RXSTRING argv[],
  2200. PSZ queuename,
  2201. PRXSTRING retstr) {
  2202.    int code = 0;
  2203.    LDAPURLDesc *desc = NULL;
  2204.    if ( argc != 2 ) {
  2205.       return ( CallingInvalid );
  2206.    } /* endif */
  2207.    if ( RXNULLSTRING(argv[0]) || RXNULLSTRING(argv[1]) ) {
  2208.       return ( CallingInvalid );
  2209.    } /* endif */
  2210.    if ( !RXSTRLEN(argv[0]) || !RXSTRLEN(argv[1]) ) {
  2211.       return ( CallingInvalid );
  2212.    } /* endif */
  2213.    code = ldap_url_parse( RXSTRPTR(argv[0]), &desc );
  2214.    if ( !code ) {
  2215.       RXSTRING varname;
  2216.       RXSTRING stem;
  2217.       RXSTRING value;
  2218.       RXSTRING t;
  2219.       varname = rxalloc( RXSTRLEN(argv[1]) + BUFSIZ );
  2220.       if ( RXNULLSTRING( varname ) ) {
  2221.          ldap_free_urldesc( desc );
  2222.          return ( CallingInvalid );
  2223.       } /* endif */
  2224.       stem = rxalloc( RXSTRLEN(argv[1]) + BUFSIZ );
  2225.       if ( RXNULLSTRING( stem ) ) {
  2226.          rxfree( varname );
  2227.          ldap_free_urldesc( desc );
  2228.          return ( CallingInvalid );
  2229.       } /* endif */
  2230.       rxstrcpy( &stem, &argv[1] );
  2231.       if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  2232.          rxappendstr( &stem, "." );
  2233.       } /* endif */
  2234.       rxappendstr( &stem, "!" );
  2235.       value = rxalloc( BUFSIZ );
  2236.       if ( RXNULLSTRING( value ) ) {
  2237.          rxfree( varname );
  2238.          rxfree( stem );
  2239.          ldap_free_urldesc( desc );
  2240.          return ( CallingInvalid );
  2241.       } /* endif */
  2242.       rxstrcpy( &varname, &stem );
  2243.       rxappendstr( &varname, "LUD_HOST" );
  2244.       MAKERXSTRING( t, desc->lud_host, strlen( desc->lud_host ) );
  2245.       if ( setvalue( &varname, &t ) != Good ) {
  2246.          rxfree( varname );
  2247.          rxfree( stem );
  2248.          rxfree( value );
  2249.          ldap_free_urldesc( desc );
  2250.          return ( CallingInvalid );
  2251.       } /* endif */
  2252.       rxstrcpy( &varname, &stem );
  2253.       rxappendstr( &varname, "LUD_PORT" );
  2254.       rxset_length( &value, strlen( _ltoa( desc->lud_port, RXSTRPTR(value), 10 ) ) );
  2255.       if ( setvalue( &varname, &value ) != Good ) {
  2256.          rxfree( varname );
  2257.          rxfree( stem );
  2258.          rxfree( value );
  2259.          ldap_free_urldesc( desc );
  2260.          return ( CallingInvalid );
  2261.       } /* endif */
  2262.       setcodename( &value, desc->lud_scope, ScopeNames, sizeof(ScopeNames) / sizeof(Name2Int), 0 );
  2263.       rxstrcpy( &varname, &stem );
  2264.       rxappendstr( &varname, "LUD_SCOPE" );
  2265.       if ( setvalue( &varname, &value ) != Good ) {
  2266.          rxfree( varname );
  2267.          rxfree( stem );
  2268.          rxfree( value );
  2269.          ldap_free_urldesc( desc );
  2270.          return ( CallingInvalid );
  2271.       } /* endif */
  2272.       rxstrcpy( &varname, &stem );
  2273.       rxappendstr( &varname, "LUD_DN" );
  2274.       MAKERXSTRING( t, desc->lud_dn, strlen( desc->lud_dn ) );
  2275.       if ( setvalue( &varname, &t ) != Good ) {
  2276.          rxfree( varname );
  2277.          rxfree( stem );
  2278.          rxfree( value );
  2279.          ldap_free_urldesc( desc );
  2280.          return ( CallingInvalid );
  2281.       } /* endif */
  2282.       rxstrcpy( &varname, &stem );
  2283.       rxappendstr( &varname, "LUD_FILTER" );
  2284.       MAKERXSTRING( t, desc->lud_filter, strlen( desc->lud_filter ) );
  2285.       if ( setvalue( &varname, &t ) != Good ) {
  2286.          rxfree( varname );
  2287.          rxfree( stem );
  2288.          rxfree( value );
  2289.          ldap_free_urldesc( desc );
  2290.          return ( CallingInvalid );
  2291.       } /* endif */
  2292.       rxstrcpy( &varname, &stem );
  2293.       rxappendstr( &varname, "LUD_ATTRS." );
  2294.       if ( setstrs( &varname, desc->lud_attrs, 0 ) < 0 ) {
  2295.          rxfree( varname );
  2296.          rxfree( stem );
  2297.          rxfree( value );
  2298.          return ( CallingInvalid );
  2299.       } /* endif */
  2300.       rxfree( varname );
  2301.       rxfree( stem );
  2302.       rxfree( value );
  2303.       ldap_free_urldesc( desc );
  2304.    } /* endif */
  2305.    SetLdapCode( retstr, code );
  2306.    return ( CallingValid );
  2307. }
  2308.  
  2309. ULONG 
  2310. Rxldap_url_search(
  2311. PUCHAR name, 
  2312. ULONG argc,
  2313. RXSTRING argv[],
  2314. PSZ queuename,
  2315. PRXSTRING retstr) {
  2316.    LDAP *ld = NULL;
  2317.    int attrsonly = 0;
  2318.    int code = 0;
  2319.    if ( argc < 2 || argc > 3 ) {
  2320.       return ( CallingInvalid );
  2321.    } /* endif */
  2322.    if ( RXNULLSTRING(argv[1]) ) {
  2323.       return ( CallingInvalid );
  2324.    } /* endif */
  2325.    if ( !RXSTRLEN(argv[1]) ) {
  2326.       return ( CallingInvalid );
  2327.    } /* endif */
  2328.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2329.       return ( CallingInvalid );
  2330.    } /* endif */
  2331.    ld = (LDAP*)rxtoul( argv[0] );
  2332.    if ( argc > 2 ) {
  2333.       if ( !isnumstr(RXSTRPTR(argv[2])) ) {
  2334.          return ( CallingInvalid );
  2335.       } /* endif */
  2336.       attrsonly = rxtoi( argv[2] );
  2337.    } /* endif */
  2338.    code = ldap_url_search( ld, RXSTRPTR(argv[1]), attrsonly );
  2339.    SetSignedInt2Rx( *retstr, code );
  2340.    return ( CallingValid );
  2341. }
  2342.  
  2343. ULONG 
  2344. Rxldap_url_search_s(
  2345. PUCHAR name, 
  2346. ULONG argc,
  2347. RXSTRING argv[],
  2348. PSZ queuename,
  2349. PRXSTRING retstr) {
  2350.    LDAP *ld = NULL;
  2351.    int attrsonly = 0;
  2352.    int code = 0;
  2353.    LDAPMessage *msg = NULL;
  2354.    RXSTRING value;
  2355.    if ( argc != 4 ) {
  2356.       return ( CallingInvalid );
  2357.    } /* endif */
  2358.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[3]) ) {
  2359.       return ( CallingInvalid );
  2360.    } /* endif */
  2361.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[3]) ) {
  2362.       return ( CallingInvalid );
  2363.    } /* endif */
  2364.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[2])) ) {
  2365.       return ( CallingInvalid );
  2366.    } /* endif */
  2367.    ld = (LDAP*)rxtoul( argv[0] );
  2368.    attrsonly = rxtoi( argv[2] );
  2369.    code = ldap_url_search_s( ld, RXSTRPTR(argv[1]), attrsonly, &msg );
  2370.    value = rxalloc( BUFSIZ );
  2371.    if ( RXNULLSTRING( value ) ) {
  2372.       return ( CallingInvalid );
  2373.    } /* endif */
  2374.    SetUnsignedInt2Rx( value, msg );
  2375.    if ( setvalue( &argv[3], &value ) != Good ) {
  2376.       rxfree( value );
  2377.       return ( CallingInvalid );
  2378.    } /* endif */
  2379.    rxfree( value );
  2380.    SetLdapCode( retstr, code );
  2381.    return ( CallingValid );
  2382. }
  2383.  
  2384. ULONG 
  2385. Rxldap_url_search_st(
  2386. PUCHAR name, 
  2387. ULONG argc,
  2388. RXSTRING argv[],
  2389. PSZ queuename,
  2390. PRXSTRING retstr) {
  2391.    LDAP *ld = NULL;
  2392.    int attrsonly = 0;
  2393.    int code = 0;
  2394.    LDAPMessage *msg = NULL;
  2395.    RXSTRING value;
  2396.    struct timeval timeout;
  2397.    if ( argc != 5 ) {
  2398.       return ( CallingInvalid );
  2399.    } /* endif */
  2400.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[3]) || RXNULLSTRING(argv[4]) ) {
  2401.       return ( CallingInvalid );
  2402.    } /* endif */
  2403.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[3]) || !RXSTRLEN(argv[4]) ) {
  2404.       return ( CallingInvalid );
  2405.    } /* endif */
  2406.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[2])) ) {
  2407.       return ( CallingInvalid );
  2408.    } /* endif */
  2409.    ld = (LDAP*)rxtoul( argv[0] );
  2410.    attrsonly = rxtoi( argv[2] );
  2411.    if ( parsetimeval( &argv[3], &timeout ) != Good ) {
  2412.       return ( CallingInvalid );
  2413.    } /* endif */
  2414.    code = ldap_url_search_st( ld, RXSTRPTR(argv[1]), attrsonly, &timeout, &msg );
  2415.    value = rxalloc( BUFSIZ );
  2416.    if ( RXNULLSTRING( value ) ) {
  2417.       return ( CallingInvalid );
  2418.    } /* endif */
  2419.    SetUnsignedInt2Rx( value, msg );
  2420.    if ( setvalue( &argv[4], &value ) != Good ) {
  2421.       rxfree( value );
  2422.       return ( CallingInvalid );
  2423.    } /* endif */
  2424.    rxfree( value );
  2425.    SetLdapCode( retstr, code );
  2426.    return ( CallingValid );
  2427. }
  2428.  
  2429. ULONG     
  2430. Rxldap_result(
  2431. PUCHAR name, 
  2432. ULONG argc,
  2433. RXSTRING argv[],
  2434. PSZ queuename,
  2435. PRXSTRING retstr) {
  2436.    LDAP *ld = NULL;
  2437.    int msgid = 0;
  2438.    int all = 0;
  2439.    LDAPMessage *msg = NULL;
  2440.    int code = 0;
  2441.    RXSTRING value;
  2442.    struct timeval timeout;
  2443.    struct timeval *timeoutp = NULL;
  2444.    Name2Int *v = NULL;
  2445.    if ( argc != 5 ) {
  2446.       return ( CallingInvalid );
  2447.    } /* endif */
  2448.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[4]) ) {
  2449.       return ( CallingInvalid );
  2450.    } /* endif */
  2451.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[4]) ) {
  2452.       return ( CallingInvalid );
  2453.    } /* endif */
  2454.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2455.       return ( CallingInvalid );
  2456.    } /* endif */
  2457.    ld = (LDAP*)rxtoul( argv[0] );
  2458.    v = findintfromname( RXSTRPTR(argv[1]), ResultTypes, sizeof(ResultTypes) / sizeof(Name2Int), 1 );
  2459.    if ( v ) {
  2460.       msgid = v->intval;
  2461.    } else if ( isnumstr(RXSTRPTR(argv[1])) ) {
  2462.       msgid = rxtoi( argv[1] );
  2463.    } else {
  2464.       return ( CallingInvalid );
  2465.    } /* endif */
  2466.    if ( !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  2467.       if ( isnumstr(RXSTRPTR(argv[2])) ) {
  2468.          all = rxtoi( argv[2] );
  2469.       } else {
  2470.          v = findintfromname( RXSTRPTR(argv[2]), ResAllNames, sizeof(ResAllNames) / sizeof(Name2Int), 0 );
  2471.          if ( !v ) {
  2472.             return ( CallingInvalid );
  2473.          } /* endif */
  2474.          all = v->intval;
  2475.       } /* endif */
  2476.    } /* endif */
  2477.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  2478.       if ( parsetimeval( &argv[3], &timeout ) != Good ) {
  2479.          return ( CallingInvalid );
  2480.       } /* endif */
  2481.       timeoutp = &timeout;
  2482.    } /* endif */
  2483.    code = ldap_result( ld, msgid, all, timeoutp, &msg );
  2484.    value = rxalloc( BUFSIZ );
  2485.    if ( RXNULLSTRING( value ) ) {
  2486.       return ( CallingInvalid );
  2487.    } /* endif */
  2488.    SetUnsignedInt2Rx( value, msg );
  2489.    if ( setvalue( &argv[4], &value ) != Good ) {
  2490.       rxfree( value );
  2491.       return ( CallingInvalid );
  2492.    } /* endif */
  2493.    rxfree( value );
  2494.    setcodename( retstr, code, ResultTypes, sizeof(ResultTypes) / sizeof(Name2Int), 0 );
  2495.    return ( CallingValid );
  2496. }
  2497.  
  2498. ULONG _Export
  2499. Rxldap_msgtype(
  2500. PUCHAR name, 
  2501. ULONG argc,
  2502. RXSTRING argv[],
  2503. PSZ queuename,
  2504. PRXSTRING retstr) {
  2505.    LDAPMessage *msg = NULL;
  2506.    int code = 0;
  2507.    if ( argc != 1 ) {
  2508.       return ( CallingInvalid );
  2509.    } /* endif */
  2510.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2511.       return ( CallingInvalid );
  2512.    } /* endif */
  2513.    msg = (LDAPMessage *)rxtoul( argv[0] );
  2514.    code = ldap_msgtype( msg );
  2515.    setcodename( retstr, code, ResultTypes, sizeof(ResultTypes) / sizeof(Name2Int), 0 );
  2516.    return ( CallingValid );
  2517. }   
  2518.  
  2519. ULONG _Export
  2520. Rxldap_msgid(
  2521. PUCHAR name, 
  2522. ULONG argc,
  2523. RXSTRING argv[],
  2524. PSZ queuename,
  2525. PRXSTRING retstr) {
  2526.    LDAPMessage *msg = NULL;
  2527.    int msgid = 0;
  2528.    int code = 0;
  2529.    if ( argc != 1 ) {
  2530.       return ( CallingInvalid );
  2531.    } /* endif */
  2532.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2533.       return ( CallingInvalid );
  2534.    } /* endif */
  2535.    msg = (LDAPMessage *)rxtoul( argv[0] );
  2536.    msgid = ldap_msgid( msg );
  2537.    SetUnsignedInt2Rx( *retstr, msgid );
  2538.    return ( CallingValid );
  2539. }   
  2540.  
  2541. ULONG     
  2542. Rxldap_get_option(
  2543. PUCHAR name, 
  2544. ULONG argc,
  2545. RXSTRING argv[],
  2546. PSZ queuename,
  2547. PRXSTRING retstr) {
  2548.    LDAP *ld = NULL;
  2549.    int code = 0;
  2550.    Name2Int *v = NULL;
  2551.    int opt = 0;
  2552.    void *optval = NULL;
  2553.    int intval = 0;
  2554.    char *strval = NULL;
  2555.    LDAPAPIInfo apiinfo;
  2556.    LDAPAPIFeatureInfo finfo;
  2557.    int i = 0;
  2558.    char *w = NULL;
  2559.    RXSTRING varname;
  2560.    RXSTRING stem;
  2561.    RXSTRING value;
  2562.    RXSTRING t;
  2563.    if ( argc != 3 ) {
  2564.       return ( CallingInvalid );
  2565.    } /* endif */
  2566.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  2567.       return ( CallingInvalid );
  2568.    } /* endif */
  2569.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  2570.       return ( CallingInvalid );
  2571.    } /* endif */
  2572.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2573.       return ( CallingInvalid );
  2574.    } /* endif */
  2575.    ld = (LDAP*)rxtoul( argv[0] );
  2576.    v = findintfromname( RXSTRPTR(argv[1]), LdapOptNames, sizeof(LdapOptNames) / sizeof(Name2Int), 0 );
  2577.    if ( !v ) {
  2578.       return ( CallingInvalid );
  2579.    } /* endif */
  2580.    opt = v->intval;
  2581.    switch ( opt ) {
  2582.    case LDAP_OPT_SIZELIMIT:
  2583.    case LDAP_OPT_TIMELIMIT:
  2584.    case LDAP_OPT_DEREF:   
  2585.    case LDAP_OPT_REFERRALS:   
  2586.    case LDAP_OPT_PROTOCOL_VERSION:
  2587.    case LDAP_OPT_ERROR_NUMBER:
  2588.       optval = &intval;
  2589.       break;
  2590.    case LDAP_OPT_HOST_NAME:
  2591.    case LDAP_OPT_ERROR_STRING:
  2592.    case LDAP_OPT_MATCHED_DN:
  2593.       optval = &strval;
  2594.       break;
  2595.    case LDAP_OPT_API_INFO:
  2596.       apiinfo.ldapai_info_version = LDAP_API_INFO_VERSION;
  2597.       apiinfo.ldapai_extensions = NULL;
  2598.       optval = &apiinfo;
  2599.       break;
  2600.    case LDAP_OPT_API_FEATURE_INFO:
  2601.       finfo.ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
  2602.       optval = &finfo;
  2603.       break;
  2604.    default:
  2605.      return ( CallingInvalid );
  2606.      break;
  2607.    } /* endswitch */
  2608.    if ( !optval ) {
  2609.       return ( CallingInvalid );
  2610.    } /* endif */
  2611.    code = ldap_get_option( ld, opt, optval );
  2612.    value = rxalloc( BUFSIZ );
  2613.    if ( RXNULLSTRING( value ) ) {
  2614.       return ( CallingInvalid );
  2615.    } /* endif */
  2616.    switch ( opt ) {
  2617.    case LDAP_OPT_SIZELIMIT:
  2618.    case LDAP_OPT_TIMELIMIT:
  2619.    case LDAP_OPT_PROTOCOL_VERSION:
  2620.    case LDAP_OPT_ERROR_NUMBER:
  2621.       SetUnsignedInt2Rx( value, intval );
  2622.       break;
  2623.    case LDAP_OPT_DEREF:   
  2624.       setcodename( &value, intval, LdapOptValDeref, sizeof(LdapOptValDeref) / sizeof(Name2Int), 1 );
  2625.       break;
  2626.    case LDAP_OPT_REFERRALS:   
  2627.       setcodename( &value, intval, LdapOptValOnOff, sizeof(LdapOptValOnOff) / sizeof(Name2Int), 1 );
  2628.       break;
  2629.    case LDAP_OPT_HOST_NAME:   
  2630.    case LDAP_OPT_ERROR_STRING:   
  2631.    case LDAP_OPT_MATCHED_DN:
  2632.       strcpy2rx( &value, strval );
  2633.       ldap_memfree( strval );
  2634.       break;
  2635.    case LDAP_OPT_API_INFO:
  2636.    case LDAP_OPT_API_FEATURE_INFO:
  2637.       varname = rxalloc( RXSTRLEN(argv[2]) + BUFSIZ );
  2638.       if ( RXNULLSTRING( varname ) ) {
  2639.          ldap_value_free( apiinfo.ldapai_extensions );
  2640.          rxfree( value );
  2641.          return ( CallingInvalid );
  2642.       } /* endif */
  2643.       stem = rxalloc( RXSTRLEN(argv[2]) + BUFSIZ );
  2644.       if ( RXNULLSTRING( stem ) ) {
  2645.          ldap_value_free( apiinfo.ldapai_extensions );
  2646.          rxfree( value );
  2647.          rxfree( varname );
  2648.          return ( CallingInvalid );
  2649.       } /* endif */
  2650.       value = rxalloc( BUFSIZ );
  2651.       if ( RXNULLSTRING( value ) ) {
  2652.          ldap_value_free( apiinfo.ldapai_extensions );
  2653.          rxfree( value );
  2654.          rxfree( varname );
  2655.          rxfree( stem );
  2656.          return ( CallingInvalid );
  2657.       } /* endif */
  2658.       rxstrcpy( &stem, &argv[2] );
  2659.       if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  2660.          rxappendstr( &stem, "." );
  2661.       } /* endif */
  2662.       rxappendstr( &stem, "!" );
  2663.       w = malloc( BUFSIZ );
  2664.       if ( !w ) {
  2665.          ldap_value_free( apiinfo.ldapai_extensions );
  2666.          rxfree( value );
  2667.          rxfree( varname );
  2668.          rxfree( stem );
  2669.       } /* endif */
  2670.       break;
  2671.    } /* endswitch */
  2672.    switch ( opt ) {
  2673.    case LDAP_OPT_SIZELIMIT:
  2674.    case LDAP_OPT_TIMELIMIT:
  2675.    case LDAP_OPT_PROTOCOL_VERSION:
  2676.    case LDAP_OPT_ERROR_NUMBER:
  2677.    case LDAP_OPT_DEREF:   
  2678.    case LDAP_OPT_REFERRALS:   
  2679.    case LDAP_OPT_HOST_NAME:   
  2680.    case LDAP_OPT_ERROR_STRING:   
  2681.    case LDAP_OPT_MATCHED_DN:
  2682.       if ( setvalue( &argv[2], &value ) != Good ) {
  2683.          rxfree( value );
  2684.          return ( CallingInvalid );
  2685.       } /* endif */
  2686.       rxfree( value );
  2687.       break;
  2688.    case LDAP_OPT_API_INFO:
  2689.       rxstrcpy( &varname, &stem );
  2690.       rxappendstr( &varname, "LDAPAI_VENDOR_VERSION" );
  2691.       rxset_length( &value, strlen( _ltoa( (ULONG)apiinfo.ldapai_vendor_version, RXSTRPTR(value), 10 ) ) );
  2692.       if ( setvalue( &varname, &value ) != Good ) {
  2693.          ldap_value_free( apiinfo.ldapai_extensions );
  2694.          rxfree( varname );
  2695.          rxfree( stem );
  2696.          rxfree( value );
  2697.          free( w );
  2698.          return ( CallingInvalid );
  2699.       } /* endif */
  2700.       rxstrcpy( &varname, &stem );
  2701.       rxappendstr( &varname, "LDAPAI_API_VERSION" );
  2702.       rxset_length( &value, strlen( _ltoa( (ULONG)apiinfo.ldapai_api_version, RXSTRPTR(value), 10 ) ) );
  2703.       if ( setvalue( &varname, &value ) != Good ) {
  2704.          ldap_value_free( apiinfo.ldapai_extensions );
  2705.          rxfree( varname );
  2706.          rxfree( stem );
  2707.          rxfree( value );
  2708.          free( w );
  2709.          return ( CallingInvalid );
  2710.       } /* endif */
  2711.       rxstrcpy( &varname, &stem );
  2712.       rxappendstr( &varname, "LDAPAI_PROTOCOL_VERSION" );
  2713.       rxset_length( &value, strlen( _ltoa( (ULONG)apiinfo.ldapai_protocol_version, RXSTRPTR(value), 10 ) ) );
  2714.       if ( setvalue( &varname, &value ) != Good ) {
  2715.          ldap_value_free( apiinfo.ldapai_extensions );
  2716.          rxfree( varname );
  2717.          rxfree( stem );
  2718.          rxfree( value );
  2719.          free( w );
  2720.          return ( CallingInvalid );
  2721.       } /* endif */
  2722.       rxstrcpy( &varname, &stem );
  2723.       rxappendstr( &varname, "LDAPAI_VENDOR_NAME" );
  2724.       MAKERXSTRING( t, apiinfo.ldapai_vendor_name, strlen(apiinfo.ldapai_vendor_name) );
  2725.       if ( setvalue( &varname, &t ) != Good ) {
  2726.          ldap_value_free( apiinfo.ldapai_extensions );
  2727.          rxfree( varname );
  2728.          rxfree( stem );
  2729.          rxfree( value );
  2730.          free( w );
  2731.          return ( CallingInvalid );
  2732.       } /* endif */
  2733.       if ( apiinfo.ldapai_extensions ) {
  2734.          for ( i = 0; apiinfo.ldapai_extensions[i]; i += 1) {
  2735.             rxstrcpy( &varname, &stem );
  2736.             rxappendstr( &varname, "LDAPAI_EXTENSIONS." );
  2737.             rxappendstr( &varname, _itoa(i + 1, w, 10) );
  2738.             MAKERXSTRING( t, apiinfo.ldapai_extensions[i], strlen(apiinfo.ldapai_extensions[i]) );
  2739.             if ( setvalue( &varname, &t ) != Good ) {
  2740.                ldap_value_free( apiinfo.ldapai_extensions );
  2741.                rxfree( value );
  2742.                rxfree( varname );
  2743.                rxfree( stem );
  2744.                free( w );
  2745.                return ( CallingInvalid );
  2746.             } /* endif */
  2747.          } /* endfor */
  2748.       } /* endif */
  2749.       rxstrcpy( &varname, &stem );
  2750.       rxappendstr( &varname, "LDAPAI_EXTENSIONS." );
  2751.       rxappendstr( &varname, "0" );
  2752.       rxset_length( &value, strlen( _ltoa( i, RXSTRPTR(value), 10 ) ) );
  2753.       if ( setvalue( &varname, &value ) != Good ) {
  2754.          ldap_value_free( apiinfo.ldapai_extensions );
  2755.          rxfree( value );
  2756.          rxfree( varname );
  2757.          rxfree( stem );
  2758.          free( w );
  2759.          return ( CallingInvalid );
  2760.       } /* endif */
  2761.       ldap_value_free( apiinfo.ldapai_extensions );
  2762.       rxfree( varname );
  2763.       rxfree( stem );
  2764.       rxfree( value );
  2765.       free( w );
  2766.       break;
  2767.    case LDAP_OPT_API_FEATURE_INFO:
  2768.       rxstrcpy( &varname, &stem );
  2769.       rxappendstr( &varname, "LDAPAIF_VERSION" );
  2770.       rxset_length( &value, strlen( _ltoa( (ULONG)finfo.ldapaif_version, RXSTRPTR(value), 10 ) ) );
  2771.       if ( setvalue( &varname, &value ) != Good ) {
  2772.          rxfree( varname );
  2773.          rxfree( stem );
  2774.          rxfree( value );
  2775.          free( w );
  2776.          return ( CallingInvalid );
  2777.       } /* endif */
  2778.       rxstrcpy( &varname, &stem );
  2779.       rxappendstr( &varname, "LDAPAIF_NAME" );
  2780.       MAKERXSTRING( t, finfo.ldapaif_name, strlen(finfo.ldapaif_name) );
  2781.       if ( setvalue( &varname, &t ) != Good ) {
  2782.          rxfree( varname );
  2783.          rxfree( stem );
  2784.          rxfree( value );
  2785.          free( w );
  2786.          return ( CallingInvalid );
  2787.       } /* endif */
  2788.       rxfree( varname );
  2789.       rxfree( stem );
  2790.       rxfree( value );
  2791.       free( w );
  2792.       break;
  2793.    } /* endswitch */
  2794.    SetSignedInt2Rx( *retstr, code );
  2795.    return ( CallingValid );
  2796. }
  2797.  
  2798. ULONG     
  2799. Rxldap_set_option(
  2800. PUCHAR name, 
  2801. ULONG argc,
  2802. RXSTRING argv[],
  2803. PSZ queuename,
  2804. PRXSTRING retstr) {
  2805.    LDAP *ld = NULL;
  2806.    int code = 0;
  2807.    Name2Int *v = NULL;
  2808.    int opt = 0;
  2809.    void *optval = NULL;
  2810.    int intval = 0;
  2811.    char *strval = NULL;
  2812.    if ( argc != 3 ) {
  2813.       return ( CallingInvalid );
  2814.    } /* endif */
  2815.    if ( RXNULLSTRING(argv[1]) || RXNULLSTRING(argv[2]) ) {
  2816.       return ( CallingInvalid );
  2817.    } /* endif */
  2818.    if ( !RXSTRLEN(argv[1]) || !RXSTRLEN(argv[2]) ) {
  2819.       return ( CallingInvalid );
  2820.    } /* endif */
  2821.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2822.       return ( CallingInvalid );
  2823.    } /* endif */
  2824.    ld = (LDAP*)rxtoul( argv[0] );
  2825.    v = findintfromname( RXSTRPTR(argv[1]), LdapOptNames, sizeof(LdapOptNames) / sizeof(Name2Int), 0 );
  2826.    if ( !v ) {
  2827.       return ( CallingInvalid );
  2828.    } /* endif */
  2829.    opt = v->intval;
  2830.    switch ( opt ) {
  2831.    case LDAP_OPT_SIZELIMIT:
  2832.    case LDAP_OPT_TIMELIMIT:
  2833.    case LDAP_OPT_PROTOCOL_VERSION:
  2834.       if ( !isnumstr(RXSTRPTR(argv[2])) ) {
  2835.          return ( CallingInvalid );
  2836.       } /* endif */
  2837.       intval = rxtoi( argv[2] );
  2838.       optval = &intval;
  2839.       break;
  2840.    case LDAP_OPT_DEREF:   
  2841.       SetIntFromName( RXSTRPTR(argv[2]), LdapOptValDeref, v, intval, optval );
  2842.       break;
  2843.    case LDAP_OPT_REFERRALS:   
  2844.       SetIntFromName( RXSTRPTR(argv[2]), LdapOptValOnOff, v, intval, optval );
  2845.       break;
  2846.    case LDAP_OPT_SERVER_CONTROLS:
  2847.    case LDAP_OPT_CLIENT_CONTROLS:
  2848.       optval = getldapcontrols( &argv[2] );
  2849.       break;
  2850.    default:
  2851.      return ( CallingInvalid );
  2852.      break;
  2853.    } /* endswitch */
  2854.    if ( !optval ) {
  2855.       return ( CallingInvalid );
  2856.    } /* endif */
  2857.    code = ldap_set_option( ld, opt, optval );
  2858.    switch ( opt ) {
  2859.    case LDAP_OPT_SERVER_CONTROLS:
  2860.    case LDAP_OPT_CLIENT_CONTROLS:
  2861.       ldap_controls_free( optval );
  2862.       break;
  2863.    } /* endswitch */
  2864.    SetSignedInt2Rx( *retstr, code );
  2865.    return ( CallingValid );
  2866. }
  2867.  
  2868. ULONG _Export
  2869. Rxldap_get_errno(
  2870. PUCHAR name, 
  2871. ULONG argc,
  2872. RXSTRING argv[],
  2873. PSZ queuename,
  2874. PRXSTRING retstr) {
  2875.    LDAP *ld = NULL;
  2876.    int code = 0;
  2877.    if ( argc != 1 ) {
  2878.       return ( CallingInvalid );
  2879.    } /* endif */
  2880.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  2881.       return ( CallingInvalid );
  2882.    } /* endif */
  2883.    ld = (LDAP*)rxtoul( argv[0] );
  2884.    ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &code );
  2885.    SetLdapCode( retstr, code );
  2886.    return ( CallingValid );
  2887. }   
  2888.  
  2889. ULONG _Export
  2890. Rxldap_err2string(
  2891. PUCHAR name, 
  2892. ULONG argc,
  2893. RXSTRING argv[],
  2894. PSZ queuename,
  2895. PRXSTRING retstr) {
  2896.    int err = 0;
  2897.    char *str = NULL;
  2898.    if ( argc != 1 ) {
  2899.       return ( CallingInvalid );
  2900.    } /* endif */
  2901.    if ( RXNULLSTRING(argv[0]) ) {
  2902.       return ( CallingInvalid );
  2903.    } /* endif */
  2904.    if ( !RXSTRLEN(argv[0]) ) {
  2905.       return ( CallingInvalid );
  2906.    } /* endif */
  2907.    if ( isnumstr(RXSTRPTR(argv[0])) ) {
  2908.       err = rxtoi( argv[0] );
  2909.    } else {   
  2910.       Name2Int *v = findintfromname( RXSTRPTR(argv[0]), LdapReturnCodes, sizeof(LdapReturnCodes) / sizeof(Name2Int), 1 );
  2911.       if ( !v ) {
  2912.          rxreturn_value( retstr, RXSTRPTR(argv[0]), RXSTRLEN(argv[0]) );
  2913.          return ( CallingValid );
  2914.       } /* endif */
  2915.       err = v->intval;
  2916.    } /* endif */
  2917.    str = ldap_err2string( err );
  2918.    if ( str ) {
  2919.       rxreturn_value( retstr, str, strlen(str) );
  2920.    } else { 
  2921.       rxset_zerolen( retstr );
  2922.    } /* endif */
  2923.    return ( CallingValid );
  2924. }   
  2925.  
  2926. ULONG _Export
  2927. Rxldap_count_entries(
  2928. PUCHAR name, 
  2929. ULONG argc,
  2930. RXSTRING argv[],
  2931. PSZ queuename,
  2932. PRXSTRING retstr) {
  2933.    LDAP *ld = NULL;
  2934.    LDAPMessage *msg = NULL;
  2935.    int count = 0;
  2936.    if ( argc != 2 ) {
  2937.       return ( CallingInvalid );
  2938.    } /* endif */
  2939.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  2940.       return ( CallingInvalid );
  2941.    } /* endif */
  2942.    ld = (LDAP *)rxtoul( argv[0] );
  2943.    msg = (LDAPMessage *)rxtoul( argv[1] );
  2944.    count = ldap_count_entries( ld, msg );
  2945.    SetSignedInt2Rx( *retstr, count );
  2946.    return ( CallingValid );
  2947. }   
  2948.  
  2949. ULONG _Export
  2950. Rxldap_parse_result(
  2951. PUCHAR name, 
  2952. ULONG argc,
  2953. RXSTRING argv[],
  2954. PSZ queuename,
  2955. PRXSTRING retstr) {
  2956.    LDAP *ld = NULL;
  2957.    LDAPMessage *msg = NULL;
  2958.    char *matcheddn = NULL;
  2959.    char **matcheddnp = NULL;
  2960.    int errcode = 0;
  2961.    int *errcodep = NULL;
  2962.    char *errmsg = NULL;
  2963.    char **errmsgp = NULL;
  2964.    LDAPControl **serverctrls = NULL;
  2965.    LDAPControl ***serverctrlsp = NULL;
  2966.    char **referrals = NULL;
  2967.    char ***referralsp = NULL;
  2968.    int freeit = 0;
  2969.    int code = 0;
  2970.    RXSTRING value;
  2971.    RXSTRING varname;
  2972.    RXSTRING stem;
  2973.    RXSTRING t;
  2974.    if ( argc != 8 ) {
  2975.       return ( CallingInvalid );
  2976.    } /* endif */
  2977.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) || !isnumstr(RXSTRPTR(argv[7])) ) {
  2978.       return ( CallingInvalid );
  2979.    } /* endif */  
  2980.    ld = (LDAP *)rxtoul( argv[0] );
  2981.    msg = (LDAPMessage *)rxtoul( argv[1] );
  2982.    if ( !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  2983.       errcodep = &errcode;
  2984.    } /* endif */
  2985.    if ( !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  2986.       matcheddnp = &matcheddn;
  2987.    } /* endif */
  2988.    if ( !RXNULLSTRING(argv[4]) && RXSTRLEN(argv[4]) ) {
  2989.    errmsgp = &errmsg;
  2990.    } /* endif */
  2991.    if ( !RXNULLSTRING(argv[5]) && RXSTRLEN(argv[5]) ) {
  2992.       referralsp = &referrals;
  2993.    } /* endif */
  2994.    if ( !RXNULLSTRING(argv[6]) && RXSTRLEN(argv[6]) ) {
  2995.       serverctrlsp = &serverctrls;
  2996.    } /* endif */
  2997.    freeit = rxtoi( argv[7] );
  2998.    code = ldap_parse_result( ld, msg, errcodep, matcheddnp, errmsgp, referralsp, serverctrlsp, freeit );
  2999.    if ( errcodep ) {
  3000.       char *w = malloc( BUFSIZ );
  3001.       if ( !w ) {
  3002.          return ( CallingInvalid );
  3003.       } /* endif */
  3004.       MAKERXSTRING( value, w, BUFSIZ );
  3005.       SetLdapCode( &value, errcode );
  3006.       if ( setvalue( &argv[2], &value ) != Good ) {
  3007.          free( w );
  3008.          return ( CallingInvalid );
  3009.       } /* endif */
  3010.       free( w );
  3011.    } /* endif */
  3012.    if ( matcheddnp ) {
  3013.       if ( matcheddn ) {
  3014.          MAKERXSTRING( value, matcheddn, strlen(matcheddn) );
  3015.          if ( setvalue( &argv[3], &value ) != Good ) {
  3016.             return ( CallingInvalid );
  3017.          } /* endif */
  3018.          ldap_memfree( matcheddn );
  3019.       } else {
  3020.          rxset_zerolen( &value );
  3021.          if ( setvalue( &argv[3], &value ) != Good ) {
  3022.             return ( CallingInvalid );
  3023.          } /* endif */
  3024.       } /* endif */
  3025.    } /* endif */
  3026.    if ( errmsgp ) {
  3027.       if ( errmsg ) {
  3028.          MAKERXSTRING( value, errmsg, strlen(errmsg) );
  3029.          if ( setvalue( &argv[4], &value ) != Good ) {
  3030.             return ( CallingInvalid );
  3031.          } /* endif */
  3032.          ldap_memfree( errmsg );
  3033.       } else {
  3034.          rxset_zerolen( &value );
  3035.          if ( setvalue( &argv[4], &value ) != Good ) {
  3036.             return ( CallingInvalid );
  3037.          } /* endif */
  3038.       } /* endif */
  3039.    } /* endif */
  3040.    if ( setstrs( &argv[5], referrals, 1 ) < 0 ) {
  3041.       return ( CallingInvalid );
  3042.    } /* endif */
  3043.    if ( setldapctrls( &argv[6], serverctrls ) != Good ) {
  3044.       return ( CallingInvalid );
  3045.    } /* endif */
  3046.    ldap_value_free( referrals );
  3047.    ldap_controls_free( serverctrls );
  3048.    SetLdapCode( retstr, code );
  3049.    return ( CallingValid );
  3050. }   
  3051.  
  3052. ULONG _Export
  3053. Rxldap_first_entry(
  3054. PUCHAR name, 
  3055. ULONG argc,
  3056. RXSTRING argv[],
  3057. PSZ queuename,
  3058. PRXSTRING retstr) {
  3059.    LDAP *ld = NULL;
  3060.    LDAPMessage *msg = NULL;
  3061.    if ( argc != 2 ) {
  3062.       return ( CallingInvalid );
  3063.    } /* endif */
  3064.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3065.       return ( CallingInvalid );
  3066.    } /* endif */
  3067.    ld = (LDAP *)rxtoul( argv[0] );
  3068.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3069.    msg = ldap_first_entry( ld, msg );
  3070.    SetUnsignedInt2Rx( *retstr, msg );
  3071.    return ( CallingValid );
  3072. }   
  3073.  
  3074. ULONG _Export
  3075. Rxldap_next_entry(
  3076. PUCHAR name, 
  3077. ULONG argc,
  3078. RXSTRING argv[],
  3079. PSZ queuename,
  3080. PRXSTRING retstr) {
  3081.    LDAP *ld = NULL;
  3082.    LDAPMessage *msg = NULL;
  3083.    if ( argc != 2 ) {
  3084.       return ( CallingInvalid );
  3085.    } /* endif */
  3086.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3087.       return ( CallingInvalid );
  3088.    } /* endif */
  3089.    ld = (LDAP *)rxtoul( argv[0] );
  3090.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3091.    msg = ldap_next_entry( ld, msg );
  3092.    SetUnsignedInt2Rx( *retstr, msg );
  3093.    return ( CallingValid );
  3094. }   
  3095.  
  3096. ULONG _Export
  3097. Rxldap_count_references(
  3098. PUCHAR name, 
  3099. ULONG argc,
  3100. RXSTRING argv[],
  3101. PSZ queuename,
  3102. PRXSTRING retstr) {
  3103.    LDAP *ld = NULL;
  3104.    LDAPMessage *msg = NULL;
  3105.    int count = 0;
  3106.    if ( argc != 2 ) {
  3107.       return ( CallingInvalid );
  3108.    } /* endif */
  3109.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3110.       return ( CallingInvalid );
  3111.    } /* endif */
  3112.    ld = (LDAP *)rxtoul( argv[0] );
  3113.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3114.    count = ldap_count_references( ld, msg );
  3115.    SetSignedInt2Rx( *retstr, count );
  3116.    return ( CallingValid );
  3117. }   
  3118.  
  3119. ULONG _Export
  3120. Rxldap_first_reference(
  3121. PUCHAR name, 
  3122. ULONG argc,
  3123. RXSTRING argv[],
  3124. PSZ queuename,
  3125. PRXSTRING retstr) {
  3126.    LDAP *ld = NULL;
  3127.    LDAPMessage *msg = NULL;
  3128.    if ( argc != 2 ) {
  3129.       return ( CallingInvalid );
  3130.    } /* endif */
  3131.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3132.       return ( CallingInvalid );
  3133.    } /* endif */
  3134.    ld = (LDAP *)rxtoul( argv[0] );
  3135.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3136.    msg = ldap_first_reference( ld, msg );
  3137.    SetUnsignedInt2Rx( *retstr, msg );
  3138.    return ( CallingValid );
  3139. }   
  3140.  
  3141. ULONG _Export
  3142. Rxldap_next_reference(
  3143. PUCHAR name, 
  3144. ULONG argc,
  3145. RXSTRING argv[],
  3146. PSZ queuename,
  3147. PRXSTRING retstr) {
  3148.    LDAP *ld = NULL;
  3149.    LDAPMessage *msg = NULL;
  3150.    if ( argc != 2 ) {
  3151.       return ( CallingInvalid );
  3152.    } /* endif */
  3153.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3154.       return ( CallingInvalid );
  3155.    } /* endif */
  3156.    ld = (LDAP *)rxtoul( argv[0] );
  3157.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3158.    msg = ldap_next_reference( ld, msg );
  3159.    SetUnsignedInt2Rx( *retstr, msg );
  3160.    return ( CallingValid );
  3161. }   
  3162.  
  3163. ULONG _Export
  3164. Rxldap_abandon(
  3165. PUCHAR name, 
  3166. ULONG argc,
  3167. RXSTRING argv[],
  3168. PSZ queuename,
  3169. PRXSTRING retstr) {
  3170.    LDAP *ld = NULL;
  3171.    int msgid = 0;
  3172.    int code = 0;
  3173.    if ( argc != 2 ) {
  3174.       return ( CallingInvalid );
  3175.    } /* endif */
  3176.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3177.       return ( CallingInvalid );
  3178.    } /* endif */
  3179.    ld = (LDAP *)rxtoul( argv[0] );
  3180.    msgid = rxtoi( argv[1] );
  3181.    code = ldap_abandon( ld, msgid );
  3182.    SetSignedInt2Rx( *retstr, code );
  3183.    return ( CallingValid );
  3184. }   
  3185.  
  3186. ULONG _Export
  3187. Rxldap_abandon_ext(
  3188. PUCHAR name, 
  3189. ULONG argc,
  3190. RXSTRING argv[],
  3191. PSZ queuename,
  3192. PRXSTRING retstr) {
  3193.    LDAP *ld = NULL;
  3194.    int msgid = 0;
  3195.    int code = 0;
  3196.    LDAPControl **serverctrls = NULL;
  3197.    LDAPControl **clientctrls = NULL;
  3198.    if ( argc < 2 || argc > 4 ) {
  3199.       return ( CallingInvalid );
  3200.    } /* endif */
  3201.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3202.       return ( CallingInvalid );
  3203.    } /* endif */
  3204.    ld = (LDAP *)rxtoul( argv[0] );
  3205.    msgid = rxtoi( argv[1] );
  3206.    if ( argc > 2 && !RXNULLSTRING(argv[2]) && RXSTRLEN(argv[2]) ) {
  3207.       serverctrls = getldapcontrols( &argv[2] );
  3208.       if ( !serverctrls ) {
  3209.          return ( CallingInvalid );
  3210.       } /* endif */
  3211.    } /* endif */
  3212.    if ( argc > 3 && !RXNULLSTRING(argv[3]) && RXSTRLEN(argv[3]) ) {
  3213.       serverctrls = getldapcontrols( &argv[3] );
  3214.       if ( !serverctrls ) {
  3215.          return ( CallingInvalid );
  3216.       } /* endif */
  3217.    } /* endif */
  3218.    code = ldap_abandon_ext( ld, msgid, serverctrls, clientctrls );
  3219.    SetLdapCode( retstr, code );
  3220.    return ( CallingValid );
  3221. }   
  3222.  
  3223. ULONG _Export
  3224. Rxldap_msgfree(
  3225. PUCHAR name, 
  3226. ULONG argc,
  3227. RXSTRING argv[],
  3228. PSZ queuename,
  3229. PRXSTRING retstr) {
  3230.    LDAPMessage *msg = NULL;
  3231.    int code = 0;
  3232.    if ( argc != 1 ) {
  3233.       return ( CallingInvalid );
  3234.    } /* endif */
  3235.    if ( !isnumstr( RXSTRPTR(argv[0])) ) {
  3236.       return ( CallingInvalid );
  3237.    } /* endif */
  3238.    msg = (LDAPMessage *)rxtoul( argv[0] );
  3239.    code = ldap_msgfree( msg );
  3240.    setcodename( retstr, code, ResultTypes, sizeof(ResultTypes) / sizeof(Name2Int), 0 );
  3241.    return ( CallingValid );
  3242. }   
  3243.  
  3244. ULONG _Export
  3245. Rxldap_ber_free(
  3246. PUCHAR name, 
  3247. ULONG argc,
  3248. RXSTRING argv[],
  3249. PSZ queuename,
  3250. PRXSTRING retstr) {
  3251.    BerElement *ber = NULL;
  3252.    if ( argc != 1 ) {
  3253.       return ( CallingInvalid );
  3254.    } /* endif */
  3255.    if ( !isnumstr(RXSTRPTR(argv[0])) ) {
  3256.       return ( CallingInvalid );
  3257.    } /* endif */
  3258.    ber = (BerElement *)rxtoul( argv[0] );
  3259.    ber_free( ber, 1 );
  3260.    rxset_zerolen( retstr );
  3261.    return ( CallingValid );
  3262. }   
  3263.  
  3264. ULONG _Export
  3265. Rxldap_get_dn(
  3266. PUCHAR name, 
  3267. ULONG argc,
  3268. RXSTRING argv[],
  3269. PSZ queuename,
  3270. PRXSTRING retstr) {
  3271.    LDAP *ld = NULL;
  3272.    LDAPMessage *msg = NULL;
  3273.    char *dn;
  3274.    if ( argc != 2 ) {
  3275.       return ( CallingInvalid );
  3276.    } /* endif */
  3277.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3278.       return ( CallingInvalid );
  3279.    } /* endif */
  3280.    ld = (LDAP *)rxtoul( argv[0] );
  3281.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3282.    dn = ldap_get_dn( ld, msg );
  3283.    if ( dn ) {
  3284.       SetRetStr( *retstr, dn );
  3285.       ldap_memfree( dn );
  3286.    } else {
  3287.       rxset_zerolen( retstr );
  3288.    } /* endif */
  3289.    return ( CallingValid );
  3290. }   
  3291.  
  3292. ULONG _Export
  3293. Rxldap_explode_dn(
  3294. PUCHAR name, 
  3295. ULONG argc,
  3296. RXSTRING argv[],
  3297. PSZ queuename,
  3298. PRXSTRING retstr) {
  3299.    int notypes = 0;
  3300.    char **v = NULL;
  3301.    int i = 0;
  3302.    int stem0 = 0;
  3303.    if ( argc != 3 ) {
  3304.       return ( CallingInvalid );
  3305.    } /* endif */
  3306.    if ( RXNULLSTRING(argv[2]) ) {
  3307.       return ( CallingInvalid );
  3308.    } /* endif */
  3309.    if ( !RXSTRLEN(argv[2]) ) {
  3310.       return ( CallingInvalid );
  3311.    } /* endif */
  3312.    if ( !isnumstr(RXSTRPTR(argv[1])) ) {
  3313.       return ( CallingInvalid );
  3314.    } /* endif */
  3315.    if ( RXNULLSTRING(argv[0]) || !RXSTRLEN(argv[0]) ) {
  3316.       if ( setstrs( &argv[2], NULL, 0 ) < 0 ) {
  3317.          return ( CallingInvalid );
  3318.       } /* endif */
  3319.       SetSignedInt2Rx( *retstr, 0 );
  3320.       return ( CallingValid );
  3321.    } /* endif */
  3322.    notypes = rxtoi( argv[1] );
  3323.    v = ldap_explode_dn( RXSTRPTR(argv[0]), notypes );
  3324.    stem0 = setstrs( &argv[2], v, 0 );
  3325.    if ( stem0 < 0 ) {
  3326.       ldap_value_free( v );
  3327.       return ( CallingInvalid );
  3328.    } /* endif */
  3329.    ldap_value_free( v );
  3330.    SetSignedInt2Rx( *retstr, stem0 );
  3331.    return ( CallingValid );
  3332. }   
  3333.  
  3334. ULONG _Export
  3335. Rxldap_first_attribute(
  3336. PUCHAR name, 
  3337. ULONG argc,
  3338. RXSTRING argv[],
  3339. PSZ queuename,
  3340. PRXSTRING retstr) {
  3341.    LDAP *ld = NULL;
  3342.    LDAPMessage *msg = NULL;
  3343.    BerElement *ber = NULL;
  3344.    char *an = NULL;
  3345.    RXSTRING value;
  3346.    if ( argc != 3 ) {
  3347.       return ( CallingInvalid );
  3348.    } /* endif */
  3349.    if ( RXNULLSTRING(argv[2]) ) {
  3350.       return ( CallingInvalid );
  3351.    } /* endif */
  3352.    if ( !RXSTRLEN(argv[2]) ) {
  3353.       return ( CallingInvalid );
  3354.    } /* endif */
  3355.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3356.       return ( CallingInvalid );
  3357.    } /* endif */
  3358.    ld = (LDAP *)rxtoul( argv[0] );
  3359.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3360.    an = ldap_first_attribute( ld, msg, &ber );
  3361.    if ( an ) {
  3362.       SetRetStr( *retstr, an );
  3363.       ldap_memfree( an );
  3364.    } else {
  3365.       rxset_zerolen( retstr );
  3366.    } /* endif */
  3367.    value = rxalloc( BUFSIZ );
  3368.    if ( RXNULLSTRING( value ) ) {
  3369.       return ( CallingInvalid );
  3370.    } /* endif */
  3371.    SetUnsignedInt2Rx( value, ber );
  3372.    if ( setvalue( &argv[2], &value ) != Good ) {
  3373.       rxfree( value );
  3374.       return ( CallingInvalid );
  3375.    } /* endif */
  3376.    return ( CallingValid );
  3377. }   
  3378.  
  3379. ULONG _Export
  3380. Rxldap_next_attribute(
  3381. PUCHAR name, 
  3382. ULONG argc,
  3383. RXSTRING argv[],
  3384. PSZ queuename,
  3385. PRXSTRING retstr) {
  3386.    LDAP *ld = NULL;
  3387.    LDAPMessage *msg = NULL;
  3388.    BerElement *ber = NULL;
  3389.    char *an = NULL;
  3390.    if ( argc != 3 ) {
  3391.       return ( CallingInvalid );
  3392.    } /* endif */
  3393.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) || !isnumstr(RXSTRPTR(argv[2])) ) {
  3394.       return ( CallingInvalid );
  3395.    } /* endif */
  3396.    ld = (LDAP *)rxtoul( argv[0] );
  3397.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3398.    ber = (BerElement *)rxtoul( argv[2] );
  3399.    an = ldap_next_attribute( ld, msg, ber );
  3400.    if ( an ) {
  3401.       SetRetStr( *retstr, an );
  3402.       ldap_memfree( an );
  3403.    } else {
  3404.       rxset_zerolen( retstr );
  3405.    } /* endif */
  3406.    return ( CallingValid );
  3407. }   
  3408.  
  3409. ULONG _Export
  3410. Rxldap_get_values(
  3411. PUCHAR name, 
  3412. ULONG argc,
  3413. RXSTRING argv[],
  3414. PSZ queuename,
  3415. PRXSTRING retstr) {
  3416.    LDAP *ld = NULL;
  3417.    LDAPMessage *msg = NULL;
  3418.    char **v = NULL;
  3419.    int stem0 = 0;
  3420.    if ( argc != 4 ) {
  3421.       return ( CallingInvalid );
  3422.    } /* endif */
  3423.    if ( RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[3]) ) {
  3424.       return ( CallingInvalid );
  3425.    } /* endif */
  3426.    if ( !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[3]) ) {
  3427.       return ( CallingInvalid );
  3428.    } /* endif */
  3429.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3430.       return ( CallingInvalid );
  3431.    } /* endif */
  3432.    ld = (LDAP *)rxtoul( argv[0] );
  3433.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3434.    v = ldap_get_values( ld, msg, RXSTRPTR(argv[2]) );
  3435.    stem0 = setstrs( &argv[3], v, 1 );
  3436.    if ( stem0 < 0 ) {
  3437.       ldap_value_free( v );
  3438.       return ( CallingInvalid );
  3439.    } /* endif */
  3440.    ldap_value_free( v );
  3441.    SetSignedInt2Rx( *retstr, stem0 );
  3442.    return ( CallingValid );
  3443. }   
  3444.  
  3445. ULONG _Export
  3446. Rxldap_get_values_len(
  3447. PUCHAR name, 
  3448. ULONG argc,
  3449. RXSTRING argv[],
  3450. PSZ queuename,
  3451. PRXSTRING retstr) {
  3452.    LDAP *ld = NULL;
  3453.    LDAPMessage *msg = NULL;
  3454.    struct berval **v = NULL;
  3455.    RXSTRING varname;
  3456.    RXSTRING stem;
  3457.    RXSTRING value;
  3458.    int i = 0;
  3459.    char *w = NULL;
  3460.    int stem0 = 0;
  3461.    if ( argc != 4 ) {
  3462.       return ( CallingInvalid );
  3463.    } /* endif */
  3464.    if ( RXNULLSTRING(argv[2]) || RXNULLSTRING(argv[3]) ) {
  3465.       return ( CallingInvalid );
  3466.    } /* endif */
  3467.    if ( !RXSTRLEN(argv[2]) || !RXSTRLEN(argv[3]) ) {
  3468.       return ( CallingInvalid );
  3469.    } /* endif */
  3470.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3471.       return ( CallingInvalid );
  3472.    } /* endif */
  3473.    ld = (LDAP *)rxtoul( argv[0] );
  3474.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3475.    varname = rxalloc( RXSTRLEN(argv[3]) + BUFSIZ );
  3476.    if ( RXNULLSTRING( varname ) ) {
  3477.       return ( CallingInvalid );
  3478.    } /* endif */
  3479.    stem = rxalloc( RXSTRLEN(argv[3]) + BUFSIZ );
  3480.    if ( RXNULLSTRING( stem ) ) {
  3481.       rxfree( varname );
  3482.       return ( CallingInvalid );
  3483.    } /* endif */
  3484.    rxstrcpy( &stem, &argv[3] );
  3485.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  3486.       rxappendstr( &stem, "." );
  3487.    } /* endif */
  3488.    w = malloc( BUFSIZ );
  3489.    if ( !w ) {
  3490.       rxfree( varname );
  3491.       rxfree( stem );
  3492.       return ( CallingInvalid );
  3493.    } /* endif */
  3494.    v = ldap_get_values_len( ld, msg, RXSTRPTR(argv[2]) );
  3495.    if ( v ) {
  3496.       for ( i = 0; v[i]; i += 1) {
  3497.          rxstrcpy( &varname, &stem );
  3498.          rxappendstr( &varname, _itoa(i + 1, w, 10) );
  3499.          MAKERXSTRING( value, v[i]->bv_val, v[i]->bv_len );
  3500.          if ( setvalue( &varname, &value ) != Good ) {
  3501.             rxfree( varname );
  3502.             rxfree( stem );
  3503.             free( w );
  3504.             return ( CallingInvalid );
  3505.          } /* endif */
  3506.       } /* endfor */
  3507.       ldap_value_free_len( v );
  3508.       stem0 = i;
  3509.    } /* endif */
  3510.    rxstrcpy( &varname, &stem );
  3511.    rxappendstr( &varname, "0" );
  3512.    _itoa( i, w, 10 );
  3513.    MAKERXSTRING( value, w, strlen(w) );
  3514.    if ( setvalue( &varname, &value ) != Good ) {
  3515.       rxfree( varname );
  3516.       rxfree( stem );
  3517.       free( w );
  3518.       return ( CallingInvalid );
  3519.    } /* endif */
  3520.    rxfree( varname );
  3521.    rxfree( stem );
  3522.    free( w );
  3523.    SetSignedInt2Rx( *retstr, stem0 );
  3524.    return ( CallingValid );
  3525. }   
  3526.  
  3527. ULONG _Export
  3528. Rxldap_count_messages(
  3529. PUCHAR name, 
  3530. ULONG argc,
  3531. RXSTRING argv[],
  3532. PSZ queuename,
  3533. PRXSTRING retstr) {
  3534.    LDAP *ld = NULL;
  3535.    LDAPMessage *msg = NULL;
  3536.    int count = 0;
  3537.    if ( argc != 2 ) {
  3538.       return ( CallingInvalid );
  3539.    } /* endif */
  3540.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3541.       return ( CallingInvalid );
  3542.    } /* endif */
  3543.    ld = (LDAP *)rxtoul( argv[0] );
  3544.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3545.    count = ldap_count_messages( ld, msg );
  3546.    SetSignedInt2Rx( *retstr, count );
  3547.    return ( CallingValid );
  3548. }   
  3549.  
  3550. ULONG _Export
  3551. Rxldap_first_message(
  3552. PUCHAR name, 
  3553. ULONG argc,
  3554. RXSTRING argv[],
  3555. PSZ queuename,
  3556. PRXSTRING retstr) {
  3557.    LDAP *ld = NULL;
  3558.    LDAPMessage *msg = NULL;
  3559.    if ( argc != 2 ) {
  3560.       return ( CallingInvalid );
  3561.    } /* endif */
  3562.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3563.       return ( CallingInvalid );
  3564.    } /* endif */
  3565.    ld = (LDAP *)rxtoul( argv[0] );
  3566.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3567.    msg = ldap_first_message( ld, msg );
  3568.    SetUnsignedInt2Rx( *retstr, msg );
  3569.    return ( CallingValid );
  3570. }   
  3571.  
  3572. ULONG _Export
  3573. Rxldap_next_message(
  3574. PUCHAR name, 
  3575. ULONG argc,
  3576. RXSTRING argv[],
  3577. PSZ queuename,
  3578. PRXSTRING retstr) {
  3579.    LDAP *ld = NULL;
  3580.    LDAPMessage *msg = NULL;
  3581.    if ( argc != 2 ) {
  3582.       return ( CallingInvalid );
  3583.    } /* endif */
  3584.    if ( !isnumstr(RXSTRPTR(argv[0])) || !isnumstr(RXSTRPTR(argv[1])) ) {
  3585.       return ( CallingInvalid );
  3586.    } /* endif */
  3587.    ld = (LDAP *)rxtoul( argv[0] );
  3588.    msg = (LDAPMessage *)rxtoul( argv[1] );
  3589.    msg = ldap_next_message( ld, msg );
  3590.    SetUnsignedInt2Rx( *retstr, msg );
  3591.    return ( CallingValid );
  3592. }   
  3593.  
  3594. static int 
  3595. getvalue(
  3596. const PRXSTRING name,
  3597. PRXSTRING value) {
  3598.    APIRET code = 0;
  3599.    SHVBLOCK shvblock;
  3600.    shvblock.shvnext = NULL;
  3601.    shvblock.shvname = *name;
  3602.    shvblock.shvnamelen = 0;
  3603.    rxset_null(&shvblock.shvvalue);
  3604.    shvblock.shvvaluelen = 0;
  3605.    shvblock.shvcode = RXSHV_SYFET;
  3606.    RexxVariablePool(&shvblock);
  3607.    *value = rxstrdup( shvblock.shvvalue );
  3608.    code = DosFreeMem(RXSTRPTR(shvblock.shvvalue));
  3609.    if ( code != NO_ERROR ) {
  3610.       return ( Bad );
  3611.    } /* endif */
  3612.    return ( shvblock.shvret );
  3613. }
  3614.  
  3615. static int 
  3616. setvalue(
  3617. const PRXSTRING name,
  3618. const PRXSTRING value) {
  3619.    ULONG rc = 0;
  3620.    SHVBLOCK shvblock;
  3621.    shvblock.shvnext = NULL;
  3622.    shvblock.shvname = *name;
  3623.    shvblock.shvnamelen = RXSTRLEN(*name);
  3624.    shvblock.shvvalue = *value;
  3625.    shvblock.shvvaluelen = RXSTRLEN(*value);
  3626.    shvblock.shvcode = RXSHV_SYSET;
  3627.    rc = RexxVariablePool(&shvblock);
  3628.    if (RXSHV_NOAVL == rc || ~(RXSHV_OK | RXSHV_NEWV) & shvblock.shvret) {
  3629.       return ( Bad );
  3630.    } /* endif */
  3631.    return ( Good );
  3632. }
  3633.  
  3634. static VOID
  3635. rxappendstr(
  3636. PRXSTRING rxstr,
  3637. const PCHAR str ) {
  3638.    RXSTRING t;
  3639.    MAKERXSTRING( t, str, strlen( str ) );
  3640.    rxstrcat( rxstr, &t );
  3641. }
  3642.  
  3643. static int _Optlink 
  3644. compname2intname( 
  3645. const void *item1, 
  3646. const void *item2 ) {
  3647.    const Name2Int *i1 = (Name2Int*)item1;
  3648.    const Name2Int *i2 = (Name2Int*)item2;
  3649.    return ( stricmp( i1->name, i2->name ) );
  3650. }
  3651.  
  3652. static int _Optlink 
  3653. compname2intint( 
  3654. const void *item1, 
  3655. const void *item2 ) {
  3656.    const Name2Int *i1 = (Name2Int*)item1;
  3657.    const Name2Int *i2 = (Name2Int*)item2;
  3658.    if ( i1->intval < i2->intval ) {
  3659.       return ( -1 );
  3660.    } else if ( i1->intval > i2->intval ) {
  3661.       return ( 1 );
  3662.    } /* endif */
  3663.    return ( 0 );
  3664. }
  3665.  
  3666. static int _Optlink 
  3667. compname2strstr( 
  3668. const void *item1, 
  3669. const void *item2 ) {
  3670.    const Name2Str *i1 = (Name2Str*)item1;
  3671.    const Name2Str *i2 = (Name2Str*)item2;
  3672.    return ( strcmp( i1->strval, i2->strval ) );
  3673. }
  3674.  
  3675. static Name2Int *
  3676. findintfromname( 
  3677. char *key, 
  3678. const Name2Int *base, 
  3679. unsigned int num,
  3680. int lflag ) {
  3681.    Name2Int k;
  3682.    Name2Int *v = NULL;
  3683.    const unsigned int w = sizeof(Name2Int);
  3684.    k.name = key;
  3685.    if ( num < 10 || lflag ) {
  3686.       v = (Name2Int *)lfind( (const char *)&k, (const char *)base, &num, w, compname2intname );
  3687.    } else {
  3688.       v = (Name2Int *)bsearch( &k, base, num, w, compname2intname );
  3689.    } /* endif */
  3690.    return ( v );
  3691. }
  3692.  
  3693. static Name2Int *
  3694. findnamefromint( 
  3695. int key, 
  3696. const Name2Int *base, 
  3697. unsigned int num,
  3698. int lflag ) {
  3699.    Name2Int k;
  3700.    Name2Int *v = NULL;
  3701.    const unsigned int w = sizeof(Name2Int);
  3702.    k.intval = key;
  3703.    if ( num < 10 || lflag ) {
  3704.       v = (Name2Int *)lfind( (const char *)&k, (const char *)base, &num, w, compname2intint );
  3705.    } else {
  3706.       v = (Name2Int *)bsearch( &k, base, num, w, compname2intint );
  3707.    } /* endif */
  3708.    return ( v );
  3709. }
  3710.  
  3711. static Name2Str *
  3712. findnamefromstr( 
  3713. const char *key, 
  3714. const Name2Str *base, 
  3715. unsigned int num,
  3716. int lflag ) {
  3717.    Name2Str k;
  3718.    Name2Str *v = NULL;
  3719.    const unsigned int w = sizeof(Name2Str);
  3720.    k.strval = (char *)key;
  3721.    if ( num < 10 || lflag ) {
  3722.       v = (Name2Str *)lfind( (const char *)&k, (const char *)base, &num, w, compname2strstr );
  3723.    } else {
  3724.       v = (Name2Str *)bsearch( &k, base, num, w, compname2strstr );
  3725.    } /* endif */
  3726.    return ( v );
  3727. }
  3728.  
  3729. static void 
  3730. freestrs( 
  3731. char **a ) {
  3732.    int i;
  3733.    if ( !a ) {
  3734.       return;
  3735.    } /* endif */
  3736.    for ( i = 0; a[i]; i += 1) {
  3737.       free(a[i]);
  3738.    } /* endfor */
  3739.    free(a);
  3740. }   
  3741.  
  3742. static int 
  3743. parsetimeval( 
  3744. const PRXSTRING rxstr, 
  3745. struct timeval *tv ) {
  3746.    PUCHAR sec = NULL;
  3747.    PUCHAR usec = NULL;
  3748.    PUCHAR p = NULL;
  3749.    if ( isnumstr(RXSTRPTR(*rxstr)) ) {
  3750.       tv->tv_sec = rxtoi( *rxstr );
  3751.       tv->tv_usec = 0;
  3752.       return ( Good );
  3753.    } /* endif */
  3754.    sec = strdup( RXSTRPTR(*rxstr) );
  3755.    if ( !sec ) {
  3756.       return ( Bad );
  3757.    } /* endif */
  3758.    p = strchr( sec, '.' );
  3759.    if ( !p ) {
  3760.       free( sec );
  3761.       return ( Bad );
  3762.    } /* endif */
  3763.    *p = '\0';
  3764.    usec = p + 1;
  3765.    if ( !isnumstr(sec) || !isnumstr(usec) ) {
  3766.       free( sec );
  3767.       return ( Bad );
  3768.    } /* endif */
  3769.    tv->tv_sec = atoi( sec );
  3770.    tv->tv_usec = atoi( usec );
  3771.    free( sec );
  3772.    return ( Good );
  3773. }
  3774.  
  3775. static void 
  3776. setcodename( 
  3777. PRXSTRING rxstr, 
  3778. int code, 
  3779. const Name2Int *base, 
  3780. unsigned int num, 
  3781. int lflag ) {
  3782.    Name2Int *t = findnamefromint( code, base, num, lflag );
  3783.    if ( !t ) {
  3784.       SetSignedInt2Rx( *rxstr, code );
  3785.       return;
  3786.    } /* endif */
  3787.    SetRetStr( *rxstr, t->name );
  3788. }
  3789.  
  3790. static void 
  3791. setstrname( 
  3792. PRXSTRING rxstr, 
  3793. const char *code, 
  3794. const Name2Str *base, 
  3795. unsigned int num, 
  3796. int lflag ) {
  3797.    Name2Str *t = findnamefromstr( code, base, num, lflag );
  3798.    if ( !t ) {
  3799.       SetSignedInt2Rx( *rxstr, code );
  3800.       return;
  3801.    } /* endif */
  3802.    SetRetStr( *rxstr, t->name );
  3803. }
  3804.  
  3805. static BOOL
  3806. isnumstr( 
  3807. const PCHAR s ) {
  3808.    int i;
  3809.    if ( !s ) {
  3810.       return ( FALSE );
  3811.    } /* endif */
  3812.    i = strspn( s, "0123456789" );
  3813.    if ( i < strlen( s ) ) {
  3814.       return ( FALSE );
  3815.    } /* endif */
  3816.    return ( TRUE );
  3817. }
  3818.  
  3819. static LDAPMod **
  3820. getldapmods( PRXSTRING stemname ) {
  3821.    RXSTRING stem;
  3822.    RXSTRING varname;
  3823.    RXSTRING value;
  3824.    char *w = NULL;
  3825.    LDAPMod **mods = NULL;
  3826.    int n = 0;
  3827.    int i = 0;
  3828.    stem = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  3829.    if ( RXNULLSTRING( stem ) ) {
  3830.       return ( NULL );
  3831.    } /* endif */ 
  3832.    varname = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  3833.    if ( RXNULLSTRING( varname ) ) {
  3834.       rxfree( stem );
  3835.       return ( NULL );
  3836.    } /* endif */
  3837.    rxstrcpy( &stem, stemname );
  3838.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  3839.       rxappendstr( &stem, "." );
  3840.    } /* endif */
  3841.    rxstrcpy( &varname, &stem );
  3842.    rxappendstr( &varname, "0" );
  3843.    if ( getvalue(&varname, &value) != Good ) {
  3844.       rxfree( stem );
  3845.       rxfree( varname );
  3846.       return ( NULL );
  3847.    } /* endif */
  3848.    if ( !isnumstr(RXSTRPTR(value)) ) {
  3849.       rxfree( stem );
  3850.       rxfree( varname );
  3851.       rxfree( value );
  3852.       return ( NULL );
  3853.    } /* endif */
  3854.    n = rxtoi( value );
  3855.    rxfree( value );
  3856.    w = malloc( BUFSIZ );
  3857.    if ( !w ) {
  3858.       rxfree( stem );
  3859.       rxfree( varname );
  3860.       return ( NULL );
  3861.    } /* endif */
  3862.    mods = calloc( n + 1, sizeof(LDAPMod*) );
  3863.    if ( !mods ) {
  3864.       rxfree( stem );
  3865.       rxfree( varname );
  3866.       free( w );
  3867.       return ( NULL );
  3868.    } /* endif */
  3869.    for ( i = 0; i < n; i += 1) {
  3870.       int m = 0;
  3871.       int j = 0;
  3872.       Name2Int *v = NULL;
  3873.       mods[i] = calloc( 1, sizeof(LDAPMod) );
  3874.       if ( !mods[i] ) {
  3875.          ldap_mods_free( mods, 1 );
  3876.          rxfree( stem );
  3877.          rxfree( varname );
  3878.          free( w );
  3879.          return ( NULL );
  3880.       } /* endif */
  3881.       rxstrcpy( &varname, &stem );
  3882.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  3883.       rxappendstr( &varname, ".!MOD_OP" );
  3884.       if ( getvalue(&varname, &value) != Good ) {
  3885.          ldap_mods_free( mods, 1 );
  3886.          rxfree( stem );
  3887.          rxfree( varname );
  3888.          free( w );
  3889.          return ( NULL );
  3890.       } /* endif */
  3891.       if ( isnumstr( RXSTRPTR(value) ) ) {
  3892.          mods[i]->mod_op = rxtoi(value); 
  3893.       } else {
  3894.          v = findintfromname( RXSTRPTR(value), OpNames, sizeof(OpNames) / sizeof(Name2Int), 0 );
  3895.          rxfree( value );
  3896.          if ( !v ) {
  3897.             rxfree( stem );
  3898.             rxfree( varname );
  3899.             free( w );
  3900.             return ( NULL );
  3901.          } /* endif */
  3902.          mods[i]->mod_op = v->intval;
  3903.       } /* endif */
  3904.       rxstrcpy( &varname, &stem );
  3905.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  3906.       rxappendstr( &varname, ".!MOD_TYPE" );
  3907.       if ( getvalue(&varname, &value) != Good ) {
  3908.          ldap_mods_free( mods, 1 );
  3909.          rxfree( stem );
  3910.          rxfree( varname );
  3911.          free( w );
  3912.          return ( NULL );
  3913.       } /* endif */
  3914.       mods[i]->mod_type = strdup( RXSTRPTR(value) );
  3915.       rxfree( value );
  3916.       if ( !mods[i]->mod_type ) {
  3917.          ldap_mods_free( mods, 1 );
  3918.          rxfree( stem );
  3919.          rxfree( varname );
  3920.          free( w );
  3921.          return ( NULL );
  3922.       } /* endif */
  3923.       rxstrcpy( &varname, &stem );
  3924.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  3925.       rxappendstr( &varname, ".!MODV.0" );
  3926.       if ( getvalue(&varname, &value) != Good ) {
  3927.          ldap_mods_free( mods, 1 );
  3928.          rxfree( stem );
  3929.          rxfree( varname );
  3930.          free( w );
  3931.          return ( NULL );
  3932.       } /* endif */
  3933.       if ( !isnumstr(RXSTRPTR(value)) ) {
  3934.          ldap_mods_free( mods, 1 );
  3935.          rxfree( stem );
  3936.          rxfree( varname );
  3937.          rxfree( value );
  3938.          free( w );
  3939.          return ( NULL );
  3940.       } /* endif */
  3941.       m = rxtoi( value );
  3942.       rxfree( value );
  3943.       mods[i]->mod_bvalues = calloc( m + 1, sizeof(struct berval *) );
  3944.       if ( !mods[i]->mod_bvalues ) {
  3945.          ldap_mods_free( mods, 1 );
  3946.          rxfree( stem );
  3947.          rxfree( varname );
  3948.          free( w );
  3949.          return ( NULL );
  3950.       } /* endif */
  3951.       for ( j = 0; j < m; j += 1) {
  3952.          mods[i]->mod_bvalues[j] = calloc( 1, sizeof(struct berval) );
  3953.          if ( !mods[i]->mod_bvalues[j] ) {
  3954.             ldap_mods_free( mods, 1 );
  3955.             rxfree( stem );
  3956.             rxfree( varname );
  3957.             free( w );
  3958.             return ( NULL );
  3959.          } /* endif */
  3960.          rxstrcpy( &varname, &stem );
  3961.          rxappendstr( &varname, _itoa(i + 1, w, 10) );
  3962.          rxappendstr( &varname, ".!MODV." );
  3963.          rxappendstr( &varname, _itoa(j + 1, w, 10) );
  3964.          if ( getvalue(&varname, &value) != Good ) {
  3965.             ldap_mods_free( mods, 1 );
  3966.             rxfree( stem );
  3967.             rxfree( varname );
  3968.             free( w );
  3969.             return ( NULL );
  3970.          } /* endif */
  3971.          if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
  3972.             mods[i]->mod_bvalues[j]->bv_val = malloc( RXSTRLEN(value) );
  3973.             if ( !mods[i]->mod_bvalues[j]->bv_val ) {
  3974.                ldap_mods_free( mods, 1 );
  3975.                rxfree( stem );
  3976.                rxfree( varname );
  3977.                rxfree( value );
  3978.                free( w );
  3979.                return ( NULL );
  3980.             } /* endif */
  3981.             mods[i]->mod_bvalues[j]->bv_len = RXSTRLEN(value);
  3982.             memcpy( mods[i]->mod_bvalues[j]->bv_val, RXSTRPTR(value), RXSTRLEN(value) );
  3983.          } else {
  3984.             mods[i]->mod_values[j] = strtoutf8( RXSTRPTR( value ) );
  3985.             if ( !mods[i]->mod_values[j] ) {
  3986.                mods[i]->mod_values[j] = RXSTRPTR( value );
  3987.             } /* endif */
  3988.          } /* endif */
  3989.          rxfree( value );
  3990.       } /* endfor */
  3991.    } /* endfor */
  3992.    rxfree( stem );
  3993.    rxfree( varname );
  3994.    free( w );
  3995.    return ( mods );
  3996. }                                                
  3997.  
  3998. static char **
  3999. getldapattrs( 
  4000. PRXSTRING stemname ) {
  4001.    RXSTRING varname;
  4002.    RXSTRING stem;
  4003.    RXSTRING value;
  4004.    char *w = NULL;
  4005.    int i = 0;
  4006.    int n = 0;
  4007.    char **attrs = NULL;
  4008.    varname = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4009.    if ( RXNULLSTRING( varname ) ) {
  4010.       return ( NULL );
  4011.    } /* endif */
  4012.    stem = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4013.    if ( RXNULLSTRING( stem ) ) {
  4014.       rxfree( varname );
  4015.       return ( NULL );
  4016.    } /* endif */
  4017.    rxstrcpy( &stem, stemname );
  4018.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  4019.       rxappendstr( &stem, "." );
  4020.    } /* endif */
  4021.    rxstrcpy( &varname, &stem );
  4022.    rxappendstr( &varname, "0" );
  4023.    if ( getvalue(&varname, &value) != Good ) {
  4024.       rxfree( stem );
  4025.       rxfree( varname );
  4026.       return ( NULL );
  4027.    } /* endif */
  4028.    if ( !isnumstr(RXSTRPTR(value)) ) {
  4029.       rxfree( stem );
  4030.       rxfree( varname );
  4031.       rxfree( value );
  4032.       return ( NULL );
  4033.    } /* endif */
  4034.    n = rxtoi( value );
  4035.    rxfree( value );
  4036.    attrs = calloc( n + 1, sizeof(char*) );
  4037.    if ( !attrs ) {
  4038.       rxfree( stem );
  4039.       rxfree( varname );
  4040.       return ( NULL );
  4041.    } /* endif */
  4042.    w = malloc( BUFSIZ );
  4043.    if ( !w ) {
  4044.       rxfree( stem );
  4045.       rxfree( varname );
  4046.       return ( NULL );
  4047.    } /* endif */
  4048.    for ( i = 0; i < n; i += 1) {
  4049.       rxstrcpy( &varname, &stem );
  4050.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4051.       if ( getvalue(&varname, &value) != Good ) {
  4052.          rxfree( stem );
  4053.          rxfree( varname );
  4054.          free( w );
  4055.          freestrs( attrs );
  4056.          return ( NULL );
  4057.       } /* endif */
  4058.       attrs[i] = malloc( RXSTRLEN(value) + 1 );
  4059.       if ( !attrs[i] ) {
  4060.          rxfree( stem );
  4061.          rxfree( varname );
  4062.          rxfree( value );
  4063.          free( w );
  4064.          freestrs( attrs );
  4065.          return ( NULL );
  4066.       } /* endif */
  4067.       memcpy( attrs[i], RXSTRPTR(value), RXSTRLEN(value) + 1 );
  4068.       rxfree( value );
  4069.    } /* endfor */
  4070.    free( w );
  4071.    rxfree( varname );
  4072.    rxfree( stem );
  4073.    return ( attrs );
  4074. }
  4075.  
  4076. static int 
  4077. setstrs( 
  4078. PRXSTRING stemname, 
  4079. char **strs,
  4080. int utf8 ) {
  4081.    RXSTRING varname;
  4082.    RXSTRING stem;
  4083.    RXSTRING value;
  4084.    char *w = NULL;
  4085.    int i = 0;
  4086.    char *v = NULL;
  4087.    if ( RXNULLSTRING(*stemname) || !RXSTRPTR(*stemname) ) {
  4088.       return ( 0 );
  4089.    } /* endif */
  4090.    w = malloc( BUFSIZ );
  4091.    if ( !w ) {
  4092.       return ( -1 );
  4093.    } /* endif */
  4094.    varname = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4095.    if ( RXNULLSTRING( varname ) ) {
  4096.       return ( -1 );
  4097.    } /* endif */
  4098.    stem = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4099.    if ( RXNULLSTRING( stem ) ) {
  4100.       rxfree( varname );
  4101.       return ( -1 );
  4102.    } /* endif */
  4103.    rxstrcpy( &stem, stemname );
  4104.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  4105.       rxappendstr( &stem, "." );
  4106.    } /* endif */
  4107.    if ( strs ) {
  4108.       for ( i = 0; strs[i]; i += 1) {
  4109.          rxstrcpy( &varname, &stem );
  4110.          rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4111.          if ( utf8 ) {
  4112.             v = utf8tostr( strs[i] );
  4113.          } /* endif */
  4114.          if ( v ) {
  4115.             MAKERXSTRING( value, v, strlen(v) );
  4116.          } else {
  4117.             MAKERXSTRING( value, strs[i], strlen(strs[i]) );
  4118.          } /* endif */
  4119.          if ( setvalue( &varname, &value ) != Good ) {
  4120.             freemem( v );
  4121.             rxfree( varname );
  4122.             rxfree( stem );
  4123.             free( w );
  4124.             return ( -1 );
  4125.          } /* endif */
  4126.          freemem( v );
  4127.       } /* endfor */
  4128.    } /* endif */
  4129.    rxstrcpy( &varname, &stem );
  4130.    rxappendstr( &varname, "0" );
  4131.    _ltoa( i, w, 10 );
  4132.    MAKERXSTRING( value, w, strlen(w) );
  4133.    if ( setvalue( &varname, &value ) != Good ) {
  4134.       rxfree( stem );
  4135.       rxfree( varname );
  4136.       free( w );
  4137.       return ( -1 );
  4138.    } /* endif */
  4139.    rxfree( varname );
  4140.    rxfree( stem );
  4141.    free( w );
  4142.    return ( i );
  4143. }
  4144.  
  4145. static LDAPControl **
  4146. getldapcontrols( 
  4147. PRXSTRING stemname ) {
  4148.    RXSTRING varname;
  4149.    RXSTRING stem;
  4150.    RXSTRING value;
  4151.    char *w = NULL;
  4152.    int i = 0;
  4153.    int n = 0;
  4154.    LDAPControl **controls = NULL;
  4155.    varname = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4156.    if ( RXNULLSTRING( varname ) ) {
  4157.       return ( NULL );
  4158.    } /* endif */
  4159.    stem = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4160.    if ( RXNULLSTRING( stem ) ) {
  4161.       rxfree( varname );
  4162.       return ( NULL );
  4163.    } /* endif */
  4164.    rxstrcpy( &stem, stemname );
  4165.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  4166.       rxappendstr( &stem, "." );
  4167.    } /* endif */
  4168.    rxstrcpy( &varname, &stem );
  4169.    rxappendstr( &varname, "0" );
  4170.    if ( getvalue(&varname, &value) != Good ) {
  4171.       rxfree( stem );
  4172.       rxfree( varname );
  4173.       return ( NULL );
  4174.    } /* endif */
  4175.    if ( !isnumstr(RXSTRPTR(value)) ) {
  4176.       rxfree( stem );
  4177.       rxfree( varname );
  4178.       rxfree( value );
  4179.       return ( NULL );
  4180.    } /* endif */
  4181.    n = rxtoi( value );
  4182.    rxfree( value );
  4183.    controls = calloc( n + 1, sizeof(LDAPControl*) );
  4184.    if ( !controls ) {
  4185.       rxfree( stem );
  4186.       rxfree( varname );
  4187.       return ( NULL );
  4188.    } /* endif */
  4189.    w = malloc( BUFSIZ );
  4190.    if ( !w ) {
  4191.       rxfree( stem );
  4192.       rxfree( varname );
  4193.       return ( NULL );
  4194.    } /* endif */
  4195.    for ( i = 0; i < n; i += 1) {
  4196.       controls[i] = calloc( 1, sizeof(LDAPControl) );
  4197.       if ( !controls[i] ) {
  4198.          rxfree( stem );
  4199.          rxfree( varname );
  4200.          free( w );
  4201.          ldap_controls_free( controls );
  4202.          return ( NULL );
  4203.       } /* endif */
  4204.       rxstrcpy( &varname, &stem );
  4205.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4206.       rxappendstr( &varname, ".!LDCTL_OID" );
  4207.       if ( getvalue(&varname, &value) != Good ) {
  4208.          rxfree( stem );
  4209.          rxfree( varname );
  4210.          free( w );
  4211.          ldap_controls_free( controls );
  4212.          return ( NULL );
  4213.       } /* endif */
  4214.       memcpy( controls[i]->ldctl_oid, RXSTRPTR(value), RXSTRLEN(value) + 1 );
  4215.       rxstrcpy( &varname, &stem );
  4216.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4217.       rxappendstr( &varname, ".!LDCTL_VALUE" );
  4218.       if ( getvalue(&varname, &value) != Good ) {
  4219.          rxfree( stem );
  4220.          rxfree( varname );
  4221.          free( w );
  4222.          ldap_controls_free( controls );
  4223.          return ( NULL );
  4224.       } /* endif */
  4225.       controls[i]->ldctl_value.bv_val = malloc( RXSTRLEN(value) );
  4226.       if ( !controls[i]->ldctl_value.bv_val ) {
  4227.          rxfree( stem );
  4228.          rxfree( varname );
  4229.          rxfree( value );
  4230.          free( w );
  4231.          ldap_controls_free( controls );
  4232.          return ( NULL );
  4233.       } /* endif */
  4234.       memcpy( controls[i]->ldctl_value.bv_val, RXSTRPTR(value), RXSTRLEN(value) );
  4235.       controls[i]->ldctl_value.bv_len = RXSTRLEN(value);
  4236.       rxfree( value );
  4237.       rxstrcpy( &varname, &stem );
  4238.       rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4239.       rxappendstr( &varname, ".!LDCTL_ISCRITICAL" );
  4240.       if ( getvalue(&varname, &value) != Good ) {
  4241.          rxfree( stem );
  4242.          rxfree( varname );
  4243.          free( w );
  4244.          ldap_controls_free( controls );
  4245.          return ( NULL );
  4246.       } /* endif */
  4247.       if ( !isnumstr(RXSTRPTR(value)) ) {
  4248.          rxfree( stem );
  4249.          rxfree( varname );
  4250.          rxfree( value );
  4251.          free( w );
  4252.          ldap_controls_free( controls );
  4253.          return ( NULL );
  4254.       } /* endif */
  4255.       controls[i]->ldctl_iscritical = rxtoi( value );
  4256.       rxfree( value );
  4257.    } /* endfor */
  4258.    free( w );
  4259.    rxfree( varname );
  4260.    rxfree( stem );
  4261.    return ( controls );
  4262. }
  4263.  
  4264. static int 
  4265. setldapctrls( 
  4266. PRXSTRING stemname, 
  4267. LDAPControl **ctrls ) {
  4268.    RXSTRING varname;
  4269.    RXSTRING stem;
  4270.    RXSTRING value;
  4271.    char *w = NULL;
  4272.    int i = 0;
  4273.    if ( RXNULLSTRING(*stemname) || !RXSTRPTR(*stemname) ) {
  4274.       return ( 0 );
  4275.    } /* endif */
  4276.    w = malloc( BUFSIZ );
  4277.    if ( !w ) {
  4278.       return ( Bad );
  4279.    } /* endif */
  4280.    varname = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4281.    if ( RXNULLSTRING( varname ) ) {
  4282.       return ( CallingInvalid );
  4283.    } /* endif */
  4284.    stem = rxalloc( RXSTRLEN(*stemname) + BUFSIZ );
  4285.    if ( RXNULLSTRING( stem ) ) {
  4286.       rxfree( varname );
  4287.       return ( CallingInvalid );
  4288.    } /* endif */
  4289.    rxstrcpy( &stem, stemname );
  4290.    if ( stem.strptr[RXSTRLEN(stem)-1] != '.' ) {
  4291.       rxappendstr( &stem, "." );
  4292.    } /* endif */
  4293.    if ( ctrls ) {
  4294.       for ( i = 0; ctrls[i]; i += 1) {
  4295.          rxstrcpy( &varname, &stem );
  4296.          rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4297.          rxappendstr( &varname, ".!LDCTL_OID" );
  4298.          if ( ctrls[i]->ldctl_oid ) {
  4299.             MAKERXSTRING( value, ctrls[i]->ldctl_oid, strlen(ctrls[i]->ldctl_oid) );
  4300.          } else {
  4301.             rxset_zerolen( &value );
  4302.          } /* endif */
  4303.          if ( setvalue( &varname, &value ) != Good ) {
  4304.             rxfree( varname );
  4305.             rxfree( stem );
  4306.             free( w );
  4307.             return ( CallingInvalid );
  4308.          } /* endif */
  4309.          rxstrcpy( &varname, &stem );
  4310.          rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4311.          rxappendstr( &varname, ".!LDCTL_VALUE" );
  4312.          if ( ctrls[i]->ldctl_value.bv_len && ctrls[i]->ldctl_value.bv_val ) {
  4313.             MAKERXSTRING( value, ctrls[i]->ldctl_value.bv_val, ctrls[i]->ldctl_value.bv_len );
  4314.          } else {
  4315.             rxset_zerolen( &value );
  4316.          } /* endif */
  4317.          if ( setvalue( &varname, &value ) != Good ) {
  4318.             rxfree( varname );
  4319.             rxfree( stem );
  4320.             free( w );
  4321.             return ( CallingInvalid );
  4322.          } /* endif */
  4323.          rxstrcpy( &varname, &stem );
  4324.          rxappendstr( &varname, _itoa(i + 1, w, 10) );
  4325.          rxappendstr( &varname, ".!LDCTL_ISCRITICAL" );
  4326.          _itoa( ctrls[i]->ldctl_iscritical, w, 10 );
  4327.          MAKERXSTRING( value, w, strlen(w) );
  4328.          if ( setvalue( &varname, &value ) != Good ) {
  4329.             rxfree( varname );
  4330.             rxfree( stem );
  4331.             free( w );
  4332.             return ( CallingInvalid );
  4333.          } /* endif */
  4334.       } /* endfor */
  4335.    } /* endif */
  4336.    rxstrcpy( &varname, &stem );
  4337.    rxappendstr( &varname, "0" );
  4338.    _ltoa( i, w, 10 );
  4339.    MAKERXSTRING( value, w, strlen(w) );
  4340.    if ( setvalue( &varname, &value ) != Good ) {
  4341.       rxfree( stem );
  4342.       rxfree( varname );
  4343.       free( w );
  4344.       return ( CallingInvalid );
  4345.    } /* endif */
  4346.    rxfree( varname );
  4347.    rxfree( stem );
  4348.    free( w );
  4349.    return ( Good );
  4350. }
  4351.  
  4352. static unsigned char *
  4353. strtoutf8( 
  4354. const unsigned char *str ) {
  4355.    UconvObject uconvobj = NULL;
  4356.    int code = 0;
  4357.    UniChar *ucsstr = NULL;
  4358.    UniChar *ucsbuf = NULL;
  4359.    size_t strsize = strlen( str );
  4360.    size_t ucsbufsize = strsize + BUFSIZ;
  4361.    size_t ucsbufleft = ucsbufsize;
  4362.    size_t utf8bufsize = 3 * ucsbufsize;
  4363.    size_t nonident = 0;
  4364.    int i = 0;
  4365.    int j = 0;
  4366.    unsigned char *utf8str = NULL;
  4367.    if ( !str ) {
  4368.       return ( NULL );
  4369.    } /* endif */
  4370.    code = UniCreateUconvObject( (UniChar *)L"", &uconvobj );
  4371.    if ( code != ULS_SUCCESS ) {
  4372.       return ( NULL );
  4373.    } /* endif */
  4374.    ucsstr = ucsbuf = calloc( ucsbufsize, sizeof( ucsstr[0] ) );
  4375.    if ( !ucsstr ) {
  4376.       return ( NULL );
  4377.    } /* endif */
  4378.    code = UniUconvToUcs( uconvobj, (void **)&str, &strsize, &ucsbuf, &ucsbufleft, &nonident );
  4379.    if ( code != ULS_SUCCESS ) {
  4380.       free( ucsstr );
  4381.       return ( NULL );
  4382.    } /* endif */
  4383.    code = UniFreeUconvObject( uconvobj );
  4384.    if ( code != ULS_SUCCESS ) {
  4385.       free( ucsstr );
  4386.       return ( NULL );
  4387.    } /* endif */
  4388.    utf8str = calloc( utf8bufsize, sizeof( utf8str[0] ) );
  4389.    if ( !utf8str ) {
  4390.       free( ucsstr );
  4391.       return ( NULL );
  4392.    } /* endif */
  4393.    for ( i = 0, j = 0; ucsstr[i]; i += 1) {
  4394.       if ( j >= utf8bufsize ) {
  4395.          free( ucsstr );
  4396.          free( utf8str );
  4397.          return ( NULL );
  4398.       } /* endif */
  4399.       if ( ucsstr[i] < 0x80U ) {
  4400.          utf8str[j++] = ucsstr[i];
  4401.       } else if (ucsstr[i] < 0x7ffU ) {
  4402.          utf8str[j++] = ((ucsstr[i] & ~0x3fU) >> 6) | 0xc0U;
  4403.          utf8str[j++] = (ucsstr[i] & 0x3fU) | 0x80U;
  4404.       } else {
  4405.          utf8str[j++] = ((ucsstr[i] & 0xf000U) >> 12) | 0xe0U;
  4406.          utf8str[j++] = ((ucsstr[i] & 0x0fc0U) >> 6) | 0x80U;
  4407.          utf8str[j++] = ((ucsstr[i] & 0x003fU)) | 0x80U;
  4408.       } /* endif */
  4409.    } /* endfor */
  4410.    free( ucsstr );
  4411.    return ( utf8str );
  4412. }
  4413.  
  4414. static unsigned char *
  4415. utf8tostr( 
  4416. const unsigned char *utf8str ) {
  4417.    UconvObject  uconvobj = NULL;
  4418.    int code = 0;
  4419.    UniChar *ucsstr = NULL;
  4420.    UniChar *ucsbuf = NULL;
  4421.    size_t ucsstrsize = 0;
  4422.    int i = 0;
  4423.    int j = 0;
  4424.    unsigned char *str = NULL;
  4425.    unsigned char *buf = NULL;
  4426.    size_t bufsize = 0;
  4427.    size_t bufleft = 0;
  4428.    size_t nonident = 0;
  4429.    size_t ucsstrlen = 0;
  4430.    if ( !utf8str ) {
  4431.       return ( NULL );
  4432.    } /* endif */
  4433.    ucsstrsize = strlen( utf8str ) + BUFSIZ;
  4434.    ucsstr = ucsbuf = calloc( ucsstrsize, sizeof( ucsstr[0] ) );
  4435.    if ( !ucsstr ) {
  4436.       return ( NULL );
  4437.    } /* endif */
  4438.    bufsize = bufleft = 2 * ucsstrsize + BUFSIZ;
  4439.    for (i = 0, j = 0; utf8str[j]; ) {
  4440.       if ( i >= ucsstrsize ) {
  4441.          free( ucsstr );
  4442.          return ( NULL );
  4443.       } /* endif */
  4444.       if ( !(utf8str[j] & 0x80U) ) {
  4445.          ucsstr[i++] = utf8str[j++];
  4446.       } else if ( (utf8str[j] & 0xe0U) == 0xc0U ) {
  4447.          if ( utf8str[j+1] & 0xc0U != 0x80U ) {
  4448.             free( ucsstr );
  4449.             return ( NULL );
  4450.          } /* endif */
  4451.          ucsstr[i++] = ((utf8str[j] & 0x1cU) << 6) | ((utf8str[j] & 0x3U) << 6) | (utf8str[j+1] & 0x3fU);
  4452.          j += 2;
  4453.       } else if ( (utf8str[j] & 0xf0U) == 0xe0U ) {
  4454.          if ( (utf8str[j+1] & 0xc0U) != 0x80U || (utf8str[j+2] & 0xc0U) != 0x80U ) {
  4455.             free( ucsstr );
  4456.             return ( NULL );
  4457.          } /* endif */
  4458.          ucsstr[i++] = ((utf8str[j] & 0x0fU) << 12) | ((utf8str[j+1] & 0x3cU) << 6) | ((utf8str[j+1] & 0x3U) << 6) | (utf8str[j+2] & 0x3fU);
  4459.          j += 3;
  4460.       } else {
  4461.          free( ucsstr );
  4462.          return ( NULL );
  4463.       } /* endif */
  4464.    } /* endfor */
  4465.    code = UniCreateUconvObject( (UniChar *)L"", &uconvobj );
  4466.    if ( code != ULS_SUCCESS ) {
  4467.       free( ucsstr );
  4468.       return ( NULL );
  4469.    } /* endif */
  4470.    str = buf = calloc( bufsize, sizeof( str[0] ) );
  4471.    if ( !str ) {
  4472.       free( ucsstr );
  4473.       return ( NULL );
  4474.    } /* endif */
  4475.    ucsstrlen = UniStrlen( ucsstr );
  4476.    code = UniUconvFromUcs( uconvobj, &ucsbuf, &ucsstrlen, (void **)&buf, &bufleft, &nonident );
  4477.    if ( code != ULS_SUCCESS ) {
  4478.       free( ucsstr );
  4479.       free( str );
  4480.       return ( NULL );
  4481.    } /* endif */
  4482.    code = UniFreeUconvObject( uconvobj );
  4483.    if ( code != ULS_SUCCESS ) {
  4484.       free( ucsstr );
  4485.       free( str );
  4486.       return ( NULL );
  4487.    } /* endif */
  4488.    free( ucsstr );
  4489.    return ( str );
  4490. }
  4491.  
  4492. static void
  4493. freemem(
  4494. void *p ) {
  4495.    if ( p ) {
  4496.       free( p );
  4497.    } /* endif */
  4498. }   
  4499.