dsalib.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. #ifndef __dsalib_h
  7. #define __dsalib_h
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <stdarg.h>
  11. #ifdef HPUX
  12. #include <limits.h> /* for PATH_MAX */
  13. #endif
  14. /* error types */
  15. #define DS_FILE_ERROR 0
  16. #define DS_MEMORY_ERROR 1
  17. #define DS_SYSTEM_ERROR 2
  18. #define DS_INCORRECT_USAGE 3
  19. #define DS_ELEM_MISSING 4
  20. #define DS_REGISTRY_DATABASE_ERROR 5
  21. #define DS_NETWORK_ERROR 6
  22. #define DS_GENERAL_FAILURE 7
  23. #define DS_WARNING 8
  24. /* The upper bound on error types */
  25. #define DS_MAX_ERROR 9
  26. /* The default error type (in case something goes wrong */
  27. #define DS_DEFAULT_ERROR 3
  28. #ifndef BIG_LINE
  29. #define BIG_LINE 1024
  30. #endif
  31. #ifndef PATH_MAX
  32. #if defined( _WIN32 )
  33. #define PATH_MAX _MAX_PATH
  34. #else
  35. #define PATH_MAX 256
  36. #endif /* _WIN32 */
  37. #endif /* PATH_MAX */
  38. #ifndef HTML_ERRCOLOR
  39. #define HTML_ERRCOLOR "#AA0000"
  40. #endif
  41. #ifndef CONTENT_NAME
  42. #define CONTENT_NAME "content"
  43. #endif
  44. #ifdef XP_UNIX
  45. #define FILE_PATHSEP '/'
  46. #define FILE_PATHSEPP "/"
  47. #define FILE_PARENT "../"
  48. #define WSACleanup()
  49. #elif defined(XP_WIN32)
  50. #define FILE_PATHSEP '/'
  51. #define FILE_PATHSEPP "\\\\"
  52. #define FILE_PARENT "..\\"
  53. #endif /* XP_WIN32 */
  54. #define PATH_SIZE 1024
  55. #define ERR_SIZE 8192
  56. /*
  57. NT doesn't strictly need these, but the libadmin API which is emulated
  58. below uses them.
  59. */
  60. #define NEWSCRIPT_MODE 0755
  61. #define NEWFILE_MODE 0644
  62. #define NEWDIR_MODE 0755
  63. #if defined( XP_WIN32 )
  64. #define DS_EXPORT_SYMBOL __declspec( dllexport )
  65. #else
  66. #define DS_EXPORT_SYMBOL
  67. #endif
  68. #if defined( XP_WIN32 )
  69. #define ENQUOTE "\""
  70. #else
  71. #define ENQUOTE ""
  72. #endif
  73. #ifndef FILE_SEP
  74. #ifdef XP_WIN32
  75. #define FILE_SEP '\\'
  76. #else
  77. #define FILE_SEP '/'
  78. #endif
  79. #endif
  80. #if defined( XP_WIN32 )
  81. #define PATH_FOR_PLATFORM(_path) ds_unixtodospath(_path)
  82. #else
  83. #define PATH_FOR_PLATFORM(_path)
  84. #endif
  85. #define START_SCRIPT "start-slapd"
  86. #define RESTART_SCRIPT "restart-slapd"
  87. #define STOP_SCRIPT "stop-slapd"
  88. #if defined( XP_WIN32 )
  89. #define SLAPD_NAME "slapd"
  90. #else
  91. #define SLAPD_NAME "ns-slapd"
  92. #endif
  93. #define MOCHA_NAME "JavaScript"
  94. /*
  95. * Return values from ds_get_updown_status()
  96. */
  97. #define DS_SERVER_UP 1
  98. #define DS_SERVER_DOWN 0
  99. #define DS_SERVER_UNKNOWN -1
  100. /*
  101. * Return values from ds_bring_up_server()
  102. */
  103. #define DS_SERVER_ALREADY_UP -2
  104. #define DS_SERVER_ALREADY_DOWN -3
  105. #define DS_SERVER_PORT_IN_USE -4
  106. #define DS_SERVER_MAX_SEMAPHORES -5
  107. #define DS_SERVER_CORRUPTED_DB -6
  108. #define DS_SERVER_NO_RESOURCES -7
  109. #define DS_SERVER_COULD_NOT_START -8
  110. /*
  111. * Other return values
  112. */
  113. #define DS_UNKNOWN_ERROR -1
  114. #define DS_NO_SERVER_ROOT -10
  115. #define DS_CANNOT_EXEC -11
  116. #define DS_CANNOT_OPEN_STAT_FILE -12
  117. #define DS_NULL_PARAMETER -13
  118. #define DS_SERVER_MUST_BE_DOWN -14
  119. #define DS_CANNOT_OPEN_BACKUP_FILE -15
  120. #define DS_NOT_A_DIRECTORY -16
  121. #define DS_CANNOT_CREATE_DIRECTORY -17
  122. #define DS_CANNOT_OPEN_LDIF_FILE -18
  123. #define DS_IS_A_DIRECTORY -19
  124. #define DS_CANNOT_CREATE_FILE -20
  125. #define DS_UNDEFINED_VARIABLE -21
  126. #define DS_NO_SUCH_FILE -22
  127. #define DS_CANNOT_DELETE_FILE -23
  128. #define DS_UNKNOWN_SNMP_COMMAND -24
  129. #define DS_NON_NUMERIC_VALUE -25
  130. #define DS_NO_LOGFILE_NAME -26
  131. #define DS_CANNOT_OPEN_LOG_FILE -27
  132. #define DS_HAS_TOBE_READONLY_MODE -28
  133. #define DS_INVALID_LDIF_FILE -29
  134. /*
  135. * Types of config files.
  136. */
  137. #define DS_REAL_CONFIG 1
  138. #define DS_TMP_CONFIG 2
  139. /*
  140. * Maximum numeric value we will accept in admin interface
  141. * We may at some point need per-option bounds, but for now,
  142. * there's just one global maximum.
  143. */
  144. #define DS_MAX_NUMERIC_VALUE 4294967295 /* 2^32 - 1 */
  145. /* Use our own macro for rpt_err, so we can put our own error code in
  146. NMC_STATUS */
  147. #undef rpt_err
  148. #define rpt_err(CODE, STR1, STR2, STR3) \
  149. fprintf( stdout, "NMC_ErrInfo: %s\n", (STR1) ); \
  150. fprintf( stdout, "NMC_STATUS: %d\n", CODE )
  151. /*
  152. * Flags for ds_display_config()
  153. */
  154. #define DS_DISP_HRB 1 /* horizontal line to begin with */
  155. #define DS_DISP_HRE 2 /* horizontal line to end with */
  156. #define DS_DISP_TB 4 /* table begin */
  157. #define DS_DISP_TE 8 /* table end */
  158. #define DS_DISP_EOL 16 /* End Of Line */
  159. #define DS_DISP_NOMT 32 /* display only non empty */
  160. #define DS_DISP_NOIN 64 /* display with no input field */
  161. #define DS_DISP_HELP 128 /* display with a help button */
  162. #define DS_DISP_PLAIN 256 /* No table, no nothin */
  163. #define DS_SIMPLE (DS_DISP_EOL | DS_DISP_NOIN | DS_DISP_HELP)
  164. /*
  165. * dci_type for ds_cfg_info
  166. */
  167. #define DS_ATTR_STRING 1
  168. #define DS_ATTR_NUMBER 2
  169. #define DS_ATTR_ONOFF 3
  170. #define DS_ATTR_LIMIT 4 /* a number where -1 is displayed as blank */
  171. struct ds_cfg_info {
  172. char *dci_varname;
  173. char *dci_display;
  174. int dci_type;
  175. char *dci_help;
  176. };
  177. extern struct ds_cfg_info ds_cfg_info[];
  178. #define LDBM_DATA_SIZE 5
  179. /*ldbm specific backend information*/
  180. struct ldbm_data {
  181. char *tv[LDBM_DATA_SIZE][2]; /*type and value*/
  182. };
  183. /*
  184. * varname for ds_showparam()
  185. * NOTE: these must be kept in synch with the ds_cfg_info array defined
  186. * in ../lib/dsalib_conf.c
  187. */
  188. #define DS_LOGLEVEL 0
  189. #define DS_REFERRAL 1
  190. #define DS_AUDITFILE 2
  191. #define DS_LOCALHOST 3
  192. #define DS_PORT 4
  193. #define DS_SECURITY 5
  194. #define DS_SECURE_PORT 6
  195. #define DS_SSL3CIPHERS 7
  196. #define DS_PASSWDHASH 8
  197. #define DS_ACCESSLOG 9
  198. #define DS_ERRORLOG 10
  199. #define DS_ROOTDN 11
  200. #define DS_ROOTPW 12
  201. #define DS_SUFFIX 13
  202. #define DS_LOCALUSER 14
  203. #define DS_CFG_MAX 15 /* MUST be one greater than the last option */
  204. /* These control how long we wait for the server to start up or shutdown */
  205. #define SERVER_START_TIMEOUT 600 /* seconds */
  206. #define SERVER_STOP_TIMEOUT SERVER_START_TIMEOUT /* same as start timeout */
  207. typedef int (*DS_RM_RF_ERR_FUNC)(const char *path, const char *op, void *arg);
  208. #ifdef __cplusplus
  209. extern "C" {
  210. #endif /* __cplusplus */
  211. extern DS_EXPORT_SYMBOL char *ds_get_server_root();
  212. extern DS_EXPORT_SYMBOL char *ds_get_install_root();
  213. extern DS_EXPORT_SYMBOL char *ds_get_admserv_based_root();
  214. extern DS_EXPORT_SYMBOL void ds_log_debug_message(char *msg);
  215. extern DS_EXPORT_SYMBOL void ds_log_env(char **envp);
  216. extern DS_EXPORT_SYMBOL int ds_get_updown_status();
  217. extern DS_EXPORT_SYMBOL void ds_print_startstop(int stop);
  218. extern DS_EXPORT_SYMBOL int ds_bring_up_server_install(int verbose,
  219. char *root, char *errorlog);
  220. extern DS_EXPORT_SYMBOL int ds_bring_up_server(int verbose);
  221. extern DS_EXPORT_SYMBOL char *ds_get_server_name();
  222. extern DS_EXPORT_SYMBOL void ds_send_error(char *errstr, int print_errno);
  223. extern DS_EXPORT_SYMBOL void ds_send_status(char *str);
  224. extern DS_EXPORT_SYMBOL char *ds_get_cgi_var(char *cgi_var_name);
  225. extern DS_EXPORT_SYMBOL char *ds_get_cgi_var_simple(int index);
  226. extern DS_EXPORT_SYMBOL char *ds_get_cgi_multiple(char *cgi_var_name);
  227. extern DS_EXPORT_SYMBOL char *ds_get_errors_name();
  228. extern DS_EXPORT_SYMBOL char *ds_get_access_name();
  229. extern DS_EXPORT_SYMBOL char *ds_get_audit_name();
  230. extern DS_EXPORT_SYMBOL char *ds_get_logfile_name(int config_type);
  231. extern DS_EXPORT_SYMBOL int ds_bring_down_server();
  232. extern DS_EXPORT_SYMBOL void ds_print_server_status(int isrunning);
  233. extern DS_EXPORT_SYMBOL int ds_get_file_size(char *fileName);
  234. extern DS_EXPORT_SYMBOL void ds_display_tail(char *fileName, int timeOut,
  235. int startSeek, char *doneMsg, char *lastLine);
  236. extern DS_EXPORT_SYMBOL char **ds_get_ldif_files();
  237. extern DS_EXPORT_SYMBOL int ds_ldif2db_preserve(char *file);
  238. extern DS_EXPORT_SYMBOL int ds_ldif2db(char *file);
  239. extern DS_EXPORT_SYMBOL int ds_ldif2db_backend_subtree(char *file, char *backend, char *subtree);
  240. extern DS_EXPORT_SYMBOL int ds_db2ldif(char *file);
  241. extern DS_EXPORT_SYMBOL int ds_vlvindex(char **backendList, char **attrList);
  242. extern DS_EXPORT_SYMBOL int ds_addindex(char **attrList, char *backendName);
  243. extern DS_EXPORT_SYMBOL int ds_db2ldif_subtree(char *file, char *subtree);
  244. extern DS_EXPORT_SYMBOL char **ds_get_bak_dirs();
  245. extern DS_EXPORT_SYMBOL int ds_db2bak(char *file);
  246. extern DS_EXPORT_SYMBOL int ds_bak2db(char *file);
  247. extern DS_EXPORT_SYMBOL int ds_get_monitor(int frontend, char *port);
  248. extern DS_EXPORT_SYMBOL int ds_get_bemonitor(char *bemdn, char *port);
  249. extern DS_EXPORT_SYMBOL int ds_client_access(char *port, char *dn);
  250. extern DS_EXPORT_SYMBOL char **ds_get_config(int type);
  251. extern DS_EXPORT_SYMBOL char *ds_get_pwenc(char *passwd_hash, char *password);
  252. extern DS_EXPORT_SYMBOL int ds_check_config(int type);
  253. extern DS_EXPORT_SYMBOL int ds_check_pw(char *pwhash, char *pwclear);
  254. extern DS_EXPORT_SYMBOL int ds_set_config(char *change_file_name);
  255. extern DS_EXPORT_SYMBOL char **ds_get_conf_from_file(FILE *conf);
  256. extern DS_EXPORT_SYMBOL void ds_display_config(char **ds_config);
  257. extern DS_EXPORT_SYMBOL char *ds_get_var_name(int varnum);
  258. extern DS_EXPORT_SYMBOL int ds_showparam(char **ds_config, int varname, int phase,
  259. int occurance, char *dispname, int size, int maxlength, unsigned flags,
  260. char *url);
  261. extern DS_EXPORT_SYMBOL void ds_show_pwmaxage(char *value);
  262. extern DS_EXPORT_SYMBOL void ds_show_pwhash(char *value);
  263. extern DS_EXPORT_SYMBOL char *ds_get_value(char **ds_config, char *parm, int phase, int occurance);
  264. extern DS_EXPORT_SYMBOL void ds_apply_cfg_changes(int param_list[], int changed);
  265. extern DS_EXPORT_SYMBOL int ds_commit_cfg_changes();
  266. extern DS_EXPORT_SYMBOL int ds_config_updated();
  267. extern DS_EXPORT_SYMBOL void ds_display_header(char *font_size, char *header);
  268. extern DS_EXPORT_SYMBOL void ds_display_message(char *font_size, char *header);
  269. extern DS_EXPORT_SYMBOL void ds_print_file_form(char *action, char *fileptr, char *full_fileptr);
  270. extern DS_EXPORT_SYMBOL char *ds_get_file_meaning(char *file);
  271. extern DS_EXPORT_SYMBOL void ds_print_file_name(char *fileptr);
  272. extern DS_EXPORT_SYMBOL int ds_file_exists(char *filename);
  273. extern DS_EXPORT_SYMBOL int ds_cp_file(char *sfile, char *dfile, int mode);
  274. extern DS_EXPORT_SYMBOL time_t ds_get_mtime(char *filename);
  275. extern DS_EXPORT_SYMBOL char *ds_get_config_value( int option );
  276. extern DS_EXPORT_SYMBOL char **ds_get_file_list( char *dir );
  277. extern DS_EXPORT_SYMBOL char *ds_get_tmp_dir();
  278. extern DS_EXPORT_SYMBOL void ds_unixtodospath(char *szText);
  279. extern DS_EXPORT_SYMBOL void ds_timetofname(char *szText);
  280. extern DS_EXPORT_SYMBOL void ds_dostounixpath(char *szText);
  281. extern DS_EXPORT_SYMBOL int ds_saferename(char *szSrc, char *szTarget);
  282. extern DS_EXPORT_SYMBOL char *get_specific_help_button(char *help_link,
  283. char *dispname, char *helpinfo);
  284. /* Change the DN to a canonical format (in place); return DN. */
  285. extern DS_EXPORT_SYMBOL char* dn_normalize (char* DN);
  286. /* Change the DN to a canonical format (in place) and convert to v3; return DN. */
  287. extern DS_EXPORT_SYMBOL char* dn_normalize_convert (char* DN);
  288. /* if dn contains an unescaped quote return true */
  289. extern DS_EXPORT_SYMBOL int ds_dn_uses_LDAPv2_quoting(const char *dn);
  290. /* Return a copy of the DN, but with optional whitespace inserted. */
  291. extern DS_EXPORT_SYMBOL char* ds_dn_expand (char* DN);
  292. /* Return the value if it can be stored 'as is' in a config file.
  293. If it requires enquoting, allocate and return its enquoted form.
  294. The caller should free() the returned pointer iff it's != value.
  295. On Windows, we don't want to double up on "\" characters in filespecs,
  296. so we need to pass in the value type */
  297. extern DS_EXPORT_SYMBOL char* ds_enquote_config_value (int paramnum, char* value);
  298. /*
  299. * Bring up a javascript alert.
  300. */
  301. extern DS_EXPORT_SYMBOL void ds_alert_user(char *header, char *message);
  302. /* Construct and return the DN that corresponds to the give DNS name.
  303. The caller should free() the returned pointer. */
  304. extern DS_EXPORT_SYMBOL char* ds_DNS_to_DN (char* DNS);
  305. /* Construct and return the DN of the LDAP server's own entry.
  306. The caller must NOT free() the returned pointer. */
  307. extern DS_EXPORT_SYMBOL char* ds_get_config_DN (char** ds_config);
  308. /* Encode characters, as described in RFC 1738 section 2.2,
  309. if they're 'unsafe' (as defined in RFC 1738), or '?' or
  310. <special> (as defined in RFC 1779).
  311. The caller should free() the returned pointer. */
  312. extern DS_EXPORT_SYMBOL char* ds_URL_encode (const char*);
  313. /* Decode characters, as described in RFC 1738 section 2.2.
  314. The caller should free() the returned pointer. */
  315. extern DS_EXPORT_SYMBOL char* ds_URL_decode (const char*);
  316. /* Encode all characters, even if 'safe' */
  317. extern DS_EXPORT_SYMBOL char* ds_encode_all (const char*);
  318. /* Change the effective UID and GID of this process to
  319. those associated with the given localuser (if any). */
  320. extern DS_EXPORT_SYMBOL char* ds_become_localuser_name (char* localuser);
  321. /* Change the effective UID and GID of this process to
  322. those associated with ds_config's localuser (if any). */
  323. extern DS_EXPORT_SYMBOL char* ds_become_localuser (char** ds_config);
  324. /* Change the effective UID and GID of this process back to
  325. what they were before calling ds_become_localuser(). */
  326. extern DS_EXPORT_SYMBOL char* ds_become_original();
  327. extern DS_EXPORT_SYMBOL char* ds_makeshort(char *filepath);
  328. extern DS_EXPORT_SYMBOL int ds_search_file(char *filename, char *searchstring);
  329. /* Begin parsing a POST in a CGI context */
  330. extern DS_EXPORT_SYMBOL int ds_post_begin(FILE *input);
  331. /* Begin parsing a GET in a CGI context */
  332. extern DS_EXPORT_SYMBOL void ds_get_begin(char *query_string);
  333. /* Display an error to the user and exit from a CGI */
  334. extern DS_EXPORT_SYMBOL void ds_report_error(int type, char *errmsg, char *details);
  335. /* Display a warning to the user */
  336. extern DS_EXPORT_SYMBOL void ds_report_warning(int type, char *errmsg, char *details);
  337. /* These functions are used by the program to alter the output behaviour
  338. if not executing in a CGI context */
  339. extern DS_EXPORT_SYMBOL int ds_get_formatted_output(void);
  340. extern DS_EXPORT_SYMBOL void ds_set_formatted_output(int val);
  341. /* return the value of a CGI variable */
  342. extern DS_EXPORT_SYMBOL char *ds_a_get_cgi_var(char *varname, char *elem_id, char *bongmsg);
  343. /* return a multi-valued CGI variable */
  344. extern DS_EXPORT_SYMBOL char **ds_a_get_cgi_multiple(char *varname, char *elem_id, char *bongmsg);
  345. /* open an html file */
  346. extern DS_EXPORT_SYMBOL FILE *ds_open_html_file(char *filename);
  347. /* show a message to be parsed by the non-HTML front end */
  348. extern DS_EXPORT_SYMBOL void ds_show_message(const char *message);
  349. /* show a key/value pair to be parsed by the non-HTML front end */
  350. extern DS_EXPORT_SYMBOL void ds_show_key_value(char *key, char *value);
  351. extern DS_EXPORT_SYMBOL void ds_submit(char *helptarget) ;
  352. extern DS_EXPORT_SYMBOL char *ds_get_helpbutton(char *topic);
  353. extern DS_EXPORT_SYMBOL void alter_startup_line(char *startup_line);
  354. extern DS_EXPORT_SYMBOL int ds_dir_exists(char *fn);
  355. extern DS_EXPORT_SYMBOL int ds_mkdir(char *dir, int mode);
  356. extern DS_EXPORT_SYMBOL char *ds_mkdir_p(char *dir, int mode);
  357. extern DS_EXPORT_SYMBOL char *ds_salted_sha1_pw_enc (char* pwd);
  358. extern DS_EXPORT_SYMBOL char * ds_escape_for_shell( char *s );
  359. extern DS_EXPORT_SYMBOL char **ds_string_to_vec(char *s);
  360. extern DS_EXPORT_SYMBOL char *ds_system_errmsg(void);
  361. extern DS_EXPORT_SYMBOL int ds_exec_and_report(char *cmd);
  362. /* remove a directory hierarchy - if the error function is given, it will be called upon
  363. error (e.g. directory not readable, cannot remove file, etc.) - if the callback function
  364. returns 0, this means to abort the removal, otherwise, continue
  365. */
  366. extern DS_EXPORT_SYMBOL int ds_rm_rf(const char *dir, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg);
  367. /*
  368. remove a registry key and report an error message if unsuccessful
  369. */
  370. extern DS_EXPORT_SYMBOL int ds_remove_reg_key(void *base, const char *format, ...);
  371. #ifdef __cplusplus
  372. }
  373. #endif /* __cplusplus */
  374. #endif /* __dsalib_h */