Blame src/include/dump_dir.h

Packit Service 779887
/*
Packit Service 779887
    On-disk storage of problem data
Packit Service 779887
Packit Service 779887
    Copyright (C) 2009  Zdenek Prikryl (zprikryl@redhat.com)
Packit Service 779887
    Copyright (C) 2009  RedHat inc.
Packit Service 779887
Packit Service 779887
    This program is free software; you can redistribute it and/or modify
Packit Service 779887
    it under the terms of the GNU General Public License as published by
Packit Service 779887
    the Free Software Foundation; either version 2 of the License, or
Packit Service 779887
    (at your option) any later version.
Packit Service 779887
Packit Service 779887
    This program is distributed in the hope that it will be useful,
Packit Service 779887
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 779887
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 779887
    GNU General Public License for more details.
Packit Service 779887
Packit Service 779887
    You should have received a copy of the GNU General Public License along
Packit Service 779887
    with this program; if not, write to the Free Software Foundation, Inc.,
Packit Service 779887
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Packit Service 779887
*/
Packit Service 779887
#ifndef LIBREPORT_DUMP_DIR_H_
Packit Service 779887
#define LIBREPORT_DUMP_DIR_H_
Packit Service 779887
Packit Service 779887
/* For const_string_vector_const_ptr_t */
Packit Service 779887
#include "libreport_types.h"
Packit Service 779887
Packit Service 779887
#include <stdint.h>
Packit Service 779887
#include <stdio.h>
Packit Service 779887
Packit Service 779887
/* For DIR */
Packit Service 779887
#include <sys/types.h>
Packit Service 779887
#include <dirent.h>
Packit Service 779887
Packit Service 779887
/* For 'struct stat' */
Packit Service 779887
#include <sys/stat.h>
Packit Service 779887
Packit Service 779887
/* Fore GList */
Packit Service 779887
#include <glib.h>
Packit Service 779887
Packit Service 779887
#ifdef __cplusplus
Packit Service 779887
extern "C" {
Packit Service 779887
#endif
Packit Service 779887
Packit Service 779887
/* Utility function */
Packit Service 779887
int create_symlink_lockfile(const char *filename, const char *pid_str);
Packit Service 779887
int create_symlink_lockfile_at(int dir_fd, const char *filename, const char *pid_str);
Packit Service 779887
Packit Service 779887
/* Opens filename for reading relatively to a directory represented by dir_fd.
Packit Service 779887
 * The function fails if the file is symbolic link, directory or hard link.
Packit Service 779887
 */
Packit Service 779887
int secure_openat_read(int dir_fd, const char *filename);
Packit Service 779887
Packit Service 779887
/******************************************************************************/
Packit Service 779887
/* Global variables                                                           */
Packit Service 779887
/******************************************************************************/
Packit Service 779887
Packit Service 779887
/* UID of super-user (default 0)
Packit Service 779887
 *
Packit Service 779887
 * This variable is used by the dd* functions when they access security
Packit Service 779887
 * sensitive elements. The functions will ONLY TRUST the contents of those
Packit Service 779887
 * elements that ARE OWNED by super-user.
Packit Service 779887
 */
Packit Service 779887
extern uid_t dd_g_super_user_uid;
Packit Service 779887
Packit Service 779887
/* GID of a dump diretory created via dd_create() with uid != -1
Packit Service 779887
 *
Packit Service 779887
 * The default value is -1 which means that the dd* functions must ignore this
Packit Service 779887
 * variable.
Packit Service 779887
 *
Packit Service 779887
 * Initialize this variable only if you don't want to use the default group
Packit Service 779887
 * ('abrt').
Packit Service 779887
 */
Packit Service 779887
extern gid_t dd_g_fs_group_gid;
Packit Service 779887
Packit Service 779887
/******************************************************************************/
Packit Service 779887
/* Dump Directory                                                             */
Packit Service 779887
/******************************************************************************/
Packit Service 779887
Packit Service 779887
enum dump_dir_flags {
Packit Service 779887
    DD_FAIL_QUIETLY_ENOENT = (1 << 0),
Packit Service 779887
    DD_FAIL_QUIETLY_EACCES = (1 << 1),
Packit Service 779887
    /* Open symlinks. dd_* funcs don't open symlinks by default */
Packit Service 779887
    DD_OPEN_FOLLOW = (1 << 2),
Packit Service 779887
    DD_OPEN_READONLY = (1 << 3),
Packit Service 779887
    DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE = (1 << 4),
Packit Service 779887
    DD_DONT_WAIT_FOR_LOCK = (1 << 5),
Packit Service 779887
    /* Create the new dump directory with parent directories (mkdir -p)*/
Packit Service 779887
    DD_CREATE_PARENTS = (1 << 6),
Packit Service 779887
    /* Initializes internal data, opens file descriptors and returns the
Packit Service 779887
     * structure. This flag is useful for testing whether a directory
Packit Service 779887
     * exists and to perform stat operations.
Packit Service 779887
     */
Packit Service 779887
    DD_OPEN_FD_ONLY = (1 << 7),
Packit Service 779887
};
Packit Service 779887
Packit Service 779887
struct dump_dir {
Packit Service 779887
    char *dd_dirname;
Packit Service 779887
    DIR *next_dir;
Packit Service 779887
    int locked;
Packit Service 779887
    uid_t dd_uid;
Packit Service 779887
    gid_t dd_gid;
Packit Service 779887
    /* mode of saved files */
Packit Service 779887
    mode_t mode;
Packit Service 779887
    time_t dd_time;
Packit Service 779887
    char *dd_type;
Packit Service 779887
Packit Service 779887
    /* In case of recursive locking the first caller owns the lock and is
Packit Service 779887
     * responsible for unlocking. The consecutive dd_lock() callers acquire the
Packit Service 779887
     * lock but are not able to unlock the dump directory.
Packit Service 779887
     */
Packit Service 779887
    int owns_lock;
Packit Service 779887
    int dd_fd;
Packit Service 779887
    /* Never use this member directly, it is intialized on demand in
Packit Service 779887
     * dd_get_meta_data_dir_fd()
Packit Service 779887
     */
Packit Service 779887
    int dd_md_fd;
Packit Service 779887
};
Packit Service 779887
Packit Service 779887
void dd_close(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Opens the given path
Packit Service 779887
 */
Packit Service 779887
struct dump_dir *dd_opendir(const char *dir, int flags);
Packit Service 779887
Packit Service 779887
/* Re-opens a dump_dir opened with DD_OPEN_FD_ONLY.
Packit Service 779887
 *
Packit Service 779887
 * The passed dump_dir must not be used any more and the return value must be
Packit Service 779887
 * used instead.
Packit Service 779887
 *
Packit Service 779887
 * The passed flags must not contain DD_OPEN_FD_ONLY.
Packit Service 779887
 *
Packit Service 779887
 * The passed dump_dir must not be already locked.
Packit Service 779887
 */
Packit Service 779887
struct dump_dir *dd_fdopendir(struct dump_dir *dd, int flags);
Packit Service 779887
Packit Service 779887
/* Creates a new directory with internal files
Packit Service 779887
 *
Packit Service 779887
 * The functions creates a new directory which remains owned by the user of the
Packit Service 779887
 * process until dd_reset_ownership() is called.
Packit Service 779887
 *
Packit Service 779887
 * The function logs error messages in case of errors.
Packit Service 779887
 *
Packit Service 779887
 * @param dir Full file system path of the new directory
Packit Service 779887
 * @param uid Desired file system owner of the new directory or -1 if the owner
Packit Service 779887
 * should stay untouched even after calling dd_reset_ownership().
Packit Service 779887
 * @param mode File system mode of the new directory.
Packit Service 779887
 * @param flags See 'enum dump_dir_flags'
Packit Service 779887
 * @return Initialized struct dump_dir of NULL
Packit Service 779887
 */
Packit Service 779887
struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode, int flags);
Packit Service 779887
Packit Service 779887
int dd_reset_ownership(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Pass uid = (uid_t)-1L to disable chown'ing of newly created files
Packit Service 779887
 * (IOW: if you aren't running under root):
Packit Service 779887
 */
Packit Service 779887
struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode);
Packit Service 779887
Packit Service 779887
/* Creates the basic files except 'type' and sets the dump dir owner to passed
Packit Service 779887
 * 'uid'.
Packit Service 779887
 *
Packit Service 779887
 * The file 'type' is required and must be added with dd_save_text().
Packit Service 779887
 *
Packit Service 779887
 * If you want to have owner different than the problem 'uid', than pass -1 and
Packit Service 779887
 * add the file 'uid' with dd_save_text()
Packit Service 779887
 *
Packit Service 779887
 * List of created files:
Packit Service 779887
 *   - time
Packit Service 779887
 *   - last_occurrence
Packit Service 779887
 *   - uid
Packit Service 779887
 *   - kernel
Packit Service 779887
 *   - architecture
Packit Service 779887
 *   - hostname
Packit Service 779887
 *   - os_info
Packit Service 779887
 *   - os_release
Packit Service 779887
 *
Packit Service 779887
 * If any of these files has a counterpart in a chroot directory (os_info,
Packit Service 779887
 * os_relase), creates an element with the prefix "root_"
Packit Service 779887
 */
Packit Service 779887
void dd_create_basic_files(struct dump_dir *dd, uid_t uid, const char *chroot_dir);
Packit Service 779887
int dd_exist(const struct dump_dir *dd, const char *path);
Packit Service 779887
void dd_sanitize_mode_and_owner(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Initializes an iterator going through all dump directory items.
Packit Service 779887
 *
Packit Service 779887
 * @returns NULL if the iterator cannot be initialized; otherwise returns
Packit Service 779887
 * the result of opendir(). Do not use the return value after the iteration is
Packit Service 779887
 * finished or after calling dd_clear_next_file().
Packit Service 779887
 */
Packit Service 779887
DIR *dd_init_next_file(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Iterates over all dump directory item names
Packit Service 779887
 *
Packit Service 779887
 * Initialize the iterator by calling dd_init_next_file(). When iteration is
Packit Service 779887
 * finished, calls dd_clear_next_file().
Packit Service 779887
 *
Packit Service 779887
 * @returns 1 if the next item was read; otherwise return 0.
Packit Service 779887
 */
Packit Service 779887
int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name);
Packit Service 779887
Packit Service 779887
/* Destroys the next file iterator and cleans dump directory internal structures
Packit Service 779887
 *
Packit Service 779887
 * Calling dd_get_next_file() after this function returns will return 0. This
Packit Service 779887
 * function also invalidates the return value of dd_init_next_file().
Packit Service 779887
 */
Packit Service 779887
void dd_clear_next_file(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
char *load_text_file(const char *path, unsigned flags);
Packit Service 779887
Packit Service 779887
char* dd_load_text_ext(const struct dump_dir *dd, const char *name, unsigned flags);
Packit Service 779887
char* dd_load_text(const struct dump_dir *dd, const char *name);
Packit Service 779887
int dd_load_int32(const struct dump_dir *dd, const char *name, int32_t *value);
Packit Service 779887
int dd_load_uint32(const struct dump_dir *dd, const char *name, uint32_t *value);
Packit Service 779887
int dd_load_int64(const struct dump_dir *dd, const char *name, int64_t *value);
Packit Service 779887
int dd_load_uint64(const struct dump_dir *dd, const char *name, uint64_t *value);
Packit Service 779887
Packit Service 779887
/* Returns value of environment variable with given name.
Packit Service 779887
 *
Packit Service 779887
 * @param dd Dump directory
Packit Service 779887
 * @param name Variables's name
Packit Service 779887
 * @param value Return value.
Packit Service 779887
 * @return 0 no success, or negative value if an error occurred (-ENOENT if the
Packit Service 779887
 * given dd does not support environment variables).
Packit Service 779887
 */
Packit Service 779887
int dd_get_env_variable(struct dump_dir *dd, const char *name, char **value);
Packit Service 779887
Packit Service 779887
void dd_save_text(struct dump_dir *dd, const char *name, const char *data);
Packit Service 779887
void dd_save_binary(struct dump_dir *dd, const char *name, const char *data, unsigned size);
Packit Service 779887
int dd_copy_file(struct dump_dir *dd, const char *name, const char *source_path);
Packit Service 779887
int dd_copy_file_unpack(struct dump_dir *dd, const char *name, const char *source_path);
Packit Service 779887
Packit Service 779887
/* Create an item of the given name with contents of the given file (see man openat)
Packit Service 779887
 *
Packit Service 779887
 * @param dd Dump directory
Packit Service 779887
 * @param name Item's name
Packit Service 779887
 * @param src_dir_fd Source directory's file descriptor
Packit Service 779887
 * @param src_name Source file name
Packit Service 779887
 * @return 0 no success, or negative value if an error occurred
Packit Service 779887
 */
Packit Service 779887
int dd_copy_file_at(struct dump_dir *dd, const char *name, int src_dir_fd, const char *src_name);
Packit Service 779887
Packit Service 779887
/* Creates/overwrites an element with data read from a file descriptor
Packit Service 779887
 *
Packit Service 779887
 * @param dd Dump directory
Packit Service 779887
 * @param name The name of the element
Packit Service 779887
 * @param fd The file descriptor
Packit Service 779887
 * @param flags libreport_copyfd_flags
Packit Service 779887
 * @param maxsize Limit for number of written Bytes. (0 for unlimited).
Packit Service 779887
 * @return Number of read Bytes. If the return value is greater than the maxsize
Packit Service 779887
 * the file descriptor content was truncated to the maxsize. The return value
Packit Service 779887
 * is not size of the file descriptor.
Packit Service 779887
 */
Packit Service 779887
off_t dd_copy_fd(struct dump_dir *dd, const char *name, int fd, int copy_flags, off_t maxsize);
Packit Service 779887
Packit Service 779887
/* Stats dump dir elements
Packit Service 779887
 *
Packit Service 779887
 * @param dd Dump Directory
Packit Service 779887
 * @param name The name of the element
Packit Service 779887
 * @param statbuf See 'man 2 stat'
Packit Service 779887
 * @return -EINVAL if name is invalid element name, -EMEDIUMTYPE if name is not
Packit Service 779887
 *  regular file, -errno on errors and 0 on success.
Packit Service 779887
 */
Packit Service 779887
int dd_item_stat(struct dump_dir *dd, const char *name, struct stat *statbuf);
Packit Service 779887
Packit Service 779887
/* Returns value less than 0 if any error occured; otherwise returns size of an
Packit Service 779887
 * item in Bytes. If an item does not exist returns 0 instead of an error
Packit Service 779887
 * value.
Packit Service 779887
 */
Packit Service 779887
long dd_get_item_size(struct dump_dir *dd, const char *name);
Packit Service 779887
Packit Service 779887
/* Returns the number of items in the dump directory (does not count meta-data).
Packit Service 779887
 *
Packit Service 779887
 * @return Negative number on errors (-errno). Otherwise number of dump
Packit Service 779887
 * directory items.
Packit Service 779887
 */
Packit Service 779887
int dd_get_items_count(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Deletes an item from dump directory
Packit Service 779887
 * On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
Packit Service 779887
 * For more about errno see unlink documentation
Packit Service 779887
 */
Packit Service 779887
int dd_delete_item(struct dump_dir *dd, const char *name);
Packit Service 779887
Packit Service 779887
/* Returns a file descriptor for the given name. The function is limited to open
Packit Service 779887
 * an element read only, write only or create new.
Packit Service 779887
 *
Packit Service 779887
 * O_RDONLY - opens an existing item for reading
Packit Service 779887
 * O_RDWR - removes an item, creates its file and opens the file for reading and writing
Packit Service 779887
 *
Packit Service 779887
 * @param dd Dump directory
Packit Service 779887
 * @param name The name of the item
Packit Service 779887
 * @param flags One of these : O_RDONLY, O_RDWR
Packit Service 779887
 * @return Negative number on error
Packit Service 779887
 */
Packit Service 779887
int dd_open_item(struct dump_dir *dd, const char *name, int flags);
Packit Service 779887
Packit Service 779887
/* Returns a FILE for the given name. The function is limited to open
Packit Service 779887
 * an element read only, write only or create new.
Packit Service 779887
 *
Packit Service 779887
 * O_RDONLY - opens an existing file for reading
Packit Service 779887
 * O_RDWR - removes an item, creates its file and opens the file for reading and writing
Packit Service 779887
 *
Packit Service 779887
 * @param dd Dump directory
Packit Service 779887
 * @param name The name of the item
Packit Service 779887
 * @param flags One of these : O_RDONLY, O_RDWR
Packit Service 779887
 * @return NULL on error
Packit Service 779887
 */
Packit Service 779887
FILE *dd_open_item_file(struct dump_dir *dd, const char *name, int flags);
Packit Service 779887
Packit Service 779887
/* Returns 0 if directory is deleted or not found */
Packit Service 779887
int dd_delete(struct dump_dir *dd);
Packit Service 779887
int dd_rename(struct dump_dir *dd, const char *new_path);
Packit Service 779887
/* Changes owner of dump dir
Packit Service 779887
 * Uses two different strategies selected at build time by
Packit Service 779887
 * DUMP_DIR_OWNED_BY_USER configuration:
Packit Service 779887
 *  <= 0 : owner = abrt user's uid,  group = new_uid's gid
Packit Service 779887
 *   > 0 : owner = new_uid,          group = abrt group's gid
Packit Service 779887
 *
Packit Service 779887
 * On success, zero is returned. On error, -1 is returned.
Packit Service 779887
 */
Packit Service 779887
int dd_chown(struct dump_dir *dd, uid_t new_uid);
Packit Service 779887
Packit Service 779887
/* Returns the number of Bytes consumed by the dump directory.
Packit Service 779887
 *
Packit Service 779887
 * @param flags For the future needs (count also meta-data, ...).
Packit Service 779887
 * @return Negative number on errors (-errno). Otherwise size in Bytes.
Packit Service 779887
 */
Packit Service 779887
off_t dd_compute_size(struct dump_dir *dd, int flags);
Packit Service 779887
Packit Service 779887
/* Sets a new owner (does NOT chown the directory)
Packit Service 779887
 *
Packit Service 779887
 * Does not validate the passed uid.
Packit Service 779887
 * The given dump_dir must be opened for writing.
Packit Service 779887
 */
Packit Service 779887
int dd_set_owner(struct dump_dir *dd, uid_t owner);
Packit Service 779887
Packit Service 779887
/* Makes the dump directory owned by nobody.
Packit Service 779887
 *
Packit Service 779887
 * The directory will be accessible for all users.
Packit Service 779887
 * The given dump_dir must be opened for writing.
Packit Service 779887
 */
Packit Service 779887
int dd_set_no_owner(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Gets the owner
Packit Service 779887
 *
Packit Service 779887
 * If meta-data misses owner, returns fs owner.
Packit Service 779887
 * Can be used with DD_OPEN_FD_ONLY.
Packit Service 779887
 */
Packit Service 779887
uid_t dd_get_owner(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Returns UNIX time stamp of the first occurrence of the problem.
Packit Service 779887
 *
Packit Service 779887
 * @param dd Examined dump directory
Packit Service 779887
 * @returns On success, the value of time of the first occurrence in seconds
Packit Service 779887
 * since the Epoch is returned. On error, ((time_t) -1) is returned, and errno
Packit Service 779887
 * is set appropriately (ENODATA).
Packit Service 779887
 */
Packit Service 779887
time_t dd_get_first_occurrence(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* Returns UNIX time stamp of the last occurrence of the problem.
Packit Service 779887
 *
Packit Service 779887
 * @param dd Examined dump directory
Packit Service 779887
 * @returns The returned value is never lower than the value returned by
Packit Service 779887
 * dd_get_first_occurrence(). On success, the value of time of the first
Packit Service 779887
 * occurrence in seconds since the Epoch is returned.On error, ((time_t) -1) is
Packit Service 779887
 * returned, and errno is set appropriately (ENODATA).
Packit Service 779887
 */
Packit Service 779887
time_t dd_get_last_occurrence(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
/* reported_to handling */
Packit Service 779887
struct report_result {
Packit Service 779887
    char *label;
Packit Service 779887
    char *url;
Packit Service 779887
    char *msg;
Packit Service 779887
    char *bthash;
Packit Service 779887
    time_t timestamp;
Packit Service 779887
    /* ^^^ if you add more fields, don't forget to update free_report_result() */
Packit Service 779887
};
Packit Service 779887
typedef struct report_result report_result_t;
Packit Service 779887
Packit Service 779887
/* Appends a new unique line to the list of report results
Packit Service 779887
 *
Packit Service 779887
 * If the reported_to data already contains the given line, the line will not
Packit Service 779887
 * be added again.
Packit Service 779887
 *
Packit Service 779887
 * @param reported_to The data
Packit Service 779887
 * @param line The appended line
Packit Service 779887
 * @return 1 if the line was added at the end of the reported_to; otherwise 0.
Packit Service 779887
 */
Packit Service 779887
#define add_reported_to_data libreport_add_reported_to_data
Packit Service 779887
int add_reported_to_data(char **reported_to, const char *line);
Packit Service 779887
Packit Service 779887
/* Appends a new unique entry to the list of report results
Packit Service 779887
 *
Packit Service 779887
 * result->label must be non-empty string which does not contain ':' character.
Packit Service 779887
 *
Packit Service 779887
 * The function converts the result to a valid reported_to line and calls
Packit Service 779887
 * add_reported_to_data().
Packit Service 779887
 *
Packit Service 779887
 * @param reported_to The data
Packit Service 779887
 * @param result The appended entry
Packit Service 779887
 * @return -EINVAL if result->label is invalid; otherwise return value of
Packit Service 779887
 * add_reported_to_data
Packit Service 779887
 */
Packit Service 779887
#define add_reported_to_entry_data libreport_add_reported_to_entry_data
Packit Service 779887
int add_reported_to_entry_data(char **reported_to, struct report_result *result);
Packit Service 779887
Packit Service 779887
/* This is a wrapper of add_reported_to_data which accepts 'struct dump_dir *'
Packit Service 779887
 * in the first argument instead of 'char **'. The added line is stored in
Packit Service 779887
 * 'reported_to' dump directory file.
Packit Service 779887
 */
Packit Service 779887
#define add_reported_to libreport_add_reported_to
Packit Service 779887
void add_reported_to(struct dump_dir *dd, const char *line);
Packit Service 779887
Packit Service 779887
/* This is a wrapper of add_reported_to_entry_data which accepts 'struct
Packit Service 779887
 * dump_dir *' in the first argument instead of 'char **'. The added entry is
Packit Service 779887
 * stored in 'reported_to' dump directory file.
Packit Service 779887
 */
Packit Service 779887
#define add_reported_to_entry libreport_add_reported_to_entry
Packit Service 779887
void add_reported_to_entry(struct dump_dir *dd, struct report_result *result);
Packit Service 779887
Packit Service 779887
#define free_report_result libreport_free_report_result
Packit Service 779887
void free_report_result(struct report_result *result);
Packit Service 779887
#define find_in_reported_to_data libreport_find_in_reported_to_data
Packit Service 779887
report_result_t *find_in_reported_to_data(const char *reported_to, const char *report_label);
Packit Service 779887
#define find_in_reported_to libreport_find_in_reported_to
Packit Service 779887
report_result_t *find_in_reported_to(struct dump_dir *dd, const char *report_label);
Packit Service 779887
#define read_entire_reported_to_data libreport_read_entire_reported_to_data
Packit Service 779887
GList *read_entire_reported_to_data(const char* reported_to);
Packit Service 779887
#define read_entire_reported_to libreport_read_entire_reported_to
Packit Service 779887
GList *read_entire_reported_to(struct dump_dir *dd);
Packit Service 779887
Packit Service 779887
Packit Service 779887
void delete_dump_dir(const char *dirname);
Packit Service 779887
/* Checks dump dir accessibility for particular uid.
Packit Service 779887
 *
Packit Service 779887
 * If the directory doesn't exist the directory is not accessible and errno is
Packit Service 779887
 * set to ENOTDIR.
Packit Service 779887
 *
Packit Service 779887
 * Returns non zero if dump dir is accessible otherwise return 0 value.
Packit Service 779887
 */
Packit Service 779887
int dump_dir_accessible_by_uid(const char *dirname, uid_t uid);
Packit Service 779887
/* Returns the same information as dump_dir_accessible_by_uid
Packit Service 779887
 *
Packit Service 779887
 * The passed dump_dir can be opened with DD_OPEN_FD_ONLY
Packit Service 779887
 */
Packit Service 779887
int dd_accessible_by_uid(struct dump_dir *dd, uid_t uid);
Packit Service 779887
Packit Service 779887
enum {
Packit Service 779887
    DD_STAT_ACCESSIBLE_BY_UID = 1,
Packit Service 779887
    DD_STAT_OWNED_BY_UID = DD_STAT_ACCESSIBLE_BY_UID << 1,
Packit Service 779887
    DD_STAT_NO_OWNER = DD_STAT_OWNED_BY_UID << 1,
Packit Service 779887
};
Packit Service 779887
Packit Service 779887
/* Gets information about a dump directory for particular uid.
Packit Service 779887
 *
Packit Service 779887
 * If the directory doesn't exist the directory is not accessible and errno is
Packit Service 779887
 * set to ENOTDIR.
Packit Service 779887
 *
Packit Service 779887
 * Returns negative number if error occurred otherwise returns 0 or positive number.
Packit Service 779887
 */
Packit Service 779887
int dump_dir_stat_for_uid(const char *dirname, uid_t uid);
Packit Service 779887
/* Returns the same information as dump_dir_stat_for_uid
Packit Service 779887
 *
Packit Service 779887
 * The passed dump_dir can be opened with DD_OPEN_FD_ONLY
Packit Service 779887
 */
Packit Service 779887
int dd_stat_for_uid(struct dump_dir *dd, uid_t uid);
Packit Service 779887
Packit Service 779887
/* creates not_reportable file in the problem directory and saves the
Packit Service 779887
   reason to it, which prevents libreport from reporting the problem
Packit Service 779887
   On success, zero is returned.
Packit Service 779887
   On error, -1 is returned and an error message is logged.
Packit Service 779887
     - this could probably happen only if the dump dir is not locked
Packit Service 779887
*/
Packit Service 779887
int dd_mark_as_notreportable(struct dump_dir *dd, const char *reason);
Packit Service 779887
Packit Service 779887
typedef int (*save_data_call_back)(struct dump_dir *, void *args);
Packit Service 779887
Packit Service 779887
/* Saves data in a new dump directory
Packit Service 779887
 *
Packit Service 779887
 * Creates a new dump directory in "problem dump location", adds the basic
Packit Service 779887
 * information to the new directory, calls given callback to allow callees to
Packit Service 779887
 * customize the dump dir contents (save problem data) and commits the dump
Packit Service 779887
 * directory (makes the directory visible for a problem daemon).
Packit Service 779887
 */
Packit Service 779887
struct dump_dir *create_dump_dir(const char *base_dir_name, const char *type,
Packit Service 779887
        uid_t uid, save_data_call_back save_data, void *args);
Packit Service 779887
Packit Service 779887
struct dump_dir *create_dump_dir_ext(const char *base_dir_name, const char *type,
Packit Service 779887
        pid_t pid, uid_t uid, save_data_call_back save_data, void *args);
Packit Service 779887
Packit Service 779887
/* Creates a new archive from the dump directory contents
Packit Service 779887
 *
Packit Service 779887
 * The dd argument must be opened for reading.
Packit Service 779887
 *
Packit Service 779887
 * The archive_name must not exist. The file will be created with 0600 mode.
Packit Service 779887
 *
Packit Service 779887
 * The archive type is deduced from archive_name suffix. The supported archive
Packit Service 779887
 * suffixes are the following:
Packit Service 779887
 *   - '.tag.gz' (note: the implementation uses child gzip process)
Packit Service 779887
 *
Packit Service 779887
 * The archive will include only the files that are not in the exclude_elements
Packit Service 779887
 * list. See get_global_always_excluded_elements().
Packit Service 779887
 *
Packit Service 779887
 * The argument "flags" is currently unused.
Packit Service 779887
 *
Packit Service 779887
 * @return 0 on success; otherwise non-0 value. -ENOSYS if archive type is not
Packit Service 779887
 * supported. -EEXIST if the archive file already exists. -ECHILD if child
Packit Service 779887
 * process fails. Other negative values can be converted to errno values by
Packit Service 779887
 * turning them positive.
Packit Service 779887
 */
Packit Service 779887
int dd_create_archive(struct dump_dir *dd, const char *archive_name,
Packit Service 779887
        const_string_vector_const_ptr_t exclude_elements, int flags);
Packit Service 779887
Packit Service 779887
#ifdef __cplusplus
Packit Service 779887
}
Packit Service 779887
#endif
Packit Service 779887
Packit Service 779887
#endif