summaryrefslogtreecommitdiffstats
path: root/ldap/admin/include/dsalib.h
blob: 6f137cf7c0c11404533942961e42abe6476422f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/** BEGIN COPYRIGHT BLOCK
 * This Program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; version 2 of the License.
 * 
 * This Program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA.
 * 
 * In addition, as a special exception, Red Hat, Inc. gives You the additional
 * right to link the code of this Program with code not covered under the GNU
 * General Public License ("Non-GPL Code") and to distribute linked combinations
 * including the two, subject to the limitations in this paragraph. Non-GPL Code
 * permitted under this exception must only link to the code of this Program
 * through those well defined interfaces identified in the file named EXCEPTION
 * found in the source code files (the "Approved Interfaces"). The files of
 * Non-GPL Code may instantiate templates or use macros or inline functions from
 * the Approved Interfaces without causing the resulting work to be covered by
 * the GNU General Public License. Only Red Hat, Inc. may make changes or
 * additions to the list of Approved Interfaces. You must obey the GNU General
 * Public License in all respects for all of the Program code and other code used
 * in conjunction with the Program except the Non-GPL Code covered by this
 * exception. If you modify this file, you may extend this exception to your
 * version of the file, but you are not obligated to do so. If you do not wish to
 * provide this exception without modification, you must delete this exception
 * statement from your version and license this file solely under the GPL without
 * exception. 
 * 
 * 
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/

#ifndef __dsalib_h
#define __dsalib_h

#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#ifdef HPUX
#include <limits.h> /* for PATH_MAX */
#endif

/* error types */
#define DS_FILE_ERROR 0
#define DS_MEMORY_ERROR 1
#define DS_SYSTEM_ERROR 2
#define DS_INCORRECT_USAGE 3
#define DS_ELEM_MISSING 4
#define DS_REGISTRY_DATABASE_ERROR 5
#define DS_NETWORK_ERROR 6
#define DS_GENERAL_FAILURE 7
#define DS_WARNING 8

/* The upper bound on error types */
#define DS_MAX_ERROR 9

/* The default error type (in case something goes wrong */
#define DS_DEFAULT_ERROR 3

#ifndef BIG_LINE
#define	BIG_LINE	1024
#endif
#ifndef PATH_MAX
#if defined( _WIN32 )
#define PATH_MAX _MAX_PATH
#else
#define PATH_MAX 256
#endif /* _WIN32 */
#endif /* PATH_MAX */
#ifndef HTML_ERRCOLOR
#define HTML_ERRCOLOR "#AA0000"
#endif
#ifndef CONTENT_NAME
#define CONTENT_NAME "content"
#endif

#ifdef XP_UNIX

#define FILE_PATHSEP '/'
#define FILE_PATHSEPP "/"
#define FILE_PARENT "../"
#define WSACleanup()

#elif defined(XP_WIN32)

#define FILE_PATHSEP '/'
#define FILE_PATHSEPP "\\\\"
#define FILE_PARENT "..\\"

#endif /* XP_WIN32 */

#define PATH_SIZE 1024
#define ERR_SIZE 8192

/* 
   NT doesn't strictly need these, but the libadmin API which is emulated
   below uses them.
 */
#define NEWSCRIPT_MODE 0755
#define NEWFILE_MODE 0644
#define NEWDIR_MODE 0755

#if defined( XP_WIN32 )
#define DS_EXPORT_SYMBOL   __declspec( dllexport ) 
#else
#define DS_EXPORT_SYMBOL  
#endif

#if defined( XP_WIN32 )
#define ENQUOTE "\""
#else
#define ENQUOTE ""
#endif

#ifndef FILE_SEP
#ifdef XP_WIN32
  #define FILE_SEP '\\'
#else
  #define FILE_SEP '/'
#endif
#endif

#if defined( XP_WIN32 )
  #define PATH_FOR_PLATFORM(_path) ds_unixtodospath(_path)
#else
  #define PATH_FOR_PLATFORM(_path)
#endif

#define START_SCRIPT "start-slapd"
#define RESTART_SCRIPT "restart-slapd"
#define STOP_SCRIPT "stop-slapd"

#if defined( XP_WIN32 )
#define SLAPD_NAME "slapd"
#else
#define SLAPD_NAME "ns-slapd"
#endif

#define MOCHA_NAME "JavaScript"

/*
 * Return values from ds_get_updown_status()
 */
#define	DS_SERVER_UP		1
#define	DS_SERVER_DOWN		0
#define	DS_SERVER_UNKNOWN	-1
/*
 * Return values from ds_bring_up_server()
 */
#define	DS_SERVER_ALREADY_UP	-2
#define	DS_SERVER_ALREADY_DOWN	-3
#define	DS_SERVER_PORT_IN_USE		-4
#define	DS_SERVER_MAX_SEMAPHORES	-5
#define	DS_SERVER_CORRUPTED_DB		-6
#define	DS_SERVER_NO_RESOURCES		-7
#define	DS_SERVER_COULD_NOT_START	-8

/*
 * Other return values
 */
#define DS_UNKNOWN_ERROR            -1
#define DS_NO_SERVER_ROOT          -10
#define DS_CANNOT_EXEC             -11
#define DS_CANNOT_OPEN_STAT_FILE   -12
#define DS_NULL_PARAMETER          -13
#define DS_SERVER_MUST_BE_DOWN     -14
#define DS_CANNOT_OPEN_BACKUP_FILE -15
#define DS_NOT_A_DIRECTORY         -16
#define DS_CANNOT_CREATE_DIRECTORY -17
#define DS_CANNOT_OPEN_LDIF_FILE   -18
#define DS_IS_A_DIRECTORY          -19
#define DS_CANNOT_CREATE_FILE      -20
#define DS_UNDEFINED_VARIABLE      -21
#define DS_NO_SUCH_FILE            -22
#define DS_CANNOT_DELETE_FILE      -23
#define DS_UNKNOWN_SNMP_COMMAND    -24
#define DS_NON_NUMERIC_VALUE       -25
#define DS_NO_LOGFILE_NAME         -26
#define DS_CANNOT_OPEN_LOG_FILE    -27
#define DS_HAS_TOBE_READONLY_MODE  -28
#define DS_INVALID_LDIF_FILE       -29

/*
 * Types of config files.
 */
#define	DS_REAL_CONFIG	1
#define	DS_TMP_CONFIG	2

/*
 * Maximum numeric value we will accept in admin interface
 * We may at some point need per-option bounds, but for now,
 * there's just one global maximum.
 */
#define	DS_MAX_NUMERIC_VALUE	4294967295	/* 2^32 - 1 */

/* Use our own macro for rpt_err, so we can put our own error code in
   NMC_STATUS */
#undef rpt_err
#define rpt_err(CODE, STR1, STR2, STR3) \
                     fprintf( stdout, "NMC_ErrInfo: %s\n", (STR1) ); \
                     fprintf( stdout, "NMC_STATUS: %d\n", CODE )

/*
 * Flags for ds_display_config()
 */
#define DS_DISP_HRB     1       /* horizontal line to begin with */
#define DS_DISP_HRE     2       /* horizontal line to end with */
#define DS_DISP_TB      4       /* table begin */
#define DS_DISP_TE      8       /* table end */
#define DS_DISP_EOL     16      /* End Of Line */
#define DS_DISP_NOMT    32      /* display only non empty */
#define DS_DISP_NOIN    64      /* display with no input field */
#define DS_DISP_HELP    128     /* display with a help button */
#define DS_DISP_PLAIN   256     /* No table, no nothin */
#define DS_SIMPLE       (DS_DISP_EOL | DS_DISP_NOIN | DS_DISP_HELP)
 
/*
 * dci_type for ds_cfg_info
 */
#define DS_ATTR_STRING  1
#define DS_ATTR_NUMBER  2
#define DS_ATTR_ONOFF   3
#define DS_ATTR_LIMIT   4       /* a number where -1 is displayed as blank */

struct ds_cfg_info {
        char    *dci_varname;
        char    *dci_display;
        int     dci_type;
        char	*dci_help;
};
 
extern struct ds_cfg_info ds_cfg_info[];

#define LDBM_DATA_SIZE 5

/*ldbm specific backend information*/
struct ldbm_data {
  char  *tv[LDBM_DATA_SIZE][2]; /*type and value*/
};


/*
 * varname for ds_showparam()
 * NOTE: these must be kept in synch with the ds_cfg_info array defined
 * in ../lib/dsalib_conf.c
 */
#define DS_LOGLEVEL     	0
#define DS_REFERRAL     	1
#define DS_AUDITFILE	   	2
#define DS_LOCALHOST    	3
#define DS_PORT			4
#define DS_SECURITY		5
#define DS_SECURE_PORT		6
#define DS_SSL3CIPHERS		7
#define DS_PASSWDHASH		8
#define DS_ACCESSLOG		9
#define DS_ERRORLOG		10
#define DS_ROOTDN		11
#define DS_ROOTPW		12
#define DS_SUFFIX       	13
#define DS_LOCALUSER	14
#define DS_CFG_MAX		15 /* MUST be one greater than the last option */

/* These control how long we wait for the server to start up or shutdown */
#define SERVER_START_TIMEOUT 600 /* seconds */
#define SERVER_STOP_TIMEOUT SERVER_START_TIMEOUT /* same as start timeout */

typedef int (*DS_RM_RF_ERR_FUNC)(const char *path, const char *op, void *arg);

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern DS_EXPORT_SYMBOL char *ds_get_server_root();
extern DS_EXPORT_SYMBOL char *ds_get_install_root();
extern DS_EXPORT_SYMBOL char *ds_get_admserv_based_root();
extern DS_EXPORT_SYMBOL void ds_log_debug_message(char *msg);
extern DS_EXPORT_SYMBOL void ds_log_env(char **envp);
extern DS_EXPORT_SYMBOL int ds_get_updown_status();
extern DS_EXPORT_SYMBOL void ds_print_startstop(int stop);
extern DS_EXPORT_SYMBOL int ds_bring_up_server_install(int verbose,
	char *root, char *errorlog);
extern DS_EXPORT_SYMBOL int ds_bring_up_server(int verbose);
extern DS_EXPORT_SYMBOL char *ds_get_server_name();
extern DS_EXPORT_SYMBOL void ds_send_error(char *errstr, int print_errno);
extern DS_EXPORT_SYMBOL void ds_send_status(char *str);
extern DS_EXPORT_SYMBOL char *ds_get_cgi_var(char *cgi_var_name);
extern DS_EXPORT_SYMBOL	char *ds_get_cgi_var_simple(int index);
extern DS_EXPORT_SYMBOL char *ds_get_cgi_multiple(char *cgi_var_name);
extern DS_EXPORT_SYMBOL char *ds_get_errors_name();
extern DS_EXPORT_SYMBOL char *ds_get_access_name();
extern DS_EXPORT_SYMBOL char *ds_get_audit_name();
extern DS_EXPORT_SYMBOL char *ds_get_logfile_name(int config_type);


extern DS_EXPORT_SYMBOL int ds_bring_down_server();
extern DS_EXPORT_SYMBOL void ds_print_server_status(int isrunning);
extern DS_EXPORT_SYMBOL int ds_get_file_size(char *fileName);
extern DS_EXPORT_SYMBOL void ds_display_tail(char *fileName, int timeOut, 
    int startSeek, char *doneMsg, char *lastLine);
extern DS_EXPORT_SYMBOL char **ds_get_ldif_files();
extern DS_EXPORT_SYMBOL int ds_ldif2db_preserve(char *file);
extern DS_EXPORT_SYMBOL int ds_ldif2db(char *file);
extern DS_EXPORT_SYMBOL int ds_ldif2db_backend_subtree(char *file, char *backend, char *subtree);
extern DS_EXPORT_SYMBOL int ds_db2ldif(char *file);
extern DS_EXPORT_SYMBOL int ds_vlvindex(char **backendList, char **attrList);
extern DS_EXPORT_SYMBOL int ds_addindex(char **attrList, char *backendName);
extern DS_EXPORT_SYMBOL int ds_db2ldif_subtree(char *file, char *subtree);
extern DS_EXPORT_SYMBOL char **ds_get_bak_dirs();
extern DS_EXPORT_SYMBOL int ds_db2bak(char *file);
extern DS_EXPORT_SYMBOL int ds_bak2db(char *file);
extern DS_EXPORT_SYMBOL int ds_get_monitor(int frontend, char *port);
extern DS_EXPORT_SYMBOL int ds_get_bemonitor(char *bemdn, char *port);
extern DS_EXPORT_SYMBOL int ds_client_access(char *port, char *dn);
extern DS_EXPORT_SYMBOL char **ds_get_config(int type);
extern DS_EXPORT_SYMBOL char *ds_get_config_dir();
extern DS_EXPORT_SYMBOL void ds_set_config_dir(char *config_dir);
extern DS_EXPORT_SYMBOL char *ds_get_run_dir();
extern DS_EXPORT_SYMBOL void ds_set_run_dir(char *run_dir);
extern DS_EXPORT_SYMBOL char *ds_get_pwenc(char *passwd_hash, char *password);
extern DS_EXPORT_SYMBOL int ds_check_config(int type);
extern DS_EXPORT_SYMBOL int ds_check_pw(char *pwhash, char *pwclear);
extern DS_EXPORT_SYMBOL int ds_set_config(char *change_file_name);
extern DS_EXPORT_SYMBOL char **ds_get_conf_from_file(FILE *conf);
extern DS_EXPORT_SYMBOL void ds_display_config(char **ds_config);
extern DS_EXPORT_SYMBOL char *ds_get_var_name(int varnum);
extern DS_EXPORT_SYMBOL int ds_showparam(char **ds_config, int varname, int phase, 
    int occurance, char *dispname, int size, int maxlength, unsigned flags,
    char *url);
extern DS_EXPORT_SYMBOL void ds_show_pwmaxage(char *value);
extern DS_EXPORT_SYMBOL void ds_show_pwhash(char *value);
extern DS_EXPORT_SYMBOL char *ds_get_value(char **ds_config, char *parm, int phase, int occurance);
extern DS_EXPORT_SYMBOL void ds_apply_cfg_changes(int param_list[], int changed);
extern DS_EXPORT_SYMBOL int ds_commit_cfg_changes();
extern DS_EXPORT_SYMBOL int ds_config_updated();
extern DS_EXPORT_SYMBOL void ds_display_header(char *font_size, char *header);
extern DS_EXPORT_SYMBOL void ds_display_message(char *font_size, char *header);
extern DS_EXPORT_SYMBOL void ds_print_file_form(char *action, char *fileptr, char *full_fileptr);
extern DS_EXPORT_SYMBOL char *ds_get_file_meaning(char *file);
extern DS_EXPORT_SYMBOL void ds_print_file_name(char *fileptr);
extern DS_EXPORT_SYMBOL int ds_file_exists(char *filename);
extern DS_EXPORT_SYMBOL int ds_cp_file(char *sfile, char *dfile, int mode);
extern DS_EXPORT_SYMBOL time_t ds_get_mtime(char *filename);
extern DS_EXPORT_SYMBOL char *ds_get_config_value( int option );
extern DS_EXPORT_SYMBOL char **ds_get_file_list( char *dir );
extern DS_EXPORT_SYMBOL char *ds_get_tmp_dir();
extern DS_EXPORT_SYMBOL void ds_unixtodospath(char *szText);
extern DS_EXPORT_SYMBOL void ds_timetofname(char *szText);
extern DS_EXPORT_SYMBOL void ds_dostounixpath(char *szText);
extern DS_EXPORT_SYMBOL int ds_saferename(char *szSrc, char *szTarget);
extern DS_EXPORT_SYMBOL char *get_specific_help_button(char *help_link, 
    char *dispname, char *helpinfo);

/* Change the DN to a canonical format (in place); return DN. */
extern DS_EXPORT_SYMBOL char* dn_normalize (char* DN);

/* Change the DN to a canonical format (in place) and convert to v3; return DN. */
extern DS_EXPORT_SYMBOL char* dn_normalize_convert (char* DN);

/* if dn contains an unescaped quote return true */
extern DS_EXPORT_SYMBOL int ds_dn_uses_LDAPv2_quoting(const char *dn);

/* Return a copy of the DN, but with optional whitespace inserted. */
extern DS_EXPORT_SYMBOL char* ds_dn_expand (char* DN);

/* Return the value if it can be stored 'as is' in a config file.
   If it requires enquoting, allocate and return its enquoted form.
   The caller should free() the returned pointer iff it's != value. 
   On Windows, we don't want to double up on "\" characters in filespecs,
   so we need to pass in the value type */
extern DS_EXPORT_SYMBOL char* ds_enquote_config_value (int paramnum, char* value);

/*
 * Bring up a javascript alert.
 */
extern DS_EXPORT_SYMBOL void ds_alert_user(char *header, char *message);

/* Construct and return the DN that corresponds to the give DNS name.
   The caller should free() the returned pointer. */
extern DS_EXPORT_SYMBOL char* ds_DNS_to_DN (char* DNS);

/* Construct and return the DN of the LDAP server's own entry.
   The caller must NOT free() the returned pointer. */
extern DS_EXPORT_SYMBOL char* ds_get_config_DN (char** ds_config);

/* Encode characters, as described in RFC 1738 section 2.2,
   if they're 'unsafe' (as defined in RFC 1738), or '?' or
   <special> (as defined in RFC 1779).
   The caller should free() the returned pointer. */
extern DS_EXPORT_SYMBOL char* ds_URL_encode (const char*);

/* Decode characters, as described in RFC 1738 section 2.2.
   The caller should free() the returned pointer. */
extern DS_EXPORT_SYMBOL char* ds_URL_decode (const char*);

/* Encode all characters, even if 'safe' */
extern DS_EXPORT_SYMBOL char* ds_encode_all (const char*);

/* Change the effective UID and GID of this process to
   those associated with the given localuser (if any). */
extern DS_EXPORT_SYMBOL char* ds_become_localuser_name (char* localuser);

/* Change the effective UID and GID of this process to
   those associated with ds_config's localuser (if any). */
extern DS_EXPORT_SYMBOL char* ds_become_localuser (char** ds_config);

/* Change the effective UID and GID of this process back to
   what they were before calling ds_become_localuser(). */
extern DS_EXPORT_SYMBOL char* ds_become_original();

extern DS_EXPORT_SYMBOL char* ds_makeshort(char *filepath);

extern DS_EXPORT_SYMBOL int ds_search_file(char *filename, char *searchstring);

/* Begin parsing a POST in a CGI context */
extern DS_EXPORT_SYMBOL int ds_post_begin(FILE *input);

/* Begin parsing a GET in a CGI context */
extern DS_EXPORT_SYMBOL void ds_get_begin(char *query_string);

/* Display an error to the user and exit from a CGI */
extern DS_EXPORT_SYMBOL void ds_report_error(int type, char *errmsg, char *details);

/* Display a warning to the user */
extern DS_EXPORT_SYMBOL void ds_report_warning(int type, char *errmsg, char *details);

/* These functions are used by the program to alter the output behaviour
if not executing in a CGI context */
extern DS_EXPORT_SYMBOL int ds_get_formatted_output(void);
extern DS_EXPORT_SYMBOL void ds_set_formatted_output(int val);

/* return the value of a CGI variable */
extern DS_EXPORT_SYMBOL char *ds_a_get_cgi_var(char *varname, char *elem_id, char *bongmsg);

/* return a multi-valued CGI variable */
extern DS_EXPORT_SYMBOL char **ds_a_get_cgi_multiple(char *varname, char *elem_id, char *bongmsg);

/* open an html file */
extern DS_EXPORT_SYMBOL FILE *ds_open_html_file(char *filename);

/* show a message to be parsed by the non-HTML front end */
extern DS_EXPORT_SYMBOL void ds_show_message(const char *message);

/* show a key/value pair to be parsed by the non-HTML front end */
extern DS_EXPORT_SYMBOL void ds_show_key_value(char *key, char *value);

extern DS_EXPORT_SYMBOL void ds_submit(char *helptarget) ;
extern DS_EXPORT_SYMBOL char *ds_get_helpbutton(char *topic);

extern DS_EXPORT_SYMBOL void alter_startup_line(char *startup_line);

extern DS_EXPORT_SYMBOL int ds_dir_exists(char *fn);
extern DS_EXPORT_SYMBOL int ds_mkdir(char *dir, int mode);
extern DS_EXPORT_SYMBOL char *ds_mkdir_p(char *dir, int mode);
extern DS_EXPORT_SYMBOL char *ds_salted_sha1_pw_enc (char* pwd);
extern DS_EXPORT_SYMBOL char * ds_escape_for_shell( char *s );

extern DS_EXPORT_SYMBOL char **ds_string_to_vec(char *s);

extern DS_EXPORT_SYMBOL char *ds_system_errmsg(void);

extern DS_EXPORT_SYMBOL int ds_exec_and_report(char *cmd);

/* remove a directory hierarchy - if the error function is given, it will be called upon
   error (e.g. directory not readable, cannot remove file, etc.) - if the callback function
   returns 0, this means to abort the removal, otherwise, continue
*/
extern DS_EXPORT_SYMBOL int ds_rm_rf(const char *dir, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg);
/*
  remove a registry key and report an error message if unsuccessful
*/
extern DS_EXPORT_SYMBOL int ds_remove_reg_key(void *base, const char *format, ...);
#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __dsalib_h */