| 1 |
/* +-------------------------------------------------------------------+ */ |
|---|
| 2 |
/* | Copyright 1991, David Koblas. | */ |
|---|
| 3 |
/* | Permission to use, copy, modify, and distribute this software | */ |
|---|
| 4 |
/* | and its documentation for any purpose and without fee is hereby | */ |
|---|
| 5 |
/* | granted, provided that the above copyright notice appear in all | */ |
|---|
| 6 |
/* | copies and that both that copyright notice and this permission | */ |
|---|
| 7 |
/* | notice appear in supporting documentation. This software is | */ |
|---|
| 8 |
/* | provided "as is" without express or implied warranty. | */ |
|---|
| 9 |
/* +-------------------------------------------------------------------+ */ |
|---|
| 10 |
|
|---|
| 11 |
#include <unistd.h> |
|---|
| 12 |
#include <limits.h> |
|---|
| 13 |
#include "config.h" |
|---|
| 14 |
|
|---|
| 15 |
#if TIME_WITH_SYS_TIME |
|---|
| 16 |
# include <sys/time.h> |
|---|
| 17 |
# include <time.h> |
|---|
| 18 |
#else |
|---|
| 19 |
# if HAVE_SYS_TIME_H |
|---|
| 20 |
# include <sys/time.h> |
|---|
| 21 |
# else |
|---|
| 22 |
# include <time.h> |
|---|
| 23 |
# endif |
|---|
| 24 |
#endif |
|---|
| 25 |
|
|---|
| 26 |
#if HAVE_DIRENT_H |
|---|
| 27 |
# include <dirent.h> |
|---|
| 28 |
# define NAMLEN(dirent) strlen((dirent)->d_name) |
|---|
| 29 |
#else |
|---|
| 30 |
# define dirent direct |
|---|
| 31 |
# define NAMLEN(dirent) (dirent)->d_namlen |
|---|
| 32 |
# if HAVE_SYS_NDIR_H |
|---|
| 33 |
# include <sys/ndir.h> |
|---|
| 34 |
# endif |
|---|
| 35 |
# if HAVE_SYS_DIR_H |
|---|
| 36 |
# include <sys/dir.h> |
|---|
| 37 |
# endif |
|---|
| 38 |
# if HAVE_NDIR_H |
|---|
| 39 |
# include <ndir.h> |
|---|
| 40 |
# endif |
|---|
| 41 |
#endif |
|---|
| 42 |
|
|---|
| 43 |
#include <sys/types.h> |
|---|
| 44 |
#if HAVE_SYS_WAIT_H |
|---|
| 45 |
# include <sys/wait.h> |
|---|
| 46 |
#endif |
|---|
| 47 |
#ifndef WEXITSTATUS |
|---|
| 48 |
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) |
|---|
| 49 |
#endif |
|---|
| 50 |
#ifndef WIFEXITED |
|---|
| 51 |
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) |
|---|
| 52 |
#endif |
|---|
| 53 |
|
|---|
| 54 |
#if STDC_HEADERS |
|---|
| 55 |
# include <string.h> |
|---|
| 56 |
#else |
|---|
| 57 |
# if !HAVE_STRCHR |
|---|
| 58 |
# define strchr index |
|---|
| 59 |
# define strrchr rindex |
|---|
| 60 |
# endif |
|---|
| 61 |
char *strchr (), *strrchr (); |
|---|
| 62 |
# if !HAVE_MEMCPY |
|---|
| 63 |
# define memcpy(d, s, n) bcopy ((s), (d), (n)) |
|---|
| 64 |
# define memmove(d, s, n) bcopy ((s), (d), (n)) |
|---|
| 65 |
# endif |
|---|
| 66 |
#endif |
|---|
| 67 |
|
|---|
| 68 |
typedef struct cmd_s { |
|---|
| 69 |
char *name; |
|---|
| 70 |
int nargs, nopts; |
|---|
| 71 |
int margs, mopts; |
|---|
| 72 |
char **args, **opts; |
|---|
| 73 |
struct cmd_s *next; |
|---|
| 74 |
} cmd_t; |
|---|
| 75 |
|
|---|
| 76 |
typedef struct var_s { |
|---|
| 77 |
char *name, *value; |
|---|
| 78 |
struct var_s *next; |
|---|
| 79 |
} var_t; |
|---|
| 80 |
|
|---|
| 81 |
typedef struct array_s { |
|---|
| 82 |
void **data; |
|---|
| 83 |
int size, capacity; |
|---|
| 84 |
} array_t; |
|---|
| 85 |
|
|---|
| 86 |
/* functions to manage a dynamically extensible array of pointers */ |
|---|
| 87 |
#define ARRAY_CHUNK 32 |
|---|
| 88 |
array_t *array_alloc(); |
|---|
| 89 |
void array_free(array_t *array); |
|---|
| 90 |
array_t *array_free_contents(array_t *array); |
|---|
| 91 |
void *array_push(array_t *array, void *object); |
|---|
| 92 |
void *array_pop(array_t *array); |
|---|
| 93 |
int array_extend(array_t *array, int capacity); |
|---|
| 94 |
|
|---|
| 95 |
extern cmd_t *First, *Build(), *BuildSingle(); |
|---|
| 96 |
extern var_t *Variables; |
|---|
| 97 |
extern unsigned minimum_logging_level; |
|---|
| 98 |
|
|---|
| 99 |
void fatal(int logit, const char *format, ...); |
|---|
| 100 |
int logger(unsigned flags, const char *format, ...); |
|---|
| 101 |
void strnprintf(char *out, int len, const char *format, ...); |
|---|
| 102 |
void vstrnprintf(char *out, int len, const char *format, va_list ap); |
|---|
| 103 |
char *strtolower(char *in); |
|---|
| 104 |
|
|---|
| 105 |
int ReadFile(char *file); |
|---|
| 106 |
int ReadDir(char *dir); |
|---|
| 107 |
int CountArgs(cmd_t *cmd); |
|---|
| 108 |
int atov(char *str, int type); |
|---|
| 109 |
|
|---|
| 110 |
#define MAXSTRLEN 2048 |
|---|
| 111 |
#define OP_ACCESS SYSCONFDIR "/op.conf" |
|---|
| 112 |
#define OP_ACCESS_DIR SYSCONFDIR "/op.d" |
|---|
| 113 |
|
|---|
| 114 |
#define VAR_EXPAND_LEN 8192 |
|---|
| 115 |
#define VAR_NAME_LEN 64 |
|---|
| 116 |
|
|---|
| 117 |
#ifndef HOST_NAME_MAX |
|---|
| 118 |
#define HOST_NAME_MAX 255 |
|---|
| 119 |
#endif |
|---|