libreport  2.1.3
A tool to inform users about various problems on the running system
dump_dir.h
00001 /*
00002     On-disk storage of problem data
00003 
00004     Copyright (C) 2009  Zdenek Prikryl (zprikryl@redhat.com)
00005     Copyright (C) 2009  RedHat inc.
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License along
00018     with this program; if not, write to the Free Software Foundation, Inc.,
00019     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020 */
00021 #ifndef LIBREPORT_DUMP_DIR_H_
00022 #define LIBREPORT_DUMP_DIR_H_
00023 
00024 /* For DIR */
00025 #include <sys/types.h>
00026 #include <dirent.h>
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 enum {
00033     DD_FAIL_QUIETLY_ENOENT = (1 << 0),
00034     DD_FAIL_QUIETLY_EACCES = (1 << 1),
00035     /* Open symlinks. dd_* funcs don't open symlinks by default */
00036     DD_OPEN_FOLLOW = (1 << 2),
00037     DD_OPEN_READONLY = (1 << 3),
00038 };
00039 
00040 struct dump_dir {
00041     char *dd_dirname;
00042     DIR *next_dir;
00043     int locked;
00044     uid_t dd_uid;
00045     gid_t dd_gid;
00046     /* mode fo saved files */
00047     mode_t mode;
00048     time_t dd_time;
00049 };
00050 
00051 void dd_close(struct dump_dir *dd);
00052 
00053 struct dump_dir *dd_opendir(const char *dir, int flags);
00054 /* Pass uid = (uid_t)-1L to disable chown'ing of newly created files
00055  * (IOW: if you aren't running under root):
00056  */
00057 struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode);
00058 
00059 void dd_create_basic_files(struct dump_dir *dd, uid_t uid, const char *chroot_dir);
00060 int dd_exist(const struct dump_dir *dd, const char *path);
00061 void dd_sanitize_mode_and_owner(struct dump_dir *dd);
00062 
00063 DIR *dd_init_next_file(struct dump_dir *dd);
00064 int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name);
00065 
00066 enum {
00067     /* DD_FAIL_QUIETLY_ENOENT bit is valid for dd_load_text_ext too, */
00068     DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE = (DD_OPEN_READONLY << 1),
00069 };
00070 char* dd_load_text_ext(const struct dump_dir *dd, const char *name, unsigned flags);
00071 char* dd_load_text(const struct dump_dir *dd, const char *name);
00072 void dd_save_text(struct dump_dir *dd, const char *name, const char *data);
00073 void dd_save_binary(struct dump_dir *dd, const char *name, const char *data, unsigned size);
00074 /* Returns value less than 0 if any error occured; otherwise returns size of an
00075  * item in Bytes. If an item does not exist returns 0 instead of an error
00076  * value.
00077  */
00078 long dd_get_item_size(struct dump_dir *dd, const char *name);
00079 /* Deletes an item from dump directory
00080  * On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
00081  * For more about errno see unlink documentation
00082  */
00083 int dd_delete_item(struct dump_dir *dd, const char *name);
00084 /* Returns 0 if directory is deleted or not found */
00085 int dd_delete(struct dump_dir *dd);
00086 int dd_rename(struct dump_dir *dd, const char *new_path);
00087 /* Changes owner of dump dir
00088  * Uses two different strategies selected at build time by
00089  * DUMP_DIR_OWNED_BY_USER configuration:
00090  *  <= 0 : owner = abrt user's uid,  group = new_uid's gid
00091  *   > 0 : owner = new_uid,          group = abrt group's gid
00092  *
00093  * On success, zero is returned. On error, -1 is returned.
00094  */
00095 int dd_chown(struct dump_dir *dd, uid_t new_uid);
00096 
00097 
00098 /* reported_to handling */
00099 #define add_reported_to libreport_add_reported_to
00100 void add_reported_to(struct dump_dir *dd, const char *line);
00101 struct report_result {
00102     char *url;
00103     char *msg;
00104     char *bthash;
00105     /* char *whole_line; */
00106     /* time_t timestamp; */
00107     /* ^^^ if you add more fields, don't forget to update free_report_result() */
00108 };
00109 typedef struct report_result report_result_t;
00110 #define free_report_result libreport_free_report_result
00111 void free_report_result(struct report_result *result);
00112 #define find_in_reported_to libreport_find_in_reported_to
00113 report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix);
00114 /* TODO: GList *read_entire_reported_to(dd); */
00115 
00116 
00117 void delete_dump_dir(const char *dirname);
00118 /* Checks dump dir accessibility for particular uid.
00119  *
00120  * If the directory doesn't exist the directory is not accessible and errno is
00121  * set to ENOTDIR.
00122  *
00123  * Returns non zero if dump dir is accessible otherwise return 0 value.
00124  */
00125 int dump_dir_accessible_by_uid(const char *dirname, uid_t uid);
00126 
00127 /* creates not_reportable file in the problem directory and saves the
00128    reason to it, which prevents libreport from reporting the problem
00129    On success, zero is returned.
00130    On error, -1 is returned and an error message is logged.
00131      - this could probably happen only if the dump dir is not locked
00132 */
00133 int dd_mark_as_notreportable(struct dump_dir *dd, const char *reason);
00134 
00135 #ifdef __cplusplus
00136 }
00137 #endif
00138 
00139 #endif