Jpp  19.1.0
the software that should make you happy
elogd.h
Go to the documentation of this file.
1 /********************************************************************
2 
3  Name: elogd.h
4  Created by: Stefan Ritt
5  Copyright 2000 + Stefan Ritt
6 
7  ELOG is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  ELOG is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  In addition, as a special exception, the copyright holders give
18  permission to link the code of portions of this program with the
19  OpenSSL library under certain conditions as described in each
20  individual source file, and distribute linked combinations
21  including the two.
22  You must obey the GNU General Public License in all respects
23  for all of the code used other than OpenSSL. If you modify
24  file(s) with this exception, you may extend this exception to your
25  version of the file(s), but you are not obligated to do so. If you
26  do not wish to do so, delete this exception statement from your
27  version. If you delete this exception statement from all source
28  files in the program, then also delete it here.
29 
30  You should have received a copy of the GNU General Public License
31  along with ELOG. If not, see <http://www.gnu.org/licenses/>.
32 
33 
34  Contents: Header file for ELOG program
35 
36 \********************************************************************/
37 
38 /* Include version from central version file */
39 #include "elog-version.h"
40 
41 #define _GNU_SOURCE
42 #include <stdio.h>
43 #include <sys/types.h>
44 #include <fcntl.h>
45 #include <stdarg.h>
46 #include <string.h>
47 #include <ctype.h>
48 #include <stdlib.h>
49 #include <assert.h>
50 #include <locale.h>
51 
52 /* Default name of the configuration file. */
53 #ifndef CFGFILE
54 #define CFGFILE "elogd.cfg"
55 #endif
56 
57 /* Default TCP port for server. */
58 #ifndef DEFAULT_PORT
59 #define DEFAULT_PORT 80
60 #endif
61 
62 #ifdef _MSC_VER
63 
64 #define OS_WINNT
65 
66 #define DIR_SEPARATOR '\\'
67 #define DIR_SEPARATOR_STR "\\"
68 
69 #define snprintf _snprintf
70 
71 #include <windows.h>
72 #include <io.h>
73 #include <conio.h>
74 #include <time.h>
75 #include <direct.h>
76 #include <sys/stat.h>
77 #include <errno.h>
78 
79 #else
80 
81 #define OS_UNIX
82 
83 #ifdef __APPLE__
84 #define OS_MACOSX
85 #endif
86 
87 #define TRUE 1
88 #define FALSE 0
89 
90 #ifndef O_TEXT
91 #define O_TEXT 0
92 #define O_BINARY 0
93 #endif
94 
95 #define DIR_SEPARATOR '/'
96 #define DIR_SEPARATOR_STR "/"
97 
98 #ifndef DEFAULT_USER
99 #define DEFAULT_USER "nobody"
100 #endif
101 
102 #ifndef DEFAULT_GROUP
103 #define DEFAULT_GROUP "nogroup"
104 #endif
105 
106 #ifndef PIDFILE
107 #define PIDFILE "/var/run/elogd.pid"
108 #endif
109 
110 typedef int BOOL;
111 
112 #include <netdb.h>
113 #include <netinet/in.h>
114 #include <arpa/inet.h>
115 #include <sys/socket.h>
116 #include <sys/time.h>
117 #include <sys/types.h>
118 #include <sys/stat.h>
119 #include <sys/wait.h>
120 #include <unistd.h>
121 #include <signal.h>
122 #include <time.h>
123 #include <dirent.h>
124 #include <errno.h>
125 #include <ctype.h>
126 #include <pwd.h>
127 #include <grp.h>
128 #include <syslog.h>
129 #include <termios.h>
130 
131 #define closesocket(s) close(s)
132 
133 #ifndef stricmp
134 #define stricmp(s1, s2) strcasecmp(s1, s2)
135 #endif
136 
137 #endif /* OS_UNIX */
138 
139 /* SSL includes */
140 #ifdef HAVE_SSL
141 #include <openssl/ssl.h>
142 #endif
143 
144 /* local includes */
145 #include "regex.h"
146 #include "mxml.h"
147 #include "strlcpy.h"
148 
149 #define SYSLOG_PRIORITY LOG_NOTICE /* Default priority for syslog facility */
150 
151 #define TELL(fh) lseek(fh, 0, SEEK_CUR)
152 
153 #ifdef OS_WINNT
154 #define TRUNCATE(fh) chsize(fh, TELL(fh))
155 #else
156 #define TRUNCATE(fh) ftruncate(fh, TELL(fh))
157 #endif
158 
159 #define NAME_LENGTH 1500
160 
161 #define DEFAULT_TIME_FORMAT "%c"
162 #define DEFAULT_DATE_FORMAT "%x"
163 
164 #define DEFAULT_HTTP_CHARSET "ISO-8859-1"
165 
166 #define SUCCESS 1
167 #define FAILURE 0
168 
169 #define EL_SUCCESS 1
170 #define EL_FIRST_MSG 2
171 #define EL_LAST_MSG 3
172 #define EL_NO_MSG 4
173 #define EL_FILE_ERROR 5
174 #define EL_UPGRADE 6
175 #define EL_EMPTY 7
176 #define EL_MEM_ERROR 8
177 #define EL_DUPLICATE 9
178 #define EL_INVAL_FILE 10
179 
180 #define EL_FIRST 1
181 #define EL_LAST 2
182 #define EL_NEXT 3
183 #define EL_PREV 4
184 
185 #define MAX_GROUPS 32
186 #define MAX_PARAM 200
187 #define MAX_ATTACHMENTS 50
188 #define MAX_N_LIST 100
189 #define MAX_N_ATTR 100
190 #define MAX_N_EMAIL 500
191 #define MAX_REPLY_TO 100
192 #define CMD_SIZE 10000
193 #define TEXT_SIZE 250000
194 #define MAX_PATH_LENGTH 256
195 
196 #define MAX_CONTENT_LENGTH 10*1024*1024
197 
198 /* attribute flags */
199 #define AF_REQUIRED (1<<0)
200 #define AF_LOCKED (1<<1)
201 #define AF_MULTI (1<<2)
202 #define AF_FIXED_EDIT (1<<3)
203 #define AF_FIXED_REPLY (1<<4)
204 #define AF_ICON (1<<5)
205 #define AF_RADIO (1<<6)
206 #define AF_EXTENDABLE (1<<7)
207 #define AF_DATE (1<<8)
208 #define AF_DATETIME (1<<9)
209 #define AF_TIME (1<<10)
210 #define AF_NUMERIC (1<<11)
211 #define AF_USERLIST (1<<12)
212 #define AF_MUSERLIST (1<<13)
213 #define AF_USEREMAIL (1<<14)
214 #define AF_MUSEREMAIL (1<<15)
215 
216 /* attribute format flags */
217 #define AFF_SAME_LINE 1
218 #define AFF_MULTI_LINE 2
219 #define AFF_DATE 4
220 #define AFF_EXTENDABLE 8
221 
222 typedef struct {
224  char subdir[256];
225  char file_name[32];
226  time_t file_time;
227  int offset;
229  unsigned char md5_digest[16];
230 } EL_INDEX;
231 
232 typedef struct {
233  char name[256];
234  char name_enc[256];
235  char data_dir[256];
236  char top_group[256];
239  int n_attr;
240  PMXML_NODE pwd_xml_tree;
241 } LOGBOOK;
242 
243 typedef struct {
245  unsigned char md5_digest[16];
246 } MD5_INDEX;
247 
248 typedef struct LBNODE *LBLIST;
249 
250 typedef struct LBNODE {
251  char name[256];
252  LBLIST *member;
254  int is_top;
255 } LBNODE;
256 
257 typedef struct {
259  int index;
260  char string[256];
261  int number;
263 } MSG_LIST;
264 
265 typedef struct {
266  char user_name[256];
267  char session_id[32];
268  char host_ip[32];
269  time_t time;
270 } SESSION_ID;
271 
272 void show_error(char *error);
273 int is_verbose(void);
274 extern void eprintf(const char *, ...);
275 BOOL enum_user_line(LOGBOOK * lbs, int n, char *user, int size);
276 int get_user_line(LOGBOOK * lbs, char *user, char *password, char *full_name, char *email,
277  BOOL email_notify[1000], time_t * last_access, int *inactive);
278 int get_full_name(LOGBOOK *lbs, char *uname, char *full_name);
279 int set_user_inactive(LOGBOOK * lbs, char *user, int inactive);
280 int strbreak(char *str, char list[][NAME_LENGTH], int size, char *brk, BOOL ignore_quotes);
281 int execute_shell(LOGBOOK * lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LENGTH],
282  char att_file[MAX_ATTACHMENTS][256], char *sh_cmd);
283 BOOL isparam(char *param);
284 char *getparam(char *param);
285 void write_logfile(LOGBOOK * lbs, const char *str);
286 BOOL check_login_user(LOGBOOK * lbs, char *user);
288 BOOL is_logbook_in_group(LBLIST pgrp, char *logbook);
289 BOOL is_admin_user(LOGBOOK * lbs, char *user);
292 void show_top_text(LOGBOOK * lbs);
294 int set_attributes(LOGBOOK * lbs, char attributes[][NAME_LENGTH], int n);
295 void show_elog_list(LOGBOOK * lbs, int past_n, int last_n, int page_n, BOOL default_page, char *info);
296 int change_config_line(LOGBOOK * lbs, char *option, char *old_value, char *new_value);
297 int read_password(char *pwd, int size);
298 int getcfg(char *group, char *param, char *value, int vsize);
299 int build_subst_list(LOGBOOK * lbs, char list[][NAME_LENGTH], char value[][NAME_LENGTH],
300  char attrib[][NAME_LENGTH], BOOL format_date);
301 void highlight_searchtext(regex_t * re_buf, char *src, char *dst, BOOL hidden);
302 int parse_config_file(char *config_file);
303 PMXML_NODE load_password_file(LOGBOOK * lbs, char *error, int error_size);
305 BOOL check_login(LOGBOOK * lbs, char *sid);
306 void compose_base_url(LOGBOOK * lbs, char *base_url, int size, BOOL email_notify);
307 void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command);
308 char *loc(char *orig);
309 void strencode(char *text);
310 void strencode_nouml(char *text);
311 char *stristr(const char *str, const char *pattern);
312 int scan_attributes(char *logbook);
313 int is_inline_attachment(char *encoding, int message_id, char *text, int i, char *att);
314 int setgroup(char *str);
315 int setuser(char *str);
316 int setegroup(char *str);
317 int seteuser(char *str);
318 void strencode2(char *b, const char *text, int size);
319 void load_config_section(char *section, char **buffer, char *error);
320 void remove_crlf(char *buffer);
321 time_t convert_date(char *date_string);
322 time_t convert_datetime(char *date_string);
323 int get_thumb_name(const char *file_name, char *thumb_name, int size, int index);
324 int create_thumbnail(LOGBOOK * lbs, char *file_name);
325 int ascii_compare(const void *s1, const void *s2);
326 int ascii_compare2(const void *s1, const void *s2);
327 void do_crypt(const char *s, char *d, int size);
328 BOOL get_password_file(LOGBOOK * lbs, char *file_name, int size);
330 
331 /* functions from auth.c */
332 int auth_verify_password(LOGBOOK *lbs, const char *user, const char *password, char *error_str, int error_size);
333 int auth_change_password(LOGBOOK *lbs, const char *user, const char *old_pwd, const char *new_pwd, char *error_str, int error_size);
334 int auth_verify_password_krb5(LOGBOOK *lbs, const char *user, const char *password, char *error_str, int error_size);
335 int auth_change_password_krb5(LOGBOOK *lbs, const char *user, const char *old_pwd, const char *new_pwd, char *error, int error_size);
336 
char text[TEXT_SIZE]
Definition: elog.cc:72
int BOOL
Definition: elogd.h:110
int is_verbose(void)
void free_logbook_hierarchy(LBLIST root)
void do_crypt(const char *s, char *d, int size)
int auth_verify_password(LOGBOOK *lbs, const char *user, const char *password, char *error_str, int error_size)
void strencode_nouml(char *text)
int get_full_name(LOGBOOK *lbs, char *uname, char *full_name)
int auth_change_password(LOGBOOK *lbs, const char *user, const char *old_pwd, const char *new_pwd, char *error_str, int error_size)
int scan_attributes(char *logbook)
BOOL is_admin_user_global(char *user)
int setuser(char *str)
char * getparam(char *param)
BOOL isparam(char *param)
int setegroup(char *str)
int build_subst_list(LOGBOOK *lbs, char list[][NAME_LENGTH], char value[][NAME_LENGTH], char attrib[][NAME_LENGTH], BOOL format_date)
int auth_change_password_krb5(LOGBOOK *lbs, const char *user, const char *old_pwd, const char *new_pwd, char *error, int error_size)
char * stristr(const char *str, const char *pattern)
BOOL check_login_user(LOGBOOK *lbs, char *user)
PMXML_NODE load_password_file(LOGBOOK *lbs, char *error, int error_size)
int getcfg(char *group, char *param, char *value, int vsize)
int ascii_compare2(const void *s1, const void *s2)
time_t convert_datetime(char *date_string)
int read_password(char *pwd, int size)
void show_error(char *error)
void strencode2(char *b, const char *text, int size)
int change_config_line(LOGBOOK *lbs, char *option, char *old_value, char *new_value)
int ascii_compare(const void *s1, const void *s2)
void show_top_text(LOGBOOK *lbs)
int load_password_files(void)
void load_config_section(char *section, char **buffer, char *error)
BOOL is_admin_user(LOGBOOK *lbs, char *user)
BOOL enum_user_line(LOGBOOK *lbs, int n, char *user, int size)
int execute_shell(LOGBOOK *lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LENGTH], char att_file[MAX_ATTACHMENTS][256], char *sh_cmd)
void show_bottom_text(LOGBOOK *lbs)
char * loc(char *orig)
void remove_crlf(char *buffer)
void highlight_searchtext(regex_t *re_buf, char *src, char *dst, BOOL hidden)
int get_thumb_name(const char *file_name, char *thumb_name, int size, int index)
BOOL is_logbook_in_group(LBLIST pgrp, char *logbook)
BOOL get_password_file(LOGBOOK *lbs, char *file_name, int size)
int setgroup(char *str)
int get_user_line(LOGBOOK *lbs, char *user, char *password, char *full_name, char *email, BOOL email_notify[1000], time_t *last_access, int *inactive)
int create_thumbnail(LOGBOOK *lbs, char *file_name)
int set_attributes(LOGBOOK *lbs, char attributes[][NAME_LENGTH], int n)
void show_elog_list(LOGBOOK *lbs, int past_n, int last_n, int page_n, BOOL default_page, char *info)
LOGBOOK * get_first_lbs_with_global_passwd(void)
void show_elog_entry(LOGBOOK *lbs, char *dec_path, char *command)
int set_user_inactive(LOGBOOK *lbs, char *user, int inactive)
void write_logfile(LOGBOOK *lbs, const char *str)
#define MAX_ATTACHMENTS
Definition: elogd.h:187
int seteuser(char *str)
void compose_base_url(LOGBOOK *lbs, char *base_url, int size, BOOL email_notify)
void eprintf(const char *,...)
#define MAX_N_ATTR
Definition: elogd.h:189
int parse_config_file(char *config_file)
int strbreak(char *str, char list[][NAME_LENGTH], int size, char *brk, BOOL ignore_quotes)
void strencode(char *text)
#define NAME_LENGTH
Definition: elogd.h:159
BOOL check_login(LOGBOOK *lbs, char *sid)
time_t convert_date(char *date_string)
int is_inline_attachment(char *encoding, int message_id, char *text, int i, char *att)
int auth_verify_password_krb5(LOGBOOK *lbs, const char *user, const char *password, char *error_str, int error_size)
LBLIST get_logbook_hierarchy(void)
const int n
Definition: JPolint.hh:786
Definition: root.py:1
time_t file_time
Definition: elogd.h:226
int offset
Definition: elogd.h:227
int message_id
Definition: elogd.h:223
int in_reply_to
Definition: elogd.h:228
Definition: elogd.h:250
int n_members
Definition: elogd.h:253
int is_top
Definition: elogd.h:254
char name[256]
Definition: elogd.h:251
LBLIST * member
Definition: elogd.h:252
Definition: elogd.h:232
int n_attr
Definition: elogd.h:239
PMXML_NODE pwd_xml_tree
Definition: elogd.h:240
int * n_el_index
Definition: elogd.h:238
EL_INDEX * el_index
Definition: elogd.h:237
int message_id
Definition: elogd.h:244
int index
Definition: elogd.h:259
int in_reply_to
Definition: elogd.h:262
LOGBOOK * lbs
Definition: elogd.h:258
int number
Definition: elogd.h:261
time_t time
Definition: elogd.h:269