dsgw.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /** --- BEGIN COPYRIGHT BLOCK ---
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. --- END COPYRIGHT BLOCK --- */
  38. /*
  39. * dsgw.h -- defines for HTTP gateway
  40. */
  41. #if !defined( DSGW_NO_SSL ) && !defined( NET_SSL )
  42. #define DSGW_NO_SSL
  43. #endif
  44. #include <stdio.h>
  45. #include <string.h>
  46. #include <stdlib.h>
  47. #include <ctype.h>
  48. #include <time.h>
  49. #ifdef LINUX
  50. #include <sys/param.h>
  51. #endif
  52. #include <ldap.h>
  53. #include <litekey.h>
  54. #include <ssl.h>
  55. #ifndef DSGW_NO_SSL
  56. #include <ldap_ssl.h>
  57. #endif
  58. #include "../../include/srchpref.h"
  59. #if defined( XP_WIN32 )
  60. #include "base/systems.h"
  61. #include "proto-ntutil.h"
  62. #endif
  63. #include <prprf.h>
  64. #ifdef AIXV4
  65. #include <strings.h>
  66. #endif /* AIXV4 */
  67. #include "base/util.h"
  68. #include "libadmin/libadmin.h"
  69. #include "i18n.h"
  70. #include <unicode/ucnv.h>
  71. #include <unicode/ucol.h>
  72. #include <unicode/ustring.h>
  73. #if defined( XP_WIN32 )
  74. #define DSGW_PATHSEP_CHAR '\\'
  75. #define DSGW_PATHSEP_STR "\\"
  76. #define DSGW_NULL_DEVICE "nul:"
  77. #define DSGW_DELETE_CMD "del /Q"
  78. #else
  79. #define DSGW_PATHSEP_CHAR '/'
  80. #define DSGW_PATHSEP_STR "/"
  81. #define DSGW_NULL_DEVICE "/dev/null"
  82. #define DSGW_DELETE_CMD "rm"
  83. #endif
  84. #define MSIE40_DEFAULT_CHARSET "iso-8859-1,*,utf-8"
  85. /* Used to name the converter used to convert from the users charset to UTF8 */
  86. #define UNICODE_ENCODING_UTF_8 "UTF-8"
  87. #define ISO_8859_1_ENCODING "ISO_8859-1"
  88. extern char *context ;
  89. extern char *langwich; /* The language chosen by libsi18n. */
  90. extern char *countri; /* The language chosen by libsi18n. */
  91. /*
  92. * define DSGW_DEBUG to cause extensive debugging output to be written
  93. * to /tmp/CGINAME and CGI's output written to /tmp/CGINAME.out
  94. */
  95. /* #define DSGW_DEBUG */ /* turn on debugging output */
  96. #define DSGW_UTF8_NBSP "\302\240" /* u00A8, in UTF-8 */
  97. /*
  98. * XXX the next group of #defines assume that HTTP server has cd'd to
  99. * our CGI dir.
  100. */
  101. #define SERVER_ROOT_PATH "../../.."
  102. #define DSGW_CONFIGDIR_HTTP "../config/"
  103. #define DSGW_CONFIGDIR_ADMSERV "../config/"
  104. /*#define DSGW_CONFIGDIR_ADMSERV SERVER_ROOT_PATH "/admin-serv/config/"*/
  105. #define DSGW_DBSWITCH_FILE "dbswitch.conf"
  106. #define DSGW_DBSWITCH_TMPFILE "dbswitch.tmp"
  107. #define DSGW_TMPLDIR_HTTP "../config/"
  108. #define DSGW_TMPLDIR_ADMSERV "../html/"
  109. #define DSGW_DOCDIR_HTTP "../html"
  110. #define DSGW_CONTEXTDIR_HTTP "../context/"
  111. #define DSGW_HTMLDIR "../html"
  112. #define DSGW_MANROOT SERVER_ROOT_PATH "/manual/"
  113. #define DSGW_MANUALSHORTCUT ".MANUAL"
  114. #define DSGW_MANUALSHORTCUT_LEN 7
  115. #define DSGW_ADMSERV_BINDIR "/admin-serv/bin/"
  116. #define DSGW_USER_ADM_BINDIR "/user-environment/bin/"
  117. #define DSGW_LCACHECONF_PPATH "ldap/config/" /* partial path from /userdb */
  118. #define DSGW_LCACHECONF_FILE "lcache.conf"
  119. #define DSGW_TOOLSDIR "/ldap/tools"
  120. #define DSGW_LDAPSEARCH "ldapsearch"
  121. #define DSGW_LDAPMODIFY "ldapmodify"
  122. #define DSGW_SEARCHPREFSFILE "dsgwsearchprefs.conf"
  123. #define DSGW_FILTERFILE "dsgwfilter.conf"
  124. #define DSGW_CONFIGFILE "dsgw.conf"
  125. #define DSGW_DEFSECURITYPATH "../ssl"
  126. #define DSGW_CONFIG_LISTPREFIX "list-"
  127. #define DSGW_CONFIG_DISPLAYPREFIX "display-"
  128. #define DSGW_CONFIG_EDITPREFIX "edit-"
  129. #define DSGW_CONFIG_ADDPREFIX "add-"
  130. #define DSGW_SRCHMODE_SMART "smart"
  131. #define DSGW_SRCHMODE_SMART_ID 1
  132. #define DSGW_SRCHMODE_COMPLEX "complex"
  133. #define DSGW_SRCHMODE_COMPLEX_ID 2
  134. #define DSGW_SRCHMODE_PATTERN "pattern"
  135. #define DSGW_SRCHMODE_PATTERN_ID 3
  136. #define DSGW_SRCHMODE_AUTH "auth"
  137. #define DSGW_SRCHMODE_AUTH_ID 4
  138. #define DSGW_SRCHTYPE_AUTH "auth"
  139. #define LDAP_URL_PREFIX "ldap://"
  140. #define LDAP_URL_PREFIX_LEN 7
  141. #define LDAPDB_URL_PREFIX "ldapdb://"
  142. #define LDAPDB_URL_PREFIX_LEN 9
  143. /* attribute types */
  144. #define DSGW_ATTRTYPE_OBJECTCLASS "objectClass"
  145. #define DSGW_ATTRTYPE_HASUBORDINATES "hasSubordinates"
  146. #define DSGW_ATTRTYPE_USERPASSWORD "userPassword"
  147. #define DSGW_ATTRTYPE_NTUSERDOMAINID "nTUserDomainId"
  148. #define DSGW_ATTRTYPE_USERID "uid"
  149. #define DSGW_OC_NTUSER "ntuser"
  150. #define DSGW_ATTRTYPE_NTGROUPDOMAINID "nTGroupDomainId"
  151. #define DSGW_ATTRTYPE_NTGROUPNAME "nTGroupName"
  152. #define DSGW_ATTRTYPE_AIMSTATUSTEXT "nsaimstatustext"
  153. #if defined( XP_WIN32 )
  154. #include <lmaccess.h>
  155. #else
  156. /*
  157. * For Gateway's running on UNIX Platforms.
  158. * These are all defined in <lmaccess.h> on Win32.
  159. */
  160. /*
  161. * Special Values and Constants - User
  162. */
  163. /*
  164. * Privilege levels (USER_INFO_X field usriX_priv (X = 0/1)).
  165. */
  166. #define USER_PRIV_MASK 0x3
  167. #define USER_PRIV_GUEST 0
  168. #define USER_PRIV_USER 1
  169. #define USER_PRIV_ADMIN 2
  170. /*
  171. * Bit masks for field usriX_flags of USER_INFO_X (X = 0/1).
  172. */
  173. #define UF_SCRIPT 0x0001
  174. #define UF_ACCOUNTDISABLE 0x0002
  175. #define UF_HOMEDIR_REQUIRED 0x0008
  176. #define UF_LOCKOUT 0x0010
  177. #define UF_PASSWD_NOTREQD 0x0020
  178. #define UF_PASSWD_CANT_CHANGE 0x0040
  179. /*
  180. * Account type bits as part of usri_flags.
  181. */
  182. #define UF_TEMP_DUPLICATE_ACCOUNT 0x0100
  183. #define UF_NORMAL_ACCOUNT 0x0200
  184. #define UF_INTERDOMAIN_TRUST_ACCOUNT 0x0800
  185. #define UF_WORKSTATION_TRUST_ACCOUNT 0x1000
  186. #define UF_SERVER_TRUST_ACCOUNT 0x2000
  187. #define UF_MACHINE_ACCOUNT_MASK ( UF_INTERDOMAIN_TRUST_ACCOUNT | \
  188. UF_WORKSTATION_TRUST_ACCOUNT | \
  189. UF_SERVER_TRUST_ACCOUNT )
  190. #define UF_ACCOUNT_TYPE_MASK ( \
  191. UF_TEMP_DUPLICATE_ACCOUNT | \
  192. UF_NORMAL_ACCOUNT | \
  193. UF_INTERDOMAIN_TRUST_ACCOUNT | \
  194. UF_WORKSTATION_TRUST_ACCOUNT | \
  195. UF_SERVER_TRUST_ACCOUNT \
  196. )
  197. #define UF_DONT_EXPIRE_PASSWD 0x10000
  198. #define UF_SETTABLE_BITS ( \
  199. UF_SCRIPT | \
  200. UF_ACCOUNTDISABLE | \
  201. UF_LOCKOUT | \
  202. UF_HOMEDIR_REQUIRED | \
  203. UF_PASSWD_NOTREQD | \
  204. UF_PASSWD_CANT_CHANGE | \
  205. UF_ACCOUNT_TYPE_MASK | \
  206. UF_DONT_EXPIRE_PASSWD \
  207. )
  208. /*
  209. * Bit masks for field usri2_auth_flags of USER_INFO_2.
  210. */
  211. #define AF_OP_PRINT 0x1
  212. #define AF_OP_COMM 0x2
  213. #define AF_OP_SERVER 0x4
  214. #define AF_OP_ACCOUNTS 0x8
  215. #define AF_SETTABLE_BITS (AF_OP_PRINT | AF_OP_COMM | \
  216. AF_OP_SERVER | AF_OP_ACCOUNTS)
  217. #endif /* XP_WIN32 */
  218. #define MAX_NTUSERID_LEN 20
  219. /* Types of privs in usri3_priv of struct USER_INFO_3 */
  220. #define DSGW_NT_UP_GUEST "Guest"
  221. #define DSGW_NT_UP_USER "User"
  222. #define DSGW_NT_UP_ADMIN "Admin"
  223. /* Meaning of flags in usri3_flags of struct USER_INFO_3 */
  224. #define DSGW_NT_UF_SCRIPT "Logon Script Executed"
  225. #define DSGW_NT_UF_ACCOUNT_DISABLED "Account Disabled"
  226. #define DSGW_NT_UF_HOMEDIR_REQD "Home Directory Required"
  227. #define DSGW_NT_UF_PASSWD_NOTREQD "Password Not Required"
  228. #define DSGW_NT_UF_PASSWD_CANT_CHANGE "User Cannot Change Password"
  229. #define DSGW_NT_UF_LOCKOUT "Account Locked Out"
  230. #define DSGW_NT_UF_DONT_EXPIRE_PASSWORD "Password Never Expires"
  231. #define DSGW_NT_UF_NORMAL_ACCOUNT "Default Account Type"
  232. #define DSGW_NT_UF_TEMP_DUPLICATE_ACCOUNT "Temporary Account Type"
  233. #define DSGW_NT_UF_TEMP_WRKSTN_TRUST_ACCOUNT "Workstation Account Type"
  234. #define DSGW_NT_UF_TEMP_SERVER_TRUST_ACCOUNT "Server Account Type"
  235. #define DSGW_NT_UF_TEMP_INTERDOMAIN_TRUST_ACCOUNT "Interdomain Trust Account Type"
  236. #define DSGW_NT_AF_OP_PRINT "Print Operator"
  237. #define DSGW_NT_AF_OP_COMM "Backup Operator"
  238. #define DSGW_NT_AF_OP_SERVER "Server Operator"
  239. #define DSGW_NT_AF_OP_ACCOUNTS "Accounts Operator"
  240. /* HTTP request methods flags */
  241. #define DSGW_METHOD_GET 0x01
  242. #define DSGW_METHOD_POST 0x02
  243. /* URL prefixes specific to our gateway */
  244. #define DSGW_URLPREFIX_MAIN_HTTP "lang?file="
  245. #define DSGW_URLPREFIX_MAIN_ADMSERV ""
  246. /*#define DSGW_URLPREFIX_CGI_HTTP "../bin/"*/
  247. #define DSGW_URLPREFIX_CGI_HTTP ""
  248. #define DSGW_URLPREFIX_CGI_ADMSERV ""
  249. #define DSGW_URLPREFIX_BIN "/clients/dsgw/bin/"
  250. #define DSGW_URLPREFIX_MAIN DSGW_URLPREFIX_MAIN_HTTP
  251. #define DSGW_CGINAME_DOSEARCH "dosearch"
  252. #define DSGW_CGINAME_BROWSE "browse"
  253. #define DSGW_CGINAME_SEARCH "search"
  254. #define DSGW_CGINAME_CSEARCH "csearch"
  255. #define DSGW_CGINAME_AUTH "auth"
  256. #define DSGW_CGINAME_EDIT "edit"
  257. #define DSGW_CGINAME_DOMODIFY "domodify"
  258. #define DSGW_CGINAME_TUTOR "tutor"
  259. #define DSGW_CGINAME_DNEDIT "dnedit"
  260. #define DSGW_CGINAME_LANG "lang"
  261. /* definitions for modes - they type of operation we are performing */
  262. /* These definitions need to match, one-for-one, the DSGW_CGINAMEs */
  263. #define DSGW_MODE_DOSEARCH 1
  264. #define DSGW_CGINUM_DOSEARCH DSGW_MODE_DOSEARCH
  265. #define DSGW_MODE_BROWSE 2
  266. #define DSGW_CGINUM_BROWSE DSGW_MODE_BROWSE
  267. #define DSGW_MODE_SEARCH 3
  268. #define DSGW_CGINUM_SEARCH DSGW_MODE_SEARCH
  269. #define DSGW_MODE_CSEARCH 4
  270. #define DSGW_CGINUM_CSEARCH DSGW_MODE_CSEARCH
  271. #define DSGW_MODE_AUTH 5
  272. #define DSGW_CGINUM_AUTH DSGW_MODE_AUTH
  273. #define DSGW_MODE_EDIT 6
  274. #define DSGW_CGINUM_EDIT DSGW_MODE_EDIT
  275. #define DSGW_MODE_DOMODIFY 7
  276. #define DSGW_CGINUM_DOMODIFY DSGW_MODE_DOMODIFY
  277. #define DSGW_MODE_TUTOR 8
  278. #define DSGW_CGINUM_TUTOR DSGW_MODE_TUTOR
  279. #define DSGW_MODE_DNEDIT 9
  280. #define DSGW_CGINUM_DNEDIT DSGW_MODE_DNEDIT
  281. #define DSGW_MODE_LANG 10
  282. #define DSGW_CGINUM_LANG DSGW_MODE_LANG
  283. #define DSGW_MODE_LASTMODE DSGW_MODE_LANG
  284. #define DSGW_MODE_NUMMODES DSGW_MODE_LASTMODE
  285. #define DSGW_MODE_UNKNOWN 99
  286. /* error codes -- messages are in dsgw_errs[] array in error.c */
  287. #define DSGW_ERR_BADMETHOD 1
  288. #define DSGW_ERR_BADFORMDATA 2
  289. #define DSGW_ERR_NOMEMORY 3
  290. #define DSGW_ERR_MISSINGINPUT 4
  291. #define DSGW_ERR_BADFILEPATH 5
  292. #define DSGW_ERR_BADCONFIG 6
  293. #define DSGW_ERR_LDAPINIT 7
  294. #define DSGW_ERR_LDAPGENERAL 8
  295. #define DSGW_ERR_UNKSRCHTYPE 9
  296. #define DSGW_ERR_NOFILTERS 10
  297. #define DSGW_ERR_OPENHTMLFILE 11
  298. #define DSGW_ERR_SEARCHMODE 12
  299. #define DSGW_ERR_UNKATTRLABEL 13
  300. #define DSGW_ERR_UNKMATCHPROMPT 14
  301. #define DSGW_ERR_LDAPURL_NODN 15
  302. #define DSGW_ERR_LDAPURL_BADSCOPE 16
  303. #define DSGW_ERR_LDAPURL_NOTLDAP 17
  304. #define DSGW_ERR_LDAPURL_BAD 18
  305. #define DSGW_ERR_INTERNAL 19
  306. #define DSGW_ERR_OPENDIR 20
  307. #define DSGW_ERR_WRITEINDEXFILE 21
  308. #define DSGW_ERR_OPENINDEXFILE 22
  309. #define DSGW_ERR_SSLINIT 23
  310. #define DSGW_ERR_NO_MGRDN 24
  311. /*
  312. * Note: do not add more error codes here! The cookie error codes use the
  313. * same error code space as all the others. Go to the end of the "more error
  314. * codes" section and add new error codes there.
  315. */
  316. /* Cookie db routines - error codes */
  317. #define DSGW_CKDB_KEY_NOT_PRESENT 25
  318. #define DSGW_CKDB_DBERROR 26
  319. #define DSGW_CKDB_EXPIRED 27
  320. #define DSGW_CKDB_RNDSTRFAIL 28
  321. #define DSGW_CKDB_NODN 29
  322. #define DSGW_CKDB_CANTOPEN 30
  323. #define DSGW_CKDB_CANTAPPEND 31
  324. /* more error codes */
  325. #define DSGW_ERR_NOSECPATH 32
  326. #define DSGW_ERR_NOSEARCHSTRING 33
  327. #define DSGW_ERR_CONFIGTOOMANYARGS 34
  328. #define DSGW_ERR_ADMSERV_CREDFAIL 35
  329. #define DSGW_ERR_LDAPDBURL_NODN 36
  330. #define DSGW_ERR_LDAPDBURL_NOTLDAPDB 37
  331. #define DSGW_ERR_LDAPDBURL_BAD 38
  332. #define DSGW_ERR_LCACHEINIT 39
  333. #define DSGW_ERR_WSAINIT 40
  334. #define DSGW_ERR_SERVICETYPE 41
  335. #define DSGW_ERR_DBCONF 42
  336. #define DSGW_ERR_USERDB_PATH 43
  337. #define DSGW_ERR_UPDATE_DBSWITCH 44
  338. #define DSGW_ERR_ENTRY_NOT_FOUND 45
  339. #define DSGW_ERR_DB_ERASE 46
  340. #define DSGW_ERR_LOCALDB_PERMISSION_DENIED 47
  341. #define DSGW_ERR_NOATTRVALUE 48
  342. #define DSGW_ERR_USERID_REQUIRED 49
  343. #define DSGW_ERR_DOMAINID_NOTUNIQUE 50
  344. #define DSGW_ERR_USERID_DOMAINID_REQUIRED 51
  345. #define DSGW_ERR_USERID_MAXLEN_EXCEEDED 52
  346. #define DSGW_ERR_CHARSET_NOT_SUPPORTED 53
  347. /* Return codes from dsgw_init_ldap() */
  348. #define DSGW_BOUND_ASUSER 1
  349. #define DSGW_BOUND_ANONYMOUS 2
  350. /* NT Domain Id seperator */
  351. #define DSGW_NTDOMAINID_SEP ':'
  352. /* Cookie names */
  353. #define DSGW_BROWSESBCKNAME "nsdsgwbrowseSB"
  354. #define DSGW_SEARCHSBCKNAME "nsdsgwsearchSB"
  355. #define DSGW_AUTHCKNAME "nsdsgwauth"
  356. #define DSGW_CKHDR "Set-cookie: "
  357. #define DSGW_EXPSTR "expires="
  358. #define DSGW_UNAUTHSTR "[unauthenticated]"
  359. /* Name of cookie database - context will be appended to "cookies" for multiple GW's*/
  360. #define DSGW_COOKIEDB_FNAME SERVER_ROOT_PATH "/bin/slapd/authck/cookies"
  361. /* Default lifetime of authentication cookies (in seconds) */
  362. #define DSGW_DEF_AUTH_LIFETIME ( 60 * 60 ) /* one hour */
  363. #define DSGW_SECS_PER_DAY ( 60 * 60 * 24 ) /* one day */
  364. #define DSGW_CKPURGEINTERVAL ( 60 * 10 ) /* Ten minutes */
  365. #define DSGW_MODIFY_GRACEPERIOD ( 60 * 5 ) /* Five minutes */
  366. /* String used as DN in auth CGI to indicate "I want to bind as the root dn" */
  367. #define MGRDNSTR "MANAGER"
  368. /*
  369. * Enum for NT Domain checking
  370. */
  371. typedef enum _LDAPDomainIdStatus {
  372. LDAPDomainIdStatus_Unique = 0,
  373. LDAPDomainIdStatus_Nonunique = -1,
  374. LDAPDomainIdStatus_NullAttr = -2,
  375. LDAPDomainIdStatus_NullId = -3
  376. } LDAPDomainIdStatus;
  377. /*
  378. * Structure used to associate LDAP objectClasses with display templates.
  379. * These are defined by "template" config. file lines.
  380. */
  381. typedef struct dsgwtmpl {
  382. char *dstmpl_name;
  383. char **dstmpl_ocvals;
  384. struct dsgwtmpl *dstmpl_next;
  385. } dsgwtmpl;
  386. /*
  387. * Structures used to keep track of template sets which are used to support
  388. * more than one way to view an entry. These are defined by "tmplset"
  389. * config. file lines.
  390. */
  391. typedef struct dsgwview {
  392. char *dsview_caption;
  393. char *dsview_template;
  394. char *dsview_jscript;
  395. struct dsgwview *dsview_next;
  396. } dsgwview;
  397. typedef struct dsgwtmplset {
  398. char *dstset_name;
  399. dsgwview *dstset_viewlist;
  400. int dstset_viewcount;
  401. struct dsgwtmplset *dstset_next;
  402. } dsgwtmplset;
  403. /*
  404. * Structure used to hold information about Attribute Value Sets that are
  405. * used with DS_ATTRVAL_SET entry display directives. These sets are defined
  406. * by "attrvset" config. file lines.
  407. */
  408. typedef struct dsgwavset {
  409. char *dsavset_handle;
  410. int dsavset_itemcount;
  411. char **dsavset_values;
  412. char **dsavset_prefixes;
  413. char **dsavset_suffixes;
  414. struct dsgwavset *dsavset_next;
  415. } dsgwavset;
  416. /*
  417. * Structure used to hold information about file include sets that are used
  418. * with INCLUDESET directives. These sets are defined by "includeset" config.
  419. * file lines.
  420. */
  421. typedef struct dsgwinclset {
  422. char *dsiset_handle;
  423. int dsiset_itemcount;
  424. char **dsiset_filenames;
  425. struct dsgwinclset *dsiset_next;
  426. } dsgwinclset;
  427. /*
  428. * structure used to track locations where new entries can be added
  429. * these are created based on the "location" config. file lines
  430. */
  431. typedef struct dsgwloc {
  432. char *dsloc_handle; /* short name */
  433. char *dsloc_fullname; /* friendly name */
  434. char *dsloc_dnsuffix; /* new entry location (a full DN) */
  435. } dsgwloc;
  436. /*
  437. * structure used to track types of new entries that can be added
  438. * these are created based on the "newtype" config. file lines
  439. */
  440. typedef struct dsgwnewtype {
  441. char *dsnt_template; /* name of add-XXX.html template */
  442. char *dsnt_fullname; /* friendly name */
  443. char *dsnt_rdnattr; /* attribute used to construct RDN */
  444. int *dsnt_locations; /* indexes into gc_locations array */
  445. int dsnt_loccount; /* number of dsnt_locations */
  446. struct dsgwnewtype *dsnt_next;
  447. } dsgwnewtype;
  448. /*
  449. * Structure used to hold mapping from LDAP attrs. to VCard properties
  450. */
  451. typedef struct dsgwvcprop {
  452. char *dsgwvcprop_property; /* VCard property name */
  453. char *dsgwvcprop_ldaptype; /* LDAP attribute type */
  454. char *dsgwvcprop_ldaptype2; /* only used for "n" prop. */
  455. char *dsgwvcprop_syntax; /* cis or mls only please! */
  456. struct dsgwvcprop *dsgwvcprop_next;
  457. } dsgwvcprop;
  458. /* substring substitution structure */
  459. typedef struct dsgwsubst {
  460. char *dsgwsubst_from;
  461. char *dsgwsubst_to;
  462. char **dsgwsubst_charsets; /* NULL => any charset */
  463. struct dsgwsubst *dsgwsubst_next;
  464. } dsgwsubst;
  465. /* Configuration information structure */
  466. typedef struct dsgwconfig_t {
  467. int gc_admserv; /* non-zero if running under admserv */
  468. int gc_enduser; /* if non-zero, running end-user CGI */
  469. char *gc_baseurl;
  470. char *gc_ldapserver;
  471. int gc_ldapport;
  472. char *gc_ldapsearchbase;
  473. char *gc_rootdn;
  474. #ifndef DSGW_NO_SSL
  475. int gc_ldapssl; /* if non-zero, do LDAP over SSL */
  476. char *gc_securitypath;
  477. #endif
  478. int gc_configerr; /* if non-zero, there were cf errs */
  479. char *gc_configdir; /* path to our config files */
  480. char *gc_tmpldir; /* path to our HTML template files */
  481. char *gc_docdir; /* path to the HTML files*/
  482. char *gc_gwnametrans; /* The nametrans for the gateway (for FT)*/
  483. char *gc_urlpfxmain; /* URL prefix for dsgw main page */
  484. char *gc_urlpfxcgi; /* URL prefix for dsgw CGIs */
  485. char *gc_configerrstr;
  486. char *gc_localdbconf; /* NULL if local DB not being used */
  487. /* otherwise - name of localdb conf */
  488. char *gc_binddn; /* DN to bind as if user info unknown */
  489. char *gc_bindpw; /* passwd to use if user info unknown */
  490. float gc_httpversion; /* client's HTTP version */
  491. char *gc_charset; /* character set used by CGIs & HTML */
  492. char *gc_NLS; /* directory used by libnls */
  493. char *gc_ClientLanguage; /* preferred language list */
  494. char *gc_AdminLanguage; /* administrator language list */
  495. char *gc_DefaultLanguage; /* default language list for either */
  496. char **gc_clientIgnoreACharset; /* browsers uses default charset
  497. instead of accept-charsets */
  498. char *gc_orgcharturl; /* http base url for orgchart*/
  499. char *gc_orgchartsearchattr; /* Search attribute the orgchart uses*/
  500. int gc_aimpresence; /* enable aim presence*/
  501. dsgwtmpl *gc_templates; /* linked list */
  502. dsgwnewtype *gc_newentrytypes; /* linked list */
  503. dsgwloc *gc_newentrylocs; /* array of structures */
  504. int gc_newentryloccount;
  505. dsgwtmplset *gc_tmplsets; /* linked list */
  506. dsgwavset *gc_avsets; /* linked list */
  507. dsgwinclset *gc_includesets; /* linked list */
  508. dsgwvcprop *gc_vcardproperties; /* linked list */
  509. int gc_httpskeysize; /* if non-zero, HTTPS is being used */
  510. int gc_sslrequired;
  511. time_t gc_authlifetime; /* lifetime of cookies, in seconds */
  512. int gc_authrequired; /* if non-zero, disallow access unless
  513. authenticated */
  514. #define DSGW_SSLREQ_NEVER 0
  515. #define DSGW_SSLREQ_WHENAUTHENTICATED 1
  516. #define DSGW_SSLREQ_ALWAYS 2
  517. dsgwsubst *gc_changeHTML; /* linked list */
  518. dsgwsubst *gc_l10nsets; /* linked list */
  519. /*
  520. * The following aren't strictly config file options, but are put
  521. * into the gc struct.
  522. */
  523. int gc_mode; /* Mode (CGI being executed) */
  524. } dsgwconfig;
  525. /*
  526. * Structure used to return broken-out ldapdb:// URL info
  527. */
  528. typedef struct ldapdb_url_desc {
  529. char *ludb_path;
  530. char *ludb_dn;
  531. } LDAPDBURLDesc;
  532. /* template stuff */
  533. /* The number of templates defined */
  534. #define MAXTEMPLATE 30
  535. /* The maximum number of variables for a given template */
  536. #define MAXVARS 4
  537. /* The structure of a directive is fairly simple. You have:
  538. *
  539. * <!-- NAME var1="val" var2="val" var3="val">
  540. *
  541. * You _must_ put the values in quotes.
  542. */
  543. /* The structure of a template. */
  544. typedef struct template_s {
  545. char *name;
  546. char *format;
  547. } *tmpptr;
  548. #define DIRECTIVE_START "<!-- "
  549. #define GCONTEXT_DIRECTIVE "<!-- GCONTEXT -->"
  550. #define DIRECTIVE_END '>'
  551. /* A really big form line */
  552. #define BIG_LINE 1024
  553. /* struct to track saved lines */
  554. typedef struct savedlines {
  555. int svl_count;
  556. int svl_current;
  557. char **svl_line;
  558. } savedlines;
  559. typedef struct dsgwtmplinfo {
  560. char *dsti_template;
  561. int dsti_type;
  562. #define DSGW_TMPLTYPE_LIST 1
  563. #define DSGW_TMPLTYPE_DISPLAY 2
  564. #define DSGW_TMPLTYPE_EDIT 3
  565. #define DSGW_TMPLTYPE_ADD 4
  566. unsigned long dsti_options;
  567. #define DSGW_DISPLAY_OPT_LIST_IF_ONE 0x00000001
  568. #define DSGW_DISPLAY_OPT_AUTH 0x00000002
  569. #define DSGW_DISPLAY_OPT_EDITABLE 0x00000004
  570. #define DSGW_DISPLAY_OPT_ADDING 0x00000008
  571. #define DSGW_DISPLAY_OPT_LINK2EDIT 0x00000010
  572. #define DSGW_DISPLAY_OPT_DNLIST_JS 0x00000020
  573. #define DSGW_DISPLAY_OPT_CUSTOM_SEARCHDESC 0x00000040
  574. char **dsti_attrs;
  575. unsigned long *dsti_attrflags;
  576. #define DSGW_DSTI_ATTR_SEEN 0x00000001
  577. char **dsti_attrsonly_attrs;
  578. char *dsti_sortbyattr;
  579. int dsti_entrycount;
  580. char *dsti_search2s;
  581. char *dsti_search3s;
  582. char *dsti_search4s;
  583. char *dsti_searcherror;
  584. char *dsti_searchlderrtxt;
  585. LDAP *dsti_ld;
  586. LDAPMessage *dsti_entry;
  587. LDAPMessage *dsti_attrsonly_entry;
  588. char *dsti_entrydn;
  589. FILE *dsti_fp;
  590. char **dsti_rdncomps; /* only set for new entries */
  591. savedlines *dsti_preludelines; /* only output once */
  592. savedlines *dsti_entrylines; /* output once for each entry */
  593. } dsgwtmplinfo;
  594. /*
  595. * HTML template directives that are specific to DSGW
  596. * Note that most of these supported only in entrydisplay.c
  597. */
  598. #define DRCT_DS_ENTRYBEGIN "DS_ENTRYBEGIN"
  599. #define DRCT_DS_ENTRYEND "DS_ENTRYEND"
  600. #define DRCT_DS_ATTRIBUTE "DS_ATTRIBUTE"
  601. #define DRCT_DS_ATTRVAL_SET "DS_ATTRVAL_SET"
  602. #define DRCT_DS_OBJECTCLASS "DS_OBJECTCLASS"
  603. #define DRCT_DS_SORTENTRIES "DS_SORTENTRIES"
  604. #define DRCT_DS_SEARCHDESC "DS_SEARCHDESC"
  605. #define DRCT_DS_POSTEDVALUE "DS_POSTEDVALUE"
  606. #define DRCT_DS_EDITBUTTON "DS_EDITBUTTON"
  607. #define DRCT_DS_DELETEBUTTON "DS_DELETEBUTTON"
  608. #define DRCT_DS_SAVEBUTTON "DS_SAVEBUTTON"
  609. #define DRCT_DS_RENAMEBUTTON "DS_RENAMEBUTTON"
  610. #define DRCT_DS_EDITASBUTTON "DS_EDITASBUTTON"
  611. #define DRCT_DS_NEWPASSWORD "DS_NEWPASSWORD"
  612. #define DRCT_DS_CONFIRM_NEWPASSWORD "DS_CONFIRM_NEWPASSWORD"
  613. #define DRCT_DS_OLDPASSWORD "DS_OLDPASSWORD"
  614. #define DRCT_DS_HELPBUTTON "DS_HELPBUTTON"
  615. #define DRCT_DS_CLOSEBUTTON "DS_CLOSEBUTTON"
  616. #define DRCT_DS_BEGIN_ENTRYFORM "DS_BEGIN_ENTRYFORM"
  617. #define DRCT_DS_END_ENTRYFORM "DS_END_ENTRYFORM"
  618. #define DRCT_DS_EMIT_BASE_HREF "DS_EMIT_BASE_HREF"
  619. #define DRCT_DS_DNATTR "DS_DNATTR"
  620. #define DRCT_DS_DNDESC "DS_DNDESC"
  621. #define DRCT_DS_DNEDITBUTTON "DS_DNEDITBUTTON"
  622. #define DRCT_DS_BEGIN_DNSEARCHFORM "DS_BEGIN_DNSEARCHFORM"
  623. #define DRCT_DS_END_DNSEARCHFORM "DS_END_DNSEARCHFORM"
  624. #define DRCT_DS_CONFIG_INFO "DS_CONFIG_INFO"
  625. #define DRCT_DS_GATEWAY_VERSION "DS_GATEWAY_VERSION"
  626. #define DRCT_DS_VIEW_SWITCHER "DS_VIEW_SWITCHER"
  627. #define DRCT_DS_STD_COMPLETION_JS "DS_STD_COMPLETION_JS"
  628. #define DRCT_HEAD "HEAD"
  629. #define DRCT_DS_ALERT_NOENTRIES "DS_ALERT_NOENTRIES"
  630. #define DRCT_DS_ORGCHARTLINK "DS_ORGCHARTLINK"
  631. /*
  632. * directives supported inside dsgw_parse_line() itself (usable anywhere)
  633. * Note that these are in addition to ones in the htmlparse.c templates array
  634. */
  635. #define DRCT_DS_LAST_OP_INFO "DS_LAST_OP_INFO"
  636. /*
  637. * directives supported by genscreen
  638. */
  639. #define DRCT_DS_LOCATIONPOPUP "DS_LOCATIONPOPUP"
  640. /*
  641. * these next few are supported by dsconfig
  642. */
  643. #define DRCT_DS_INLINE_POST_RESULTS "DS_INLINE_POST_RESULTS"
  644. #define DRCT_DS_CHECKED_IF_LOCAL "DS_CHECKED_IF_LOCAL"
  645. #define DRCT_DS_CHECKED_IF_REMOTE "DS_CHECKED_IF_REMOTE"
  646. #define DRCT_DS_HOSTNAME_VALUE "DS_HOSTNAME_VALUE"
  647. #define DRCT_DS_PORT_VALUE "DS_PORT_VALUE"
  648. #define DRCT_DS_CHECKED_IF_SSL "DS_CHECKED_IF_SSL"
  649. #define DRCT_DS_CHECKED_IF_NOSSL "DS_CHECKED_IF_NOSSL"
  650. #define DRCT_DS_SSL_CONFIG_VALUE "DS_SSL_CONFIG_VALUE"
  651. #define DRCT_DS_BASEDN_VALUE "DS_BASEDN_VALUE"
  652. #define DRCT_DS_BINDDN_VALUE "DS_BINDDN_VALUE"
  653. #define DRCT_DS_BINDPASSWD_VALUE "DS_BINDPASSWD_VALUE"
  654. #define DRCT_DS_NOCERTFILE_WARNING "DS_NOCERTFILE_WARNING"
  655. /*
  656. * directives supported by dsimpldif
  657. */
  658. #define DS_LDIF_FILE "DS_LDIF_FILE"
  659. #define DS_CHECKED_IF_ERASE "DS_CHECKED_IF_ERASE"
  660. #define DS_CHECKED_IF_NOTERASE "DS_CHECKED_IF_NOTERASE"
  661. #define DS_CHECKED_IF_STOP "DS_CHECKED_IF_STOP"
  662. #define DS_CHECKED_IF_NOTSTOP "DS_CHECKED_IF_NOTSTOP"
  663. #define DSGW_ARG_BUTTON_LABEL "label"
  664. #define DSGW_ARG_BUTTON_NAME "name"
  665. /*
  666. * directives supported by dsexpldif
  667. */
  668. #define DS_SUFFIX "DS_SUFFIX"
  669. /* conditionals -- replaces "xxx" in <!-- IF xxx --> directives */
  670. #define DSGW_COND_FOUNDENTRIES "FoundEntries"
  671. #define DSGW_COND_ADDING "Adding"
  672. #define DSGW_COND_EDITING "Editing"
  673. #define DSGW_COND_DISPLAYING "Displaying"
  674. #define DSGW_COND_BOUND "Bound"
  675. #define DSGW_COND_BOUNDASTHISENTRY "BoundAsThisEntry"
  676. #define DSGW_COND_ADMSERV "AdminServer"
  677. #define DSGW_COND_LOCALDB "DirectoryIsLocalDB"
  678. #define DSGW_COND_ATTRHASVALUES "AttributeHasValues"
  679. #define DSGW_COND_ATTRHASTHISVALUE "AttributeHasThisValue"
  680. #define DSGW_COND_POSTEDFORMVALUE "PostedFormValue"
  681. #define DSGW_COND_DISPLAYORGCHART "DisplayOrgChart"
  682. #define DSGW_COND_DISPLAYAIMPRESENCE "DisplayAimPresence"
  683. /* global variables */
  684. extern char *progname; /* set in dsgwutil.c:dsgw_init() */
  685. extern char *dsgw_last_op_info; /* set in edit.c and genscreen.c */
  686. extern char *dsgw_dnattr; /* set in edit.c */
  687. extern char *dsgw_dndesc; /* set in edit.c */
  688. extern int http_hdr_sent; /* set in dsgwutil.c:dsgw_send_header() */
  689. extern char *dsgw_html_body_colors; /* set in htmlparse.c */
  690. extern int dsgw_NSSInitializedAlready; /* set in cookie.c:dsgw_NSSInit */
  691. /* function prototypes */
  692. /*
  693. * in cgiutil.c
  694. */
  695. int dsgw_post_begin( FILE *in );
  696. void dsgw_form_unescape( char *str );
  697. char *dsgw_get_cgi_var( char *varname, int required );
  698. int dsgw_get_int_var( char *varname, int required, int defval );
  699. int dsgw_get_boolean_var( char *varname, int required, int defval );
  700. char *dsgw_get_escaped_cgi_var( char *varname_escaped, char *varname,
  701. int required );
  702. #define DSGW_CGIVAR_OPTIONAL 0
  703. #define DSGW_CGIVAR_REQUIRED 1
  704. char *dsgw_next_cgi_var( int *indexp, char **valuep );
  705. /*
  706. * in dsgwutil.c:
  707. */
  708. extern dsgwconfig *gc;
  709. int dsgw_init( int argc, char **argv, int methods_handled );
  710. int dsgw_simple_cond_is_true( int argc, char **argv, void *arg );
  711. char *dsgw_file2path( char *prefix, char *filename );
  712. char *dsgw_file2htmlpath( char *prefix, char *filename );
  713. void *dsgw_ch_malloc( size_t n );
  714. void *dsgw_ch_calloc( size_t nelem, size_t elsize );
  715. void *dsgw_ch_realloc( void *p, size_t n );
  716. char *dsgw_ch_strdup( const char *s );
  717. char *dsgw_escape_quotes( char *in );
  718. char *dsgw_get_translation( char *in );
  719. void dsgw_send_header();
  720. void dsgw_add_header( char *line );
  721. char *dsgw_get_auth_cookie();
  722. void dsgw_emit_helpbutton( char *topic );
  723. void dsgw_emit_homebutton();
  724. char *dsgw_build_urlprefix();
  725. void dsgw_init_searchprefs( struct ldap_searchobj **solistp );
  726. void dsgw_addtemplate( dsgwtmpl **tlpp, char *template, int count,
  727. char **ocvals );
  728. dsgwtmpl *dsgw_oc2template( char **ocvals );
  729. void dsgw_remove_leading_and_trailing_spaces( char **sp );
  730. int dsgw_parse_cookie( char *cookie, char **rndstr, char **dn );
  731. char *dsgw_getvp( int cginum );
  732. #ifdef DSGW_DEBUG
  733. void dsgw_log( char *fmt, ... );
  734. void dsgw_logstringarray( char *arrayname, char **strs );
  735. void dsgw_log_out (const char* s, size_t n);
  736. #else
  737. #define dsgw_log_out(s,n) ;
  738. #endif /* DSGW_DEBUG */
  739. void dsgw_head_begin();
  740. void dsgw_quote_emptyFrame();
  741. void dsgw_password_expired_alert( char *binddn );
  742. time_t dsgw_current_time();
  743. time_t dsgw_time_plus_sec (time_t l, long r);
  744. /*
  745. * in entrydisplay.c
  746. */
  747. dsgwtmplinfo *dsgw_display_init( int tmpltype, char *template,
  748. unsigned long options );
  749. void dsgw_display_entry( dsgwtmplinfo *tip, LDAP *ld, LDAPMessage *entry,
  750. LDAPMessage *attrsonly_entry, char *dn );
  751. void dsgw_display_done( dsgwtmplinfo *tip );
  752. char *dsgw_mls_convertlines( char *val, char *sep, int *linesp, int emitlines,
  753. int quote_html_specials );
  754. void dsgw_set_searchdesc( dsgwtmplinfo *tip, char*, char*, char*);
  755. void dsgw_set_search_result( dsgwtmplinfo *tip, int entrycount,
  756. char *searcherror, char *lderrtxt );
  757. /*
  758. * in error.c
  759. */
  760. void dsgw_error( int errcode, char *extra, int options, int lderr,
  761. char *lderrtxt );
  762. #define DSGW_ERROPT_EXIT 0x01
  763. #define DSGW_ERROPT_IGNORE 0x02
  764. #define DSGW_ERROPT_TERSE 0x04
  765. #define DSGW_ERROPT_INLINE 0x08
  766. #define DSGW_ERROPT_DURINGBIND 0x10
  767. int dsgw_dn2passwd_error( int ckrc, int skipauthwarning );
  768. char* dsgw_err2string( int err );
  769. char *dsgw_ldaperr2string( int lderr );
  770. /*
  771. * in htmlout.c
  772. */
  773. void dsgw_html_begin( char *title, int titleinbody );
  774. void dsgw_html_end( void );
  775. void dsgw_html_href( char *urlprefix, char *url, char *label, char *value,
  776. char *extra );
  777. void dsgw_strcat_escaped( char *s1, const char *s2 );
  778. char *dsgw_strdup_escaped( const char *s );
  779. void dsgw_substitute_and_output( char *s, char *tag, char *value, int escape );
  780. void dsgw_form_begin( const char* name, const char* format, ... );
  781. char *dsgw_strdup_with_entities( char *s, int *madecopyp );
  782. void dsgw_HTML_emits( char * );
  783. void dsgw_emit_cgi_var( int argc, char **argv );
  784. void dsgw_emit_button( int argc, char **argv, const char* format, ... );
  785. void dsgw_emit_alertForm();
  786. void dsgw_emit_alert( const char* frame, const char* windowOptions, const char* fmt, ... );
  787. void dsgw_emit_confirmForm();
  788. void dsgw_emit_confirm( const char* frame, const char* yes, const char* no,
  789. const char* windowOptions, int enquote, const char* fmt, ... );
  790. /*
  791. * in htmlparse.c:
  792. */
  793. typedef int (*condfunc)( int argc, char **argv, void *arg );
  794. int dsgw_parse_line( char *line_input, int *argc, char ***argv, int parseonly,
  795. condfunc conditionalfn, void *condarg );
  796. char *get_arg_by_name( char *name, int argc, char **argv );
  797. int dsgw_get_arg_pos_by_name( char *name, int argc, char **argv );
  798. FILE *dsgw_open_html_file( char *filename, int erropts );
  799. int dsgw_next_html_line(FILE *f, char *line);
  800. void dsgw_argv_free( char **argv );
  801. savedlines *dsgw_savelines_alloc( void );
  802. void dsgw_savelines_free( savedlines *svlp );
  803. void dsgw_savelines_save( savedlines *svlp, char *line );
  804. void dsgw_savelines_rewind( savedlines *svlp );
  805. char *dsgw_savelines_next( savedlines *svlp );
  806. int dsgw_directive_is(char *target, char *directive);
  807. /*
  808. * in ldaputil.c
  809. */
  810. int dsgw_init_ldap( LDAP **ldp, LDAPFiltDesc **lfdpp, int skipac, int skipauthwarning );
  811. int dsgw_get_adm_identity( LDAP *ld, char **uidp, char **dnp, char **pwdp,
  812. int erropts );
  813. void dsgw_ldap_error( LDAP *ld, int erropts );
  814. struct ldap_searchobj *dsgw_type2searchobj( struct ldap_searchobj *solistp,
  815. char *type );
  816. struct ldap_searchattr *dsgw_label2searchattr( struct ldap_searchobj *sop,
  817. char *label );
  818. struct ldap_searchmatch *dsgw_prompt2searchmatch( struct ldap_searchobj *sop,
  819. char *prompt );
  820. void dsgw_smart_search( LDAP *ld, struct ldap_searchobj *sop,
  821. LDAPFiltDesc *lfdp, char *base, char *value, unsigned long options );
  822. void dsgw_pattern_search( LDAP *ld, char *listtmpl,
  823. char *searchdesc2, char *searchdesc3, char *searchdesc4,
  824. char *filtpattern, char *filtprefix, char *filtsuffix, char *attr,
  825. char *base, int scope, char *value, unsigned long options );
  826. void dsgw_ldapurl_search( LDAP *ld, char *ldapurl );
  827. void dsgw_read_entry( LDAP *ld, char *dn, char **ocvals, char *tmplname,
  828. char **attrs, unsigned long options );
  829. int dsgw_ldap_entry_exists( LDAP *ld, char *dn, char **matchedp,
  830. unsigned long erropts );
  831. char **dsgw_rdn_values( char *dn );
  832. char *dsgw_get_binddn( void );
  833. int dsgw_bound_as_dn( char *dn, int def_answer );
  834. int dsgw_dn_cmp( char *dn1, char *dn2 );
  835. int dsgw_is_dnparent( char *dn1, char *dn2 );
  836. char *dsgw_dn_parent( char *dn );
  837. void dsgw_emit_location_popup( LDAP *ld, int argc, char **argv, int erropts );
  838. /*
  839. * in config.c
  840. */
  841. dsgwconfig *dsgw_read_config();
  842. int dsgw_update_dbswitch( dsgwconfig *cfgp, char *handle, int erropts );
  843. int dsgw_valid_docname(char *filename);
  844. char *dsgw_get_docdir(void) ;
  845. typedef struct scriptrange {
  846. unsigned long sr_min;
  847. unsigned long sr_max;
  848. struct scriptrange* sr_next;
  849. } scriptrange_t;
  850. typedef struct scriptorder {
  851. unsigned so_caseIgnoreAccents;
  852. scriptrange_t** so_sort;
  853. scriptrange_t** so_display;
  854. } scriptorder_t;
  855. scriptorder_t* dsgw_scriptorder();
  856. /*
  857. * in cookie.c
  858. */
  859. char *dsgw_mkcookie();
  860. int dsgw_ckdn2passwd( char *cookie, char *dn, char **ret_pw );
  861. int dsgw_storecookie( char *cookie, char *dn, char *password, time_t expires );
  862. void dsgw_traverse_db();
  863. char *dsgw_t2gmts( time_t cktime );
  864. int dsgw_delcookie( char *cookie );
  865. void dsgw_closecookiedb( FILE *fp );
  866. FILE *dsgw_opencookiedb();
  867. time_t dsgw_getlastpurged( FILE *fp );
  868. int dsgw_purgedatabase( char *dn );
  869. /*
  870. * in emitauth.c
  871. */
  872. void dsgw_emit_auth_form( char *binddn );
  873. void dsgw_emit_auth_dest( char *binddn, char* authdesturl );
  874. /*
  875. * in emitf.c
  876. */
  877. int dsgw_emits (const char* s); /* like fputs(s, stdout) */
  878. int dsgw_emitf (const char* format, ...); /* like printf */
  879. int dsgw_emitfv (const char* format, va_list argl);
  880. char* dsgw_emit_converts_to (char* charset);
  881. int is_UTF_8 (const char* charset);
  882. void* dsgw_emitn (void*, const char* buf, size_t len);
  883. size_t dsgw_fputn (FILE*, const char* buf, size_t len);
  884. #define QUOTATION_JAVASCRIPT 2
  885. #define QUOTATION_JAVASCRIPT_MULTILINE 3
  886. void dsgw_quotation_begin (int kind);
  887. void dsgw_quotation_end();
  888. int dsgw_quote_emits (int kind, const char* s);
  889. int dsgw_quote_emitf (int kind, const char* format, ...);
  890. /*
  891. * in collate.c
  892. */
  893. #define CASE_EXACT 0
  894. #define CASE_INSENSITIVE 1
  895. typedef int (*strcmp_t) (const char*, const char*);
  896. strcmp_t dsgw_strcmp (int);
  897. typedef int (*valcmp_t) (const char**, const char**);
  898. valcmp_t dsgw_valcmp (int);
  899. extern struct berval* dsgw_strkeygen (int, const char*);
  900. extern struct berval* dsgw_key_first;
  901. extern struct berval* dsgw_key_last;
  902. int LDAP_C LDAP_CALLBACK dsgw_keycmp (void*, const struct berval*, const struct berval*);
  903. void LDAP_C LDAP_CALLBACK dsgw_keyfree(void*, const struct berval*);
  904. /*
  905. * in vcard.c
  906. */
  907. void dsgw_vcard_from_entry( LDAP *ld, char *dn, char *mimetype );
  908. /*
  909. * utf8compare.c
  910. */
  911. int dsgw_utf8casecmp(unsigned char *s0, unsigned char *s1);
  912. int dsgw_utf8ncasecmp(unsigned char *s0, unsigned char *s1, int n);
  913. /*
  914. * dsgwutil.c
  915. */
  916. /******************** Accept Language List ************************/\
  917. #if 0 /* defined in i18n.h */
  918. #define MAX_ACCEPT_LANGUAGE 16
  919. #define MAX_ACCEPT_LENGTH 18
  920. typedef char ACCEPT_LANGUAGE_LIST[MAX_ACCEPT_LANGUAGE][MAX_ACCEPT_LENGTH];
  921. #endif /* MAX_ACCEPT_LANGUAGE */
  922. /* AcceptLangList
  923. *
  924. * Will parse an Accept-Language string of the form
  925. * "en;q=1.0,fr;q=0.9..."
  926. * The ACCEPT_LANGUAGE_LIST array will be loaded with the ordered
  927. * language elements based on the priority of the languages specified.
  928. * The number of languages will be returned as the result of the
  929. * call.
  930. */
  931. size_t
  932. AcceptLangList(
  933. const char * acceptLanguage,
  934. ACCEPT_LANGUAGE_LIST acceptLanguageList
  935. );
  936. /*
  937. * converts a buffer of characters to/from UTF8 from/to a native charset
  938. * the given converter will handle the native charset
  939. * returns 0 if not all of source was converted, 1 if all of source
  940. * was converted, -1 upon error
  941. * all of source will be converted if there is enough room in dest to contain
  942. * the entire conversion, or if dest is null and we are malloc'ing space for dest
  943. */
  944. int
  945. dsgw_convert(
  946. int direction, /* DSGW_TO_UTF8 or DSGW_FROM_UTF8 */
  947. UConverter *nativeConv, /* convert from/to native charset */
  948. char **dest, /* *dest is the destination buffer - if *dest == NULL, it will be malloced */
  949. size_t destSize, /* size of dest buffer (ignored if *dest == NULL) */
  950. size_t *nDest, /* number of chars written to dest */
  951. const char *source, /* source buffer to convert - either in native encoding (to) or utf8 (from) */
  952. size_t sourceSize, /* size of source buffer - if 0, assume source is NULL terminated */
  953. size_t *nSource, /* number of chars read from source buffer */
  954. UErrorCode *pErrorCode /* will be reset each time through */
  955. );
  956. #define DSGW_TO_UTF8 0
  957. #define DSGW_FROM_UTF8 1