libreport  2.9.1.4.gbb0c
A tool to inform users about various problems on the running system
internal_libreport.h
1 /*
2  Copyright (C) 2010 ABRT team
3  Copyright (C) 2010 RedHat Inc
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef LIBREPORT_INTERNAL_H_
21 #define LIBREPORT_INTERNAL_H_
22 
23 #include <assert.h>
24 #include <ctype.h>
25 #include <dirent.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <inttypes.h>
29 #include <setjmp.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34 #include <stddef.h>
35 #include <string.h>
36 #include <syslog.h>
37 #include <sys/poll.h>
38 #include <sys/mman.h>
39 #include <sys/socket.h>
40 #include <sys/stat.h>
41 #include <sys/time.h>
42 #include <sys/types.h>
43 #include <sys/wait.h>
44 #include <arpa/inet.h> /* sockaddr_in, sockaddr_in6 etc */
45 #include <termios.h>
46 #include <time.h>
47 #include <unistd.h>
48 /* Try to pull in PATH_MAX */
49 #include <limits.h>
50 #include <sys/param.h>
51 #ifndef PATH_MAX
52 # define PATH_MAX 256
53 #endif
54 #include <pwd.h>
55 #include <grp.h>
56 
57 #ifdef HAVE_CONFIG_H
58 # include "config.h"
59 #endif
60 
61 /* Must be after #include "config.h" */
62 #if ENABLE_NLS
63 # include <libintl.h>
64 # define _(S) dgettext(PACKAGE, S)
65 #else
66 # define _(S) (S)
67 #endif
68 
69 #if HAVE_LOCALE_H
70 # include <locale.h>
71 #endif /* HAVE_LOCALE_H */
72 
73 /* Some libc's forget to declare these, do it ourself */
74 extern char **environ;
75 #if defined(__GLIBC__) && __GLIBC__ < 2
76 int vdprintf(int d, const char *format, va_list ap);
77 #endif
78 
79 #undef NORETURN
80 #define NORETURN __attribute__ ((noreturn))
81 
82 #undef ERR_PTR
83 #define ERR_PTR ((void*)(uintptr_t)1)
84 
85 #undef ARRAY_SIZE
86 #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
87 
88 /* consts used across whole libreport */
89 #define CREATE_PRIVATE_TICKET "ABRT_CREATE_PRIVATE_TICKET"
90 #define STOP_ON_NOT_REPORTABLE "ABRT_STOP_ON_NOT_REPORTABLE"
91 
92 /* Pull in entire public libreport API */
93 #include "global_configuration.h"
94 #include "dump_dir.h"
95 #include "event_config.h"
96 #include "problem_data.h"
97 #include "report.h"
98 #include "run_event.h"
99 #include "workflow.h"
100 #include "file_obj.h"
101 #include "libreport_types.h"
102 #include "reporters.h"
103 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 
108 #define prefixcmp libreport_prefixcmp
109 int prefixcmp(const char *str, const char *prefix);
110 #define suffixcmp libreport_suffixcmp
111 int suffixcmp(const char *str, const char *suffix);
112 #define trim_all_whitespace libreport_trim_all_whitespace
113 char *trim_all_whitespace(const char *str);
114 #define shorten_string_to_length libreport_shorten_string_to_length
115 char *shorten_string_to_length(const char *str, unsigned length);
116 #define strtrim libreport_strtrim
117 char *strtrim(char *str);
118 #define strtrimch libreport_strtrimch
119 char *strtrimch(char *str, int ch);
120 #define strremovech libreport_strremovech
121 char *strremovech(char *str, int ch);
122 #define append_to_malloced_string libreport_append_to_malloced_string
123 char *append_to_malloced_string(char *mstr, const char *append);
124 #define skip_blank libreport_skip_blank
125 char* skip_blank(const char *s);
126 #define skip_whitespace libreport_skip_whitespace
127 char* skip_whitespace(const char *s);
128 #define skip_non_whitespace libreport_skip_non_whitespace
129 char* skip_non_whitespace(const char *s);
130 /* Like strcpy but can copy overlapping strings. */
131 #define overlapping_strcpy libreport_overlapping_strcpy
132 void overlapping_strcpy(char *dst, const char *src);
133 
134 #define concat_path_file libreport_concat_path_file
135 char *concat_path_file(const char *path, const char *filename);
136 /*
137  * Used to construct a name in a different directory with the basename
138  * similar to the old name, if possible.
139  */
140 #define concat_path_basename libreport_concat_path_basename
141 char *concat_path_basename(const char *path, const char *filename);
142 
143 /* Allows all printable characters except '/',
144  * the string must not exceed 64 characters of length
145  * and must not equal neither "." nor ".." (these strings may appear in the string) */
146 #define str_is_correct_filename libreport_str_is_correct_filename
147 bool str_is_correct_filename(const char *str);
148 
149 /* A-la fgets, but malloced and of unlimited size */
150 #define xmalloc_fgets libreport_xmalloc_fgets
151 char *xmalloc_fgets(FILE *file);
152 /* Similar, but removes trailing \n */
153 #define xmalloc_fgetline libreport_xmalloc_fgetline
154 char *xmalloc_fgetline(FILE *file);
155 /* Useful for easy reading of various /proc files */
156 #define xmalloc_fopen_fgetline_fclose libreport_xmalloc_fopen_fgetline_fclose
157 char *xmalloc_fopen_fgetline_fclose(const char *filename);
158 
159 
160 typedef enum {
161  COPYFD_SPARSE = 1 << 0,
162 } libreport_copyfd_flags;
163 
164 /* Writes up to 'size' Bytes from a file descriptor to a file in a directory
165  *
166  * If you need to write all Bytes of the file descriptor, pass 0 as the size.
167  *
168  * @param src The source file descriptor
169  * @param dir_fd A file descriptor for the parent directory of the destination file
170  * @param name The destination file name
171  * @param mode The destination file open mode
172  * @param uid The destination file's uid
173  * @param gid The destination file's gid
174  * @param open_flags The destination file open flags
175  * @param copy_flags libreport_copyfd_flags
176  * @param size The upper limit for written bytes (0 for no limit).
177  * @return Number of read Bytes on success. On errors, return -1 and prints out
178  * reasonable good error messages.
179  */
180 #define copyfd_ext_at libreport_copyfd_ext_at
181 off_t copyfd_ext_at(int src, int dir_fd, const char *name, int mode,
182  uid_t uid, gid_t gid, int open_flags, int copy_flags, off_t size);
183 
184 /* On error, copyfd_XX prints error messages and returns -1 */
185 #define copyfd_eof libreport_copyfd_eof
186 off_t copyfd_eof(int src_fd, int dst_fd, int flags);
187 #define copyfd_size libreport_copyfd_size
188 off_t copyfd_size(int src_fd, int dst_fd, off_t size, int flags);
189 #define copyfd_exact_size libreport_copyfd_exact_size
190 void copyfd_exact_size(int src_fd, int dst_fd, off_t size);
191 #define copy_file_ext_2at libreport_copy_file_ext_2at
192 off_t copy_file_ext_2at(int src_dir_fd, const char *src_name, int dir_fd, const char *name, int mode, uid_t uid, gid_t gid, int src_flags, int dst_flags);
193 #define copy_file_ext_at libreport_copy_file_ext_at
194 off_t copy_file_ext_at(const char *src_name, int dir_fd, const char *name, int mode, uid_t uid, gid_t gid, int src_flags, int dst_flags);
195 #define copy_file_ext(src_name, dst_name, mode, uid, gid, src_flags, dst_flags) \
196  copy_file_ext_at(src_name, AT_FDCWD, dst_name, mode, uid, gid, src_flags, dst_flags)
197 #define copy_file libreport_copy_file
198 off_t copy_file(const char *src_name, const char *dst_name, int mode);
199 #define copy_file_at libreport_copy_file_at
200 off_t copy_file_at(const char *src_name, int dir_fd, const char *name, int mode);
201 #define copy_file_recursive libreport_copy_file_recursive
202 int copy_file_recursive(const char *source, const char *dest);
203 
204 #define decompress_fd libreport_decompress_fd
205 int decompress_fd(int fdi, int fdo);
206 #define decompress_file libreport_decompress_file
207 int decompress_file(const char *path_in, const char *path_out, mode_t mode_out);
208 #define decompress_file_ext_at libreport_decompress_file_ext_at
209 int decompress_file_ext_at(const char *path_in, int dir_fd, const char *path_out,
210  mode_t mode_out, uid_t uid, gid_t gid, int src_flags, int dst_flags);
211 
212 // NB: will return short read on error, not -1,
213 // if some data was read before error occurred
214 #define xread libreport_xread
215 void xread(int fd, void *buf, size_t count);
216 #define safe_read libreport_safe_read
217 ssize_t safe_read(int fd, void *buf, size_t count);
218 #define safe_write libreport_safe_write
219 ssize_t safe_write(int fd, const void *buf, size_t count);
220 #define full_read libreport_full_read
221 ssize_t full_read(int fd, void *buf, size_t count);
222 #define full_write libreport_full_write
223 ssize_t full_write(int fd, const void *buf, size_t count);
224 #define full_write_str libreport_full_write_str
225 ssize_t full_write_str(int fd, const char *buf);
226 #define xmalloc_read libreport_xmalloc_read
227 void* xmalloc_read(int fd, size_t *maxsz_p);
228 #define xmalloc_open_read_close libreport_xmalloc_open_read_close
229 void* xmalloc_open_read_close(const char *filename, size_t *maxsz_p);
230 #define xmalloc_xopen_read_close libreport_xmalloc_xopen_read_close
231 void* xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p);
232 #define malloc_readlink libreport_malloc_readlink
233 char* malloc_readlink(const char *linkname);
234 #define malloc_readlinkat libreport_malloc_readlinkat
235 char* malloc_readlinkat(int dir_fd, const char *linkname);
236 
237 
238 /* Returns malloc'ed block */
239 #define encode_base64 libreport_encode_base64
240 char *encode_base64(const void *src, int length);
241 
242 /* Returns NULL if the string needs no sanitizing.
243  * control_chars_to_sanitize is a bit mask.
244  * If Nth bit is set, Nth control char will be sanitized (replaced by [XX]).
245  */
246 #define sanitize_utf8 libreport_sanitize_utf8
247 char *sanitize_utf8(const char *src, uint32_t control_chars_to_sanitize);
248 enum {
249  SANITIZE_ALL = 0xffffffff,
250  SANITIZE_TAB = (1 << 9),
251  SANITIZE_LF = (1 << 10),
252  SANITIZE_CR = (1 << 13),
253 };
254 
255 #define SHA1_RESULT_LEN (5 * 4)
256 typedef struct sha1_ctx_t {
257  uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
258  /* for sha256: void (*process_block)(struct md5_ctx_t*); */
259  uint64_t total64; /* must be directly before hash[] */
260  uint32_t hash[8]; /* 4 elements for md5, 5 for sha1, 8 for sha256 */
261 } sha1_ctx_t;
262 #define sha1_begin libreport_sha1_begin
263 void sha1_begin(sha1_ctx_t *ctx);
264 #define sha1_hash libreport_sha1_hash
265 void sha1_hash(sha1_ctx_t *ctx, const void *buffer, size_t len);
266 #define sha1_end libreport_sha1_end
267 void sha1_end(sha1_ctx_t *ctx, void *resbuf);
268 
269 /* Helpers to hash a string: */
270 #define str_to_sha1 libreport_str_to_sha1
271 const uint8_t *str_to_sha1(uint8_t result[SHA1_RESULT_LEN], const char *str);
272 #define str_to_sha1str libreport_str_to_sha1str
273 const char *str_to_sha1str(char result[SHA1_RESULT_LEN*2 + 1], const char *str);
274 
275 
276 #define try_atou libreport_try_atou
277 int try_atou(const char *numstr, unsigned *value);
278 #define xatou libreport_xatou
279 unsigned xatou(const char *numstr);
280 #define try_atoi libreport_try_atoi
281 int try_atoi(const char *numstr, int *value);
282 #define xatoi libreport_xatoi
283 int xatoi(const char *numstr);
284 /* Using xatoi() instead of naive atoi() is not always convenient -
285  * in many places people want *non-negative* values, but store them
286  * in signed int. Therefore we need this one:
287  * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc.
288  * It should really be named xatoi_nonnegative (since it allows 0),
289  * but that would be too long.
290  */
291 #define try_atoi_positive libreport_try_atoi_positive
292 int try_atoi_positive(const char *numstr, int *value);
293 #define xatoi_positive libreport_xatoi_positive
294 int xatoi_positive(const char *numstr);
295 
296 //unused for now
297 //unsigned long long monotonic_ns(void);
298 //unsigned long long monotonic_us(void);
299 //unsigned monotonic_sec(void);
300 
301 #define safe_waitpid libreport_safe_waitpid
302 pid_t safe_waitpid(pid_t pid, int *wstat, int options);
303 
304 enum {
305  /* on return, pipefds[1] is fd to which parent may write
306  * and deliver data to child's stdin: */
307  EXECFLG_INPUT = 1 << 0,
308  /* on return, pipefds[0] is fd from which parent may read
309  * child's stdout: */
310  EXECFLG_OUTPUT = 1 << 1,
311  /* open child's stdin to /dev/null: */
312  EXECFLG_INPUT_NUL = 1 << 2,
313  /* open child's stdout to /dev/null: */
314  EXECFLG_OUTPUT_NUL = 1 << 3,
315  /* redirect child's stderr to stdout: */
316  EXECFLG_ERR2OUT = 1 << 4,
317  /* open child's stderr to /dev/null: */
318  EXECFLG_ERR_NUL = 1 << 5,
319  /* suppress perror_msg("Can't execute 'foo'") if exec fails */
320  EXECFLG_QUIET = 1 << 6,
321  EXECFLG_SETGUID = 1 << 7,
322  EXECFLG_SETSID = 1 << 8,
323  EXECFLG_SETPGID = 1 << 9,
324 };
325 /*
326  * env_vec: list of variables to set in environment (if string has
327  * "VAR=VAL" form) or unset in environment (if string has no '=' char).
328  *
329  * Returns pid.
330  */
331 #define fork_execv_on_steroids libreport_fork_execv_on_steroids
332 pid_t fork_execv_on_steroids(int flags,
333  char **argv,
334  int *pipefds,
335  char **env_vec,
336  const char *dir,
337  uid_t uid);
338 /* Returns malloc'ed string. NULs are retained, and extra one is appended
339  * after the last byte (this NUL is not accounted for in *size_p) */
340 #define run_in_shell_and_save_output libreport_run_in_shell_and_save_output
341 char *run_in_shell_and_save_output(int flags,
342  const char *cmd,
343  const char *dir,
344  size_t *size_p);
345 
346 /* Random utility functions */
347 
348 #define is_in_string_list libreport_is_in_string_list
349 bool is_in_string_list(const char *name, const char *const *v);
350 
351 #define index_of_string_in_list libreport_index_of_string_in_list
352 int index_of_string_in_list(const char *name, const char *const *v);
353 
354 #define is_in_comma_separated_list libreport_is_in_comma_separated_list
355 bool is_in_comma_separated_list(const char *value, const char *list);
356 #define is_in_comma_separated_list_of_glob_patterns libreport_is_in_comma_separated_list_of_glob_patterns
357 bool is_in_comma_separated_list_of_glob_patterns(const char *value, const char *list);
358 
359 /* Calls GLib version appropriate initialization function.
360  */
361 #define glib_init libreport_glib_init
362 void glib_init(void);
363 
364 /* Frees every element'd data using free(),
365  * then frees list itself using g_list_free(list):
366  */
367 #define list_free_with_free libreport_list_free_with_free
368 void list_free_with_free(GList *list);
369 
370 #define get_dirsize libreport_get_dirsize
371 double get_dirsize(const char *pPath);
372 #define get_dirsize_find_largest_dir libreport_get_dirsize_find_largest_dir
373 double get_dirsize_find_largest_dir(
374  const char *pPath,
375  char **worst_dir, /* can be NULL */
376  const char *excluded /* can be NULL */
377 );
378 
379 #define ndelay_on libreport_ndelay_on
380 int ndelay_on(int fd);
381 #define ndelay_off libreport_ndelay_off
382 int ndelay_off(int fd);
383 #define close_on_exec_on libreport_close_on_exec_on
384 int close_on_exec_on(int fd);
385 
386 #define xmalloc libreport_xmalloc
387 void* xmalloc(size_t size);
388 #define xrealloc libreport_xrealloc
389 void* xrealloc(void *ptr, size_t size);
390 #define xzalloc libreport_xzalloc
391 void* xzalloc(size_t size);
392 #define xstrdup libreport_xstrdup
393 char* xstrdup(const char *s);
394 #define xstrndup libreport_xstrndup
395 char* xstrndup(const char *s, int n);
396 #define xstrdup_between libreport_xstrdup_between
397 char* xstrdup_between(const char *s, const char *open, const char *close);
398 
399 #define xpipe libreport_xpipe
400 void xpipe(int filedes[2]);
401 #define xdup libreport_xdup
402 int xdup(int from);
403 #define xdup2 libreport_xdup2
404 void xdup2(int from, int to);
405 #define xmove_fd libreport_xmove_fd
406 void xmove_fd(int from, int to);
407 
408 #define xwrite libreport_xwrite
409 void xwrite(int fd, const void *buf, size_t count);
410 #define xwrite_str libreport_xwrite_str
411 void xwrite_str(int fd, const char *str);
412 
413 #define xlseek libreport_xlseek
414 off_t xlseek(int fd, off_t offset, int whence);
415 
416 #define xchdir libreport_xchdir
417 void xchdir(const char *path);
418 
419 #define xvasprintf libreport_xvasprintf
420 char* xvasprintf(const char *format, va_list p);
421 #define xasprintf libreport_xasprintf
422 char* xasprintf(const char *format, ...);
423 
424 #define xsetenv libreport_xsetenv
425 void xsetenv(const char *key, const char *value);
426 /*
427  * Utility function to unsetenv a string which was possibly putenv'ed.
428  * The problem here is that "natural" optimization:
429  * strchrnul(var_val, '=')[0] = '\0';
430  * unsetenv(var_val);
431  * is BUGGY: if string was put into environment via putenv,
432  * its modification (s/=/NUL/) is illegal, and unsetenv will fail to unset it.
433  * Of course, saving/restoring the char wouldn't work either.
434  * This helper creates a copy up to '=', unsetenv's it, and frees:
435  */
436 #define safe_unsetenv libreport_safe_unsetenv
437 void safe_unsetenv(const char *var_val);
438 
439 #define xsocket libreport_xsocket
440 int xsocket(int domain, int type, int protocol);
441 #define xbind libreport_xbind
442 void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
443 #define xlisten libreport_xlisten
444 void xlisten(int s, int backlog);
445 #define xsendto libreport_xsendto
446 ssize_t xsendto(int s, const void *buf, size_t len,
447  const struct sockaddr *to, socklen_t tolen);
448 
449 #define xstat libreport_xstat
450 void xstat(const char *name, struct stat *stat_buf);
451 #define fstat_st_size_or_die libreport_fstat_st_size_or_die
452 off_t fstat_st_size_or_die(int fd);
453 #define stat_st_size_or_die libreport_stat_st_size_or_die
454 off_t stat_st_size_or_die(const char *filename);
455 
456 #define xopen3 libreport_xopen3
457 int xopen3(const char *pathname, int flags, int mode);
458 #define xopen libreport_xopen
459 int xopen(const char *pathname, int flags);
460 #define xunlink libreport_xunlink
461 void xunlink(const char *pathname);
462 #define xunlinkat libreport_xunlinkat
463 void xunlinkat(int dir_fd, const char *pathname, int flags);
464 
465 /* Just testing dent->d_type == DT_REG is wrong: some filesystems
466  * do not report the type, they report DT_UNKNOWN for every dirent
467  * (and this is not a bug in filesystem, this is allowed by standards).
468  * This function handles this case. Note: it returns 0 on symlinks
469  * even if they point to regular files.
470  */
471 #define is_regular_file libreport_is_regular_file
472 int is_regular_file(struct dirent *dent, const char *dirname);
473 #define is_regular_file_at libreport_is_regular_file_at
474 int is_regular_file_at(struct dirent *dent, int dir_fd);
475 
476 #define dot_or_dotdot libreport_dot_or_dotdot
477 bool dot_or_dotdot(const char *filename);
478 #define last_char_is libreport_last_char_is
479 char *last_char_is(const char *s, int c);
480 
481 #define string_to_bool libreport_string_to_bool
482 bool string_to_bool(const char *s);
483 
484 #define xseteuid libreport_xseteuid
485 void xseteuid(uid_t euid);
486 #define xsetegid libreport_xsetegid
487 void xsetegid(gid_t egid);
488 #define xsetreuid libreport_xsetreuid
489 void xsetreuid(uid_t ruid, uid_t euid);
490 #define xsetregid libreport_xsetregid
491 void xsetregid(gid_t rgid, gid_t egid);
492 
493 #define xfdopen libreport_xfdopen
494 FILE *xfdopen(int fd, const char *mode);
495 
496 /* Emit a string of hex representation of bytes */
497 #define bin2hex libreport_bin2hex
498 char* bin2hex(char *dst, const char *str, int count);
499 /* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */
500 #define hex2bin libreport_hex2bin
501 char* hex2bin(char *dst, const char *str, int count);
502 
503 
504 enum {
505  LOGMODE_NONE = 0,
506  LOGMODE_STDIO = (1 << 0),
507  LOGMODE_SYSLOG = (1 << 1),
508  LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
509  LOGMODE_CUSTOM = (1 << 2),
510  LOGMODE_JOURNAL = (1 << 3),
511 };
512 
513 enum libreport_diemode {
514  DIEMODE_EXIT = 0,
515  DIEMODE_ABORT = 1,
516 };
517 
518 #define g_custom_logger libreport_g_custom_logger
519 extern void (*g_custom_logger)(const char*);
520 #define msg_prefix libreport_msg_prefix
521 extern const char *msg_prefix;
522 #define msg_eol libreport_msg_eol
523 extern const char *msg_eol;
524 #define logmode libreport_logmode
525 extern int logmode;
526 #define xfunc_error_retval libreport_xfunc_error_retval
527 extern int xfunc_error_retval;
528 
529 /* A few magic exit codes */
530 #define EXIT_CANCEL_BY_USER 69
531 #define EXIT_STOP_EVENT_RUN 70
532 
533 #define set_xfunc_error_retval libreport_set_xfunc_error_retval
534 void set_xfunc_error_retval(int retval);
535 
536 #define set_xfunc_diemode libreport_set_xfunc_diemode
537 void set_xfunc_diemode(enum libreport_diemode mode);
538 
539 /* Verbosity level */
540 #define g_verbose libreport_g_verbose
541 extern int g_verbose;
542 /* VERB1 log("what you sometimes want to see, even on a production box") */
543 #define VERB1 if (g_verbose >= 1)
544 /* VERB2 log("debug message, not going into insanely small details") */
545 #define VERB2 if (g_verbose >= 2)
546 /* VERB3 log("lots and lots of details") */
547 #define VERB3 if (g_verbose >= 3)
548 /* there is no level > 3 */
549 
550 #define libreport_
551 #define xfunc_die libreport_xfunc_die
552 void xfunc_die(void) NORETURN;
553 
554 #define die_out_of_memory libreport_die_out_of_memory
555 void die_out_of_memory(void) NORETURN;
556 
557 /* It's a macro, not function, since it collides with log() from math.h */
558 #undef log
559 #define log(...) log_standard(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
560 #define log_debug(...) log_standard(LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
561 #define log_info(...) log_standard(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
562 #define log_notice(...) log_standard(LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
563 #define log_warning(...) log_standard(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
564 #define log_error(...) log_standard(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__)
565 
566 // specific subsystem debugging
567 #define log_parser(...) if(0) log_debug(__VA_ARGS__)
568 
569 #define log_standard(level, file, line, func, ...) log_wrapper(level, __FILE__, __LINE__, __func__, false, false, __VA_ARGS__)
570 
571 // level, file, line, func, perror, custom logger, format & args
572 #define log_error_and_die(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, false, false,__VA_ARGS__)
573 #define log_perror(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, false, __VA_ARGS__)
574 #define log_perror_and_die(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, false, __VA_ARGS__)
575 
576 #define error_msg(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
577 #define perror_msg(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
578 #define warn_msg(...) log_wrapper(LOG_WARNING, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
579 #define pwarn_msg(...) log_wrapper(LOG_WARNING, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
580 #define notice_msg(...) log_wrapper(LOG_NOTICE, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
581 #define pnotice_msg(...) log_wrapper(LOG_NOTICE, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
582 #define error_msg_and_die(...) log_and_die_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
583 #define perror_msg_and_die(...) log_and_die_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
584 
585 
586 void log_wrapper(int level,
587  const char *file,
588  int line,
589  const char *func,
590  bool process_perror,
591  bool use_custom_logger,
592  const char *format, ...) __attribute__ ((format (printf, 7,8)));
593 
594 void log_and_die_wrapper(int level,
595  const char *file,
596  int line,
597  const char *func,
598  bool process_perror,
599  bool use_custom_logger,
600  const char *format, ...) __attribute__ ((noreturn, format (printf, 7,8)));
601 
602 struct strbuf
603 {
604  /* Size of the allocated buffer. Always > 0. */
605  int alloc;
606  /* Length of the string, without the ending \0. */
607  int len;
608  char *buf;
609 };
610 
617 #define strbuf_new libreport_strbuf_new
618 struct strbuf *strbuf_new(void);
619 
625 #define strbuf_free libreport_strbuf_free
626 void strbuf_free(struct strbuf *strbuf);
627 
633 #define strbuf_free_nobuf libreport_strbuf_free_nobuf
634 char* strbuf_free_nobuf(struct strbuf *strbuf);
635 
640 #define strbuf_clear libreport_strbuf_clear
641 void strbuf_clear(struct strbuf *strbuf);
642 
647 #define strbuf_append_char libreport_strbuf_append_char
648 struct strbuf *strbuf_append_char(struct strbuf *strbuf, char c);
649 
654 #define strbuf_append_str libreport_strbuf_append_str
655 struct strbuf *strbuf_append_str(struct strbuf *strbuf,
656  const char *str);
657 
662 #define strbuf_prepend_str libreport_strbuf_prepend_str
663 struct strbuf *strbuf_prepend_str(struct strbuf *strbuf,
664  const char *str);
665 
670 #define strbuf_append_strf libreport_strbuf_append_strf
671 struct strbuf *strbuf_append_strf(struct strbuf *strbuf,
672  const char *format, ...);
673 
678 #define strbuf_append_strfv libreport_strbuf_append_strfv
679 struct strbuf *strbuf_append_strfv(struct strbuf *strbuf,
680  const char *format, va_list p);
681 
687 #define strbuf_prepend_strf libreport_strbuf_prepend_strf
688 struct strbuf *strbuf_prepend_strf(struct strbuf *strbuf,
689  const char *format, ...);
690 
695 #define strbuf_prepend_strfv libreport_strbuf_prepend_strfv
696 struct strbuf *strbuf_prepend_strfv(struct strbuf *strbuf,
697  const char *format, va_list p);
698 
699 /* Returns command line of running program.
700  * Caller is responsible to free() the returned value.
701  * If the pid is not valid or command line can not be obtained,
702  * empty string is returned.
703  */
704 #define open_proc_pid_dir libreport_open_proc_pid_dir
705 int open_proc_pid_dir(pid_t pid);
706 #define get_cmdline_at libreport_get_cmdline_at
707 char* get_cmdline_at(pid_t pid);
708 #define get_cmdline libreport_get_cmdline
709 char* get_cmdline(pid_t pid);
710 #define get_environ_at libreport_get_environ_at
711 char* get_environ_at(pid_t pid);
712 #define get_environ libreport_get_environ
713 char* get_environ(pid_t pid);
714 #define get_executable_at libreport_get_executable_at
715 char *get_executable_at(pid_t pid);
716 #define get_executable libreport_get_executable
717 char *get_executable(pid_t pid);
718 #define get_cwd_at libreport_get_cwd_at
719 char* get_cwd_at(pid_t pid);
720 #define get_cwd libreport_get_cwd
721 char* get_cwd(pid_t pid);
722 #define get_rootdir_at libreport_get_rootdir_at
723 char* get_rootdir_at(pid_t pid);
724 #define get_rootdir libreport_get_rootdir
725 char* get_rootdir(pid_t pid);
726 
727 #define get_fsuid libreport_get_fsuid
728 int get_fsuid(const char *proc_pid_status);
729 #define get_fsgid libreport_get_fsgid
730 int get_fsgid(const char *proc_pid_status);
731 #define dump_fd_info_at libreport_dump_fd_info_at
732 int dump_fd_info_at(int pid_proc_fd, FILE *dest);
733 #define dump_fd_info_ext libreport_dump_fd_info_ext
734 int dump_fd_info_ext(const char *dest_filename, const char *proc_pid_fd_path, uid_t uid, gid_t gid);
735 #define dump_fd_info libreport_dump_fd_info
736 int dump_fd_info(const char *dest_filename, const char *proc_pid_fd_path);
737 #define get_env_variable_ext libreport_get_env_variable_ext
738 int get_env_variable_ext(int fd, char delim, const char *name, char **value);
739 #define get_env_variable libreport_get_env_variable
740 int get_env_variable(pid_t pid, const char *name, char **value);
741 
742 #define PROC_NS_UNSUPPORTED ((ino_t)-1)
743 #define PROC_NS_ID_IPC 0
744 #define PROC_NS_ID_MNT 1
745 #define PROC_NS_ID_NET 2
746 #define PROC_NS_ID_PID 3
747 #define PROC_NS_ID_USER 4
748 #define PROC_NS_ID_UTS 5
749 #define PROC_NS_ID_CGROUP 6
750 static const char * libreport_proc_namespaces[] = { "ipc", "mnt", "net", "pid", "uts", "user", "cgroup" };
751 
752 struct ns_ids {
753  ino_t nsi_ids[ARRAY_SIZE(libreport_proc_namespaces)];
754 };
755 
756 #define get_ns_ids_at libreport_get_ns_ids_at
757 int get_ns_ids_at(int pid_proc_fd, struct ns_ids *ids);
758 #define get_ns_ids libreport_get_ns_ids
759 int get_ns_ids(pid_t pid, struct ns_ids *ids);
760 
761 /* These functions require a privileged user and does not work correctly in
762  * processes running in own PID namespace
763  */
764 #define process_has_own_root_at libreport_process_has_own_root_at
765 int process_has_own_root_at(int proc_pid_fd);
766 #define process_has_own_root libreport_process_has_own_root
767 int process_has_own_root(pid_t pid);
768 
769 #define get_pid_of_container_at libreport_get_pid_of_container_at
770 int get_pid_of_container_at(int pid_proc_fd, pid_t *init_pid);
771 #define get_pid_of_container libreport_get_pid_of_container
772 int get_pid_of_container(pid_t pid, pid_t *init_pid);
773 #define dump_namespace_diff_at libreport_dump_namespace_diff_at
774 int dump_namespace_diff_at(int base_pid_proc_fd, int tested_pid_proc_fd, FILE *dest);
775 #define dump_namespace_diff_ext libreport_dump_namespace_diff_ext
776 int dump_namespace_diff_ext(const char *dest_filename, pid_t base_pid, pid_t tested_pid, uid_t uid, gid_t gid);
777 #define dump_namespace_diff libreport_dump_namespace_diff
778 int dump_namespace_diff(const char *dest_filename, pid_t base_pid, pid_t tested_pid);
779 
780 enum
781 {
782  MOUNTINFO_INDEX_MOUNT_ID,
783  MOUNTINFO_INDEX_PARENT_ID,
784  MOUNTINFO_INDEX_MAJOR_MINOR,
785  MOUNTINFO_INDEX_ROOT,
786  MOUNTINFO_INDEX_MOUNT_POINT,
787  MOUNTINFO_INDEX_MOUNT_OPTIONS,
788  MOUNTINFO_INDEX_OPTIONAL_FIELDS,
789  MOUNTINFO_INDEX_FS_TYPE,
790  MOUNTINFO_INDEX_MOUNT_SOURCE,
791  MOUNTINFO_INDEX_SUPER_OPITONS,
792  _MOUNTINFO_INDEX_MAX,
793 };
794 
795 #define MOUNTINFO_ROOT(val) (val.mntnf_items[MOUNTINFO_INDEX_ROOT])
796 #define MOUNTINFO_MOUNT_POINT(val) (val.mntnf_items[MOUNTINFO_INDEX_MOUNT_POINT])
797 #define MOUNTINFO_MOUNT_SOURCE(val) (val.mntnf_items[MOUNTINFO_INDEX_MOUNT_SOURCE])
798 
799 struct mountinfo
800 {
801  /* 4 : root of the mount within the filesystem */
802  /* 5 : mount point relative to the process's root */
803  /* 10 : mount source: filesystem specific information or "none" */
804  /* but it mount source is preceded by 0 or more optional fields */
805  /* so the effective value is 9 */
806  char *mntnf_items[_MOUNTINFO_INDEX_MAX];
807 };
808 #define mountinfo_destroy libreport_mountinfo_destroy
809 void mountinfo_destroy(struct mountinfo *mntnf);
810 #define get_mountinfo_for_mount_point libreport_get_mountinfo_for_mount_point
811 int get_mountinfo_for_mount_point(FILE *fin, struct mountinfo *mntnf, const char *mnt_point);
812 
813 /* Takes ptr to time_t, or NULL if you want to use current time.
814  * Returns "YYYY-MM-DD-hh:mm:ss" string.
815  */
816 #define iso_date_string libreport_iso_date_string
817 char *iso_date_string(const time_t *pt);
818 #define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss"
819 #define LIBREPORT_ISO_DATE_STRING_FORMAT "%Y-%m-%d-%H:%M:%S"
820 
821 /* Parses date into integer UNIX time stamp
822  *
823  * @param date The parsed date string
824  * @param pt Return value
825  * @return 0 on success; otherwise non-0 number. -EINVAL if the parameter date
826  * does not match LIBREPORT_ISO_DATE_STRING_FORMAT
827  */
828 #define iso_date_string_parse libreport_iso_date_string_parse
829 int iso_date_string_parse(const char *date, time_t *pt);
830 
831 enum {
832  MAKEDESC_SHOW_FILES = (1 << 0),
833  MAKEDESC_SHOW_MULTILINE = (1 << 1),
834  MAKEDESC_SHOW_ONLY_LIST = (1 << 2),
835  MAKEDESC_WHITELIST = (1 << 3),
836  /* Include all URLs from FILENAME_REPORTED_TO element in the description text */
837  MAKEDESC_SHOW_URLS = (1 << 4),
838 };
839 #define make_description libreport_make_description
840 char *make_description(problem_data_t *problem_data, char **names_to_skip, unsigned max_text_size, unsigned desc_flags);
841 #define make_description_logger libreport_make_description_logger
842 char* make_description_logger(problem_data_t *problem_data, unsigned max_text_size);
843 
844 /* See man os-release(5) for details */
845 #define OSINFO_ID "ID"
846 #define OSINFO_NAME "NAME"
847 #define OSINFO_VERSION_ID "VERSION_ID"
848 #define OSINFO_PRETTY_NAME "PRETTY_NAME"
849 
850 /* @brief Loads a text in format of os-release(5) in to a map
851  *
852  * Function doesn't check for format errors much. It just tries to avoid
853  * program errors. In case of error the function prints out a log message and
854  * continues in parsing.
855  *
856  * @param osinfo_bytes Non-NULL pointer to osinfo bytes.
857  * @param osinfo The map where result is stored
858  */
859 #define parse_osinfo libreport_parse_osinfo
860 void parse_osinfo(const char *osinfo_bytes, map_string_t *osinfo);
861 
862 /* @brief Builds product string and product's version string for Bugzilla
863  *
864  * At first tries to get strings from the os specific variables
865  * (REDHAT_BUGZILLA_PRODUCT, REDHAT_BUGZILLA_PRODUCT_VERSION) if no such
866  * variables are found, uses NAME key for the product and VERSION_ID key for
867  * the product's version. If neither NAME nor VERSION_ID are provided fallbacks
868  * to parsing of os_release which should be stored under PRETTY_NAME key.
869  *
870  * https://bugzilla.redhat.com/show_bug.cgi?id=950373
871  *
872  * @param osinfo Input data from which the values are built
873  * @param produc Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
874  * @param version Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
875  */
876 #define parse_osinfo_for_bz libreport_parse_osinfo_for_bz
877 void parse_osinfo_for_bz(map_string_t *osinfo, char **product, char **version);
878 
879 /* @brief Extract BUG_REPORT_URL from os-release
880  *
881  * A default location for bug reports can be stored in os-release.
882  * This extracts the value if present and stores it in url.
883  * If unset, url will become NULL
884  *
885  * https://github.com/abrt/libreport/issues/459
886  *
887  * @param osinfo Input data from which the values are built
888  * @param url Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
889  */
890 #define parse_osinfo_for_bug_url libreport_parse_osinfo_for_bug_url
891 void parse_osinfo_for_bug_url(map_string_t *osinfo, char** url);
892 
893 /* @brief Builds product string and product's version string for Red Hat Support
894  *
895  * At first tries to get strings from the os specific variables
896  * (REDHAT_SUPPORT_PRODUCT, REDHAT_SUPPORT_PRODUCT_VERSION) if no such
897  * variables are found, uses NAME key for the product and VERSION_ID key for
898  * the product's version. If no NAME nor VERSION_ID are provided fallbacks to
899  * parsing of os_release which should be stored under PRETTY_NAME key.
900  *
901  * https://bugzilla.redhat.com/show_bug.cgi?id=950373
902  *
903  * @param osinfo Input data from which the values are built
904  * @param produc Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
905  * @param version Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
906  */
907 #define parse_osinfo_for_rhts libreport_parse_osinfo_for_rhts
908 void parse_osinfo_for_rhts(map_string_t *osinfo, char **product, char **version);
909 
910 #define parse_release_for_bz libreport_parse_release_for_bz
911 void parse_release_for_bz(const char *pRelease, char **product, char **version);
912 #define parse_release_for_rhts libreport_parse_release_for_rhts
913 void parse_release_for_rhts(const char *pRelease, char **product, char **version);
914 
929 #define load_conf_file libreport_load_conf_file
930 bool load_conf_file(const char *pPath, map_string_t *settings, bool skipKeysWithoutValue);
931 #define load_plugin_conf_file libreport_load_plugin_conf_file
932 bool load_plugin_conf_file(const char *name, map_string_t *settings, bool skipKeysWithoutValue);
933 
934 #define get_user_conf_base_dir libreport_get_user_conf_base_dir
935 const char *get_user_conf_base_dir(void);
936 
937 #define load_conf_file_from_dirs libreport_load_conf_file_from_dirs
938 bool load_conf_file_from_dirs(const char *base_name, const char *const *directories, map_string_t *settings, bool skipKeysWithoutValue);
939 
940 enum {
941  CONF_DIR_FLAG_NONE = 0,
942  CONF_DIR_FLAG_OPTIONAL = 1,
943 };
944 
945 #define load_conf_file_from_dirs_ext libreport_load_conf_file_from_dirs_ext
946 bool load_conf_file_from_dirs_ext(const char *base_name, const char *const *directories,
947  const int * dir_flags, map_string_t *settings,
948  bool skipKeysWithoutValue);
949 
950 #define save_conf_file libreport_save_conf_file
951 bool save_conf_file(const char *path, map_string_t *settings);
952 #define save_plugin_conf_file libreport_save_plugin_conf_file
953 bool save_plugin_conf_file(const char *name, map_string_t *settings);
954 
955 #define save_app_conf_file libreport_save_app_conf_file
956 bool save_app_conf_file(const char* application_name, map_string_t *settings);
957 #define load_app_conf_file libreport_load_app_conf_file
958 bool load_app_conf_file(const char *application_name, map_string_t *settings);
959 #define set_app_user_setting libreport_set_app_user_setting
960 void set_app_user_setting(map_string_t *settings, const char *name, const char *value);
961 #define get_app_user_setting libreport_get_app_user_setting
962 const char *get_app_user_setting(map_string_t *settings, const char *name);
963 
964 #define save_user_settings libreport_save_user_settings
965 bool save_user_settings(void);
966 #define load_user_settings libreport_load_user_settings
967 bool load_user_settings(const char *application_name);
968 #define set_user_setting libreport_set_user_setting
969 void set_user_setting(const char *name, const char *value);
970 #define get_user_setting libreport_get_user_setting
971 const char *get_user_setting(const char *name);
972 
973 /* filename is expected to exist in CONF_DIR
974  * usually /etc/libreport
975  */
976 #define load_forbidden_words libreport_load_forbidden_words
977 GList *load_words_from_file(const char *filename);
978 #define get_file_list libreport_get_file_list
979 GList *get_file_list(const char *path, const char *ext);
980 #define free_file_list libreport_free_file_list
981 void free_file_list(GList *filelist);
982 #define new_file_obj libreport_new_file_obj
983 file_obj_t *new_file_obj(const char* fullpath, const char* filename);
984 #define free_file_obj libreport_free_file_obj
985 void free_file_obj(file_obj_t *f);
986 #define parse_delimited_list libreport_parse_delimited_list
987 GList *parse_delimited_list(char* list, const char *delim);
988 #define parse_list libreport_parse_list
989 GList *parse_list(const char* list);
990 
991 /* Connect to abrtd over unix domain socket, issue DELETE command */
992 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
993 
994 /* Tries to create a copy of dump_dir_name in base_dir, with same or similar basename.
995  * Returns NULL if copying failed. In this case, logs a message before returning. */
996 #define steal_directory libreport_steal_directory
997 struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name);
998 
999 /* Resolves if the given user is in given group
1000  *
1001  * @param uid user ID
1002  * @param gid group ID
1003  * @returns TRUE in case the user is in the group otherwise returns FALSE
1004  */
1005 #define uid_in_group libreport_uid_in_group
1006 bool uid_in_group(uid_t uid, gid_t gid);
1007 
1008 /* Tries to open dump_dir_name with writing access. If function needs to steal
1009  * directory calls ask_continue(new base dir, dump dir) callback to ask user
1010  * for permission. If ask_continue param is NULL the function thinks that an
1011  * answer is positive and steals directory.
1012  * Returns NULL if opening failed or if stealing was dismissed. In this case,
1013  * logs a message before returning. */
1014 #define open_directory_for_writing libreport_open_directory_for_writing
1015 struct dump_dir *open_directory_for_writing(
1016  const char *dump_dir_name,
1017  bool (*ask_continue)(const char *, const char *));
1018 
1019 // Files bigger than this are never considered to be text.
1020 //
1021 // Started at 64k limit. But _some_ limit is necessary:
1022 // fields declared "text" may end up in editing fields and such.
1023 // We don't want to accidentally end up with 100meg text in a textbox!
1024 // So, don't remove this. If you really need to, raise the limit.
1025 //
1026 // Bumped up to 200k: saw 124740 byte /proc/PID/smaps file
1027 // Bumped up to 500k: saw 375252 byte anaconda traceback file
1028 // Bumped up to 1M: bugzilla.redhat.com/show_bug.cgi?id=746727
1029 // mentions 853646 byte anaconda-tb-* file.
1030 // Bumped up to 8M: bugzilla.redhat.com/show_bug.cgi?id=887570
1031 // (anaconda-tb file of 1.38 MBytes)
1032 //
1033 #define CD_MAX_TEXT_SIZE (8*1024*1024)
1034 
1035 // Text bigger than this usually is attached, not added inline
1036 // was 2k, 20kb is too much, let's try 4kb
1037 //
1038 // For bug databases
1039 #define CD_TEXT_ATT_SIZE_BZ (4*1024)
1040 // For dumping problem data into a text file, email, etc
1041 #define CD_TEXT_ATT_SIZE_LOGGER (CD_MAX_TEXT_SIZE)
1042 
1043 // Filenames in problem directory:
1044 // filled by a hook:
1045 #define FILENAME_TIME "time" /* mandatory */
1046 #define FILENAME_LAST_OCCURRENCE "last_occurrence" /* optional */
1047 #define FILENAME_REASON "reason" /* mandatory? */
1048 #define FILENAME_UID "uid" /* mandatory? */
1049 
1050 /*
1051  * "analyzer" is to be gradually changed to "type":
1052  * For now, we fetch and look at "analyzer" element,
1053  * but we always save both "analyzer" and "type" (with same contents).
1054  * By 2013, we switch to looking at "type". Then we will stop generating
1055  * "analyzer" element.
1056  * ----
1057  * Update 2015: based on the recent changes where we have introduced several
1058  * tools generating one problem type, we have decided to retain 'analyzer'
1059  * file, but it shall contain string identifier of a tool that created the
1060  * problem.
1061  */
1062 #define FILENAME_ANALYZER "analyzer"
1063 #define FILENAME_TYPE "type"
1064 #define FILENAME_EXECUTABLE "executable"
1065 #define FILENAME_PID "pid"
1066 #define FILENAME_TID "tid"
1067 #define FILENAME_GLOBAL_PID "global_pid"
1068 #define FILENAME_PWD "pwd"
1069 #define FILENAME_ROOTDIR "rootdir"
1070 #define FILENAME_BINARY "binary"
1071 #define FILENAME_CMDLINE "cmdline"
1072 #define FILENAME_COREDUMP "coredump"
1073 #define FILENAME_CGROUP "cgroup"
1074 #define FILENAME_BACKTRACE "backtrace"
1075 #define FILENAME_MAPS "maps"
1076 #define FILENAME_SMAPS "smaps"
1077 #define FILENAME_PROC_PID_STATUS "proc_pid_status"
1078 #define FILENAME_ENVIRON "environ"
1079 #define FILENAME_LIMITS "limits"
1080 #define FILENAME_OPEN_FDS "open_fds"
1081 #define FILENAME_MOUNTINFO "mountinfo"
1082 #define FILENAME_NAMESPACES "namespaces"
1083 
1084 /* Global problem identifier which is usually generated by some "analyze_*"
1085  * event because it may take a lot of time to obtain strong problem
1086  * identification */
1087 #define FILENAME_DUPHASH "duphash"
1088 
1089 // Name of the function where the application crashed.
1090 // Optional.
1091 #define FILENAME_CRASH_FUNCTION "crash_function"
1092 #define FILENAME_ARCHITECTURE "architecture"
1093 #define FILENAME_KERNEL "kernel"
1094 /*
1095  * From /etc/os-release
1096  * os_release filename name is alredy occupied by /etc/redhat-release (see
1097  * below) in sake of backward compatibility /etc/os-release is stored in
1098  * os_info file
1099  */
1100 #define FILENAME_OS_INFO "os_info"
1101 #define FILENAME_OS_INFO_IN_ROOTDIR "os_info_in_rootdir"
1102 // From /etc/system-release or /etc/redhat-release
1103 #define FILENAME_OS_RELEASE "os_release"
1104 #define FILENAME_OS_RELEASE_IN_ROOTDIR "os_release_in_rootdir"
1105 // Filled by <what?>
1106 #define FILENAME_PACKAGE "package"
1107 #define FILENAME_COMPONENT "component"
1108 #define FILENAME_COMMENT "comment"
1109 #define FILENAME_RATING "backtrace_rating"
1110 #define FILENAME_HOSTNAME "hostname"
1111 // Optional. Set to "1" by abrt-handle-upload for every unpacked dump
1112 #define FILENAME_REMOTE "remote"
1113 #define FILENAME_TAINTED "kernel_tainted"
1114 #define FILENAME_TAINTED_SHORT "kernel_tainted_short"
1115 #define FILENAME_TAINTED_LONG "kernel_tainted_long"
1116 #define FILENAME_VMCORE "vmcore"
1117 #define FILENAME_KERNEL_LOG "kernel_log"
1118 // File created by createAlertSignature() from libreport's python module
1119 // The file should contain a description of an alert
1120 #define FILENAME_DESCRIPTION "description"
1121 
1122 /* Local problem identifier (weaker than global identifier) designed for fast
1123  * local for fast local duplicate identification. This file is usually provided
1124  * by crashed application (problem creator).
1125  */
1126 #define FILENAME_UUID "uuid"
1127 
1128 #define FILENAME_COUNT "count"
1129 /* Multi-line list of places problem was reported.
1130  * Recommended line format:
1131  * "Reporter: VAR=VAL VAR=VAL"
1132  * Use add_reported_to(dd, "line_without_newline"): it adds line
1133  * only if it is not already there.
1134  */
1135 #define FILENAME_REPORTED_TO "reported_to"
1136 #define FILENAME_EVENT_LOG "event_log"
1137 /*
1138  * If exists, should contain a full sentence (with trailing period)
1139  * which describes why this problem should not be reported.
1140  * Example: "Your laptop firmware 1.9a is buggy, version 1.10 contains the fix."
1141  */
1142 #define FILENAME_NOT_REPORTABLE "not-reportable"
1143 #define FILENAME_CORE_BACKTRACE "core_backtrace"
1144 #define FILENAME_REMOTE_RESULT "remote_result"
1145 #define FILENAME_PKG_EPOCH "pkg_epoch"
1146 #define FILENAME_PKG_NAME "pkg_name"
1147 #define FILENAME_PKG_VERSION "pkg_version"
1148 #define FILENAME_PKG_RELEASE "pkg_release"
1149 #define FILENAME_PKG_ARCH "pkg_arch"
1150 
1151 /* RHEL packages - Red Hat, Inc. */
1152 #define FILENAME_PKG_VENDOR "pkg_vendor"
1153 /* RHEL keys - https://access.redhat.com/security/team/key */
1154 #define FILENAME_PKG_FINGERPRINT "pkg_fingerprint"
1155 
1156 #define FILENAME_USERNAME "username"
1157 #define FILENAME_ABRT_VERSION "abrt_version"
1158 #define FILENAME_EXPLOITABLE "exploitable"
1159 
1160 /* reproducible element is used by functions from problem_data.h */
1161 #define FILENAME_REPRODUCIBLE "reproducible"
1162 #define FILENAME_REPRODUCER "reproducer"
1163 
1164 /* File names related to Anaconda problems
1165  */
1166 #define FILENAME_KICKSTART_CFG "ks.cfg"
1167 #define FILENAME_ANACONDA_TB "anaconda-tb"
1168 
1169 /* Containers
1170  */
1171 #define FILENAME_CONTAINER "container"
1172 #define FILENAME_CONTAINER_ID "container_id"
1173 #define FILENAME_CONTAINER_UUID "container_uuid"
1174 #define FILENAME_CONTAINER_IMAGE "container_image"
1175 #define FILENAME_CONTAINER_CMDLINE "container_cmdline"
1176 /* Container root file-system directory as seen from the host. */
1177 #define FILENAME_CONTAINER_ROOTFS "container_rootfs"
1178 #define FILENAME_DOCKER_INSPECT "docker_inspect"
1179 
1180 /* Type of catched exception
1181  * Optional.
1182  */
1183 #define FILENAME_EXCEPTION_TYPE "exception_type"
1184 
1185 // Not stored as files, added "on the fly":
1186 #define CD_DUMPDIR "Directory"
1187 
1188 #define cmp_problem_data libreport_cmp_problem_data
1189 gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename);
1190 
1191 //UNUSED:
1194 //#define CD_EVENTS "Events"
1195 
1196 /* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK
1197  * when it reaches HIGH_WATERMARK size
1198  */
1199 enum {
1200  EVENT_LOG_HIGH_WATERMARK = 30 * 1024,
1201  EVENT_LOG_LOW_WATERMARK = 20 * 1024,
1202 };
1203 
1204 #define log_problem_data libreport_log_problem_data
1205 void log_problem_data(problem_data_t *problem_data, const char *pfx);
1206 
1207 extern int g_libreport_inited;
1208 void libreport_init(void);
1209 
1210 #define INITIALIZE_LIBREPORT() \
1211  do \
1212  { \
1213  if (!g_libreport_inited) \
1214  { \
1215  g_libreport_inited = 1; \
1216  libreport_init(); \
1217  } \
1218  } \
1219  while (0)
1220 
1221 const char *abrt_init(char **argv);
1222 #define export_abrt_envvars libreport_export_abrt_envvars
1223 void export_abrt_envvars(int pfx);
1224 #define g_progname libreport_g_progname
1225 extern const char *g_progname;
1226 
1227 enum parse_opt_type {
1228  OPTION_BOOL,
1229  OPTION_GROUP,
1230  OPTION_STRING,
1231  OPTION_INTEGER,
1232  OPTION_OPTSTRING,
1233  OPTION_LIST,
1234  OPTION_END,
1235 };
1236 
1237 struct options {
1238  enum parse_opt_type type;
1239  int short_name;
1240  const char *long_name;
1241  void *value;
1242  const char *argh;
1243  const char *help;
1244 };
1245 
1246 /*
1247  * s - short_name
1248  * l - long_name
1249  * v - value
1250  * a - option parameter name (for help text)
1251  * h - help
1252  */
1253 #define OPT_END() { OPTION_END }
1254 #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
1255 #define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) }
1256 #define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) }
1257 #define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) }
1258 #define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) }
1259 #define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) }
1260 
1261 #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose"))
1262 #define OPT__DUMP_DIR(v) OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory"))
1263 
1264 #define parse_opts libreport_parse_opts
1265 unsigned parse_opts(int argc, char **argv, const struct options *opt,
1266  const char *usage);
1267 
1268 #define show_usage_and_die libreport_show_usage_and_die
1269 void show_usage_and_die(const char *usage, const struct options *opt) NORETURN;
1270 
1271 /* Can't include "abrt_curl.h", it's not a public API.
1272  * Resorting to just forward-declaring the struct we need.
1273  */
1274 struct abrt_post_state;
1275 
1276 /* Decomposes uri to its base elements, removes userinfo out of the hostname and
1277  * composes a new uri without userinfo.
1278  *
1279  * The function does not validate the url.
1280  *
1281  * @param uri The uri that might contain userinfo
1282  * @param result The userinfo free uri will be store here. Cannot be null. Must
1283  * be de-allocated by free.
1284  * @param scheme Scheme of the uri. Can be NULL. Result can be NULL. Result
1285  * must be de-allocated by free.
1286  * @param hostname Hostname of the uri. Can be NULL. Result can be NULL. Result
1287  * must be de-allocated by free.
1288  * @param username Username of the uri. Can be NULL. Result can be NULL. Result
1289  * must be de-allocated by free.
1290  * @param password Password of the uri. Can be NULL. Result can be NULL. Result
1291  * must be de-allocated by free.
1292  * @param location Location of the uri. Can be NULL. Result is never NULL. Result
1293  * must be de-allocated by free.
1294  */
1295 #define uri_userinfo_remove libreport_uri_userinfo_remove
1296 int uri_userinfo_remove(const char *uri, char **result, char **scheme, char **hostname, char **username, char **password, char **location);
1297 
1298 #ifdef __cplusplus
1299 }
1300 #endif
1301 
1302 #endif