libreport  2.1.5
A tool to inform users about various problems on the running system
dump_dir.h
1 /*
2  On-disk storage of problem data
3 
4  Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
5  Copyright (C) 2009 RedHat inc.
6 
7  This program 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 2 of the License, or
10  (at your option) any later version.
11 
12  This program 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  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21 #ifndef LIBREPORT_DUMP_DIR_H_
22 #define LIBREPORT_DUMP_DIR_H_
23 
24 /* For DIR */
25 #include <sys/types.h>
26 #include <dirent.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 enum {
33  DD_FAIL_QUIETLY_ENOENT = (1 << 0),
34  DD_FAIL_QUIETLY_EACCES = (1 << 1),
35  /* Open symlinks. dd_* funcs don't open symlinks by default */
36  DD_OPEN_FOLLOW = (1 << 2),
37  DD_OPEN_READONLY = (1 << 3),
38  DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE = (1 << 4),
39  DD_DONT_WAIT_FOR_LOCK = (1 << 5),
40 };
41 
42 struct dump_dir {
43  char *dd_dirname;
44  DIR *next_dir;
45  int locked;
46  uid_t dd_uid;
47  gid_t dd_gid;
48  /* mode fo saved files */
49  mode_t mode;
50  time_t dd_time;
51 };
52 
53 void dd_close(struct dump_dir *dd);
54 
55 struct dump_dir *dd_opendir(const char *dir, int flags);
56 /* Pass uid = (uid_t)-1L to disable chown'ing of newly created files
57  * (IOW: if you aren't running under root):
58  */
59 struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode);
60 
61 void dd_create_basic_files(struct dump_dir *dd, uid_t uid, const char *chroot_dir);
62 int dd_exist(const struct dump_dir *dd, const char *path);
63 void dd_sanitize_mode_and_owner(struct dump_dir *dd);
64 
65 DIR *dd_init_next_file(struct dump_dir *dd);
66 int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name);
67 
68 char* dd_load_text_ext(const struct dump_dir *dd, const char *name, unsigned flags);
69 char* dd_load_text(const struct dump_dir *dd, const char *name);
70 void dd_save_text(struct dump_dir *dd, const char *name, const char *data);
71 void dd_save_binary(struct dump_dir *dd, const char *name, const char *data, unsigned size);
72 /* Returns value less than 0 if any error occured; otherwise returns size of an
73  * item in Bytes. If an item does not exist returns 0 instead of an error
74  * value.
75  */
76 long dd_get_item_size(struct dump_dir *dd, const char *name);
77 /* Deletes an item from dump directory
78  * On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
79  * For more about errno see unlink documentation
80  */
81 int dd_delete_item(struct dump_dir *dd, const char *name);
82 /* Returns 0 if directory is deleted or not found */
83 int dd_delete(struct dump_dir *dd);
84 int dd_rename(struct dump_dir *dd, const char *new_path);
85 /* Changes owner of dump dir
86  * Uses two different strategies selected at build time by
87  * DUMP_DIR_OWNED_BY_USER configuration:
88  * <= 0 : owner = abrt user's uid, group = new_uid's gid
89  * > 0 : owner = new_uid, group = abrt group's gid
90  *
91  * On success, zero is returned. On error, -1 is returned.
92  */
93 int dd_chown(struct dump_dir *dd, uid_t new_uid);
94 
95 
96 /* reported_to handling */
97 #define add_reported_to libreport_add_reported_to
98 void add_reported_to(struct dump_dir *dd, const char *line);
99 struct report_result {
100  char *url;
101  char *msg;
102  char *bthash;
103  /* char *whole_line; */
104  /* time_t timestamp; */
105  /* ^^^ if you add more fields, don't forget to update free_report_result() */
106 };
107 typedef struct report_result report_result_t;
108 #define free_report_result libreport_free_report_result
109 void free_report_result(struct report_result *result);
110 #define find_in_reported_to libreport_find_in_reported_to
111 report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix);
112 /* TODO: GList *read_entire_reported_to(dd); */
113 
114 
115 void delete_dump_dir(const char *dirname);
116 /* Checks dump dir accessibility for particular uid.
117  *
118  * If the directory doesn't exist the directory is not accessible and errno is
119  * set to ENOTDIR.
120  *
121  * Returns non zero if dump dir is accessible otherwise return 0 value.
122  */
123 int dump_dir_accessible_by_uid(const char *dirname, uid_t uid);
124 
125 enum {
126  DD_STAT_ACCESSIBLE_BY_UID = 1,
127  DD_STAT_OWNED_BY_UID = DD_STAT_ACCESSIBLE_BY_UID << 1,
128 };
129 
130 /* Gets information about a dump directory for particular uid.
131  *
132  * If the directory doesn't exist the directory is not accessible and errno is
133  * set to ENOTDIR.
134  *
135  * Returns negative number if error occurred otherwise returns 0 or positive number.
136  */
137 int dump_dir_stat_for_uid(const char *dirname, uid_t uid);
138 
139 /* creates not_reportable file in the problem directory and saves the
140  reason to it, which prevents libreport from reporting the problem
141  On success, zero is returned.
142  On error, -1 is returned and an error message is logged.
143  - this could probably happen only if the dump dir is not locked
144 */
145 int dd_mark_as_notreportable(struct dump_dir *dd, const char *reason);
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif