[PATCH] reporter-rhts: when parsing os_release, don't strip "Alpha"/"Beta" from version
by Denys Vlasenko
Should fix rhbz#896090 while NOT breaking rhbz#730887
--
vda
diff -x '*.po' -d -urpN libreport.0/src/lib/parse_release.c libreport.1/src/lib/parse_release.c
--- libreport.0/src/lib/parse_release.c 2013-01-10 14:18:05.000000000 +0100
+++ libreport.1/src/lib/parse_release.c 2013-01-23 16:32:46.558850018 +0100
@@ -18,8 +18,34 @@
*/
#include "internal_libreport.h"
+/* Houston, we have a problem.
+ *
+ * Mapping from OS release string to (product,version) string tuple
+ * in different bug databases is non-trivial, and differs from DB to DB.
+ * OTOH, it does have a lot of similarities too, making it worthwhile
+ * to use a common function for parsing.
+ *
+ * To accomodate this, parse_release() takes a flag parameter
+ * with two types of bits:
+ *
+ * - some bits indicate a specific tweak to parsing algorithm (such as
+ * "remove everything after numeric version").
+ *
+ * - if there is a bug DB which requires a quirk not easily describable
+ * by a combination of aforementioned bits, it gets its own bit
+ * "parse OS release for bug database XYZ" (so far we have none).
+ *
+ * In order to not torture API users with the need to know these bits,
+ * we have convenience functions parse_release_for_XYZ()
+ * which call parse_release() with correct bits.
+ */
+enum {
+ APPEND_MAJOR_VER_TO_RHEL_PRODUCT = 1 << 0,
+ RETAIN_ALPHA_BETA_TAIL_IN_VER = 1 << 1,
+};
+
// caller is reposible for freeing *product* and *version*
-static void parse_release(const char *release, char** product, char** version, bool append_rhel_version)
+static void parse_release(const char *release, char** product, char** version, int flags)
{
if (strstr(release, "Rawhide"))
{
@@ -29,21 +55,29 @@ static void parse_release(const char *re
return;
}
+ bool it_is_rhel = false;
+
struct strbuf *buf_product = strbuf_new();
if (strstr(release, "Fedora"))
+ {
strbuf_append_str(buf_product, "Fedora");
+ }
else if (strstr(release, "Red Hat Enterprise Linux"))
+ {
strbuf_append_str(buf_product, "Red Hat Enterprise Linux");
+ it_is_rhel = true;
+ }
else
{
/* TODO: add logic for parsing other distros' names here */
strbuf_append_str(buf_product, release);
}
- /* examples of release strings:
- * installed system: Red Hat Enterprise Linux Server release 6.2 Beta (Santiago)
- * anaconda: Red Hat Enterprise Linux 6.2
+ /* Examples of release strings:
+ * installed system: "Red Hat Enterprise Linux Server release 6.2 Beta (Santiago)"
+ * anaconda: "Red Hat Enterprise Linux 6.2"
*/
+ struct strbuf *buf_version = strbuf_new();
const char *r = strstr(release, "release");
const char *space = r ? strchr(r, ' ') : NULL;
if (!space)
@@ -57,25 +91,48 @@ static void parse_release(const char *re
space++;
}
}
-
- struct strbuf *buf_version = strbuf_new();
if (space)
{
space++;
/* observed also: "Fedora F16-Alpha" rhbz#730887 */
- while (isdigit(*space) || *space == '.')
+ while ((*space >= '0' && *space <= '9') || *space == '.')
{
/* Eat string like "5.2" */
strbuf_append_char(buf_version, *space);
- if (append_rhel_version
- && strcmp(buf_product->buf, "Red Hat Enterprise Linux") == 0
- ) {
- strbuf_append_char(buf_product, ' ');
- strbuf_append_char(buf_product, *space);
- }
- append_rhel_version = false;
space++;
}
+
+ if (flags & RETAIN_ALPHA_BETA_TAIL_IN_VER)
+ {
+ /* Example: "... 6.2 [Beta ](Santiago)".
+ * 'space' variable points to non-digit char after "2".
+ * We assume that non-parenthesized text is "Alpha"/"Beta"/etc.
+ * If this text is only whitespace, we won't append it.
+ */
+ const char *to_append = space;
+ while (*space && *space != '(') /* go to '(' */
+ space++;
+ while (space > to_append && space[-1] == ' ') /* back to 1st non-space */
+ space--;
+ strbuf_append_strf(buf_version, "%.*s", (int)(space - to_append), to_append);
+ }
+ }
+
+ if ((flags & APPEND_MAJOR_VER_TO_RHEL_PRODUCT) && it_is_rhel)
+ {
+ char *v = buf_version->buf;
+
+ /* Append "integer part" of version to product:
+ * "10.2<anything>" -> append " 10"
+ * "10 <anything>" -> append " 10"
+ * "10" -> append " 10"
+ * "10abcde" -> append ?????
+ */
+ unsigned idx_dot = strchrnul(v, '.') - v;
+ unsigned idx_space = strchrnul(v, ' ') - v;
+ strbuf_append_strf(buf_product, " %.*s",
+ (idx_dot < idx_space ? idx_dot : idx_space), v
+ );
}
*version = strbuf_free_nobuf(buf_version);
@@ -86,12 +143,43 @@ static void parse_release(const char *re
void parse_release_for_bz(const char *release, char** product, char** version)
{
- /* Fedora/RH bugzilla uses "Red Hat Enterprise Linux N" product RHEL */
- parse_release(release, product, version, /*append_rhel_version:*/ true);
+ /* Fedora/RH bugzilla uses "Red Hat Enterprise Linux N" product for RHEL */
+ parse_release(release, product, version, 0
+ | APPEND_MAJOR_VER_TO_RHEL_PRODUCT
+ );
}
+/*
+ * Note to developers: you can use
+ * curl --silent -u $USER:$PASS "https://api.access.redhat.com/rs/products/Red%20Hat%20Enterprise%20Linux/..." | xmllint --format -
+ * to query RHTS for valid set of versions. Currently (2013-01) I get:
+ * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+ * <versions xmlns="http://www.redhat.com/gss/strata">
+ * <version>3 - ELS</version>
+ * <version>4</version>
+ * <version>4 - ELS</version>
+ * <version>5.0</version>
+ * <version>5.1</version>
+ * <version>5.2</version>
+ * <version>5.3</version>
+ * <version>5.4</version>
+ * <version>5.5</version>
+ * <version>5.6</version>
+ * <version>5.7</version>
+ * <version>5.8</version>
+ * <version>5.9</version>
+ * <version>6.0</version>
+ * <version>6.1</version>
+ * <version>6.2</version>
+ * <version>6.3</version>
+ * <version>6.4 Beta</version>
+ * <version>7.0 Alpha-2</version>
+ * <version>Unknown</version>
+ * </versions>
+ */
void parse_release_for_rhts(const char *release, char** product, char** version)
{
- /* RHTS uses "Red Hat Enterprise Linux" product for RHEL */
- parse_release(release, product, version, /*append_rhel_version:*/ false);
+ parse_release(release, product, version, 0
+ | RETAIN_ALPHA_BETA_TAIL_IN_VER
+ );
}
diff -x '*.po' -d -urpN libreport.0/tests/osrelease.at libreport.1/tests/osrelease.at
--- libreport.0/tests/osrelease.at 2013-01-10 14:18:05.000000000 +0100
+++ libreport.1/tests/osrelease.at 2013-01-23 16:52:05.136844531 +0100
@@ -113,7 +113,8 @@ int main(void)
{
char *releases_good[7][3] =
{
- {"Red Hat Enterprise Linux Server release 6.2 Beta (Santiago)", "Red Hat Enterprise Linux", "6.2"},
+ {"Red Hat Enterprise Linux Server release 6.2 Beta (Santiago)", "Red Hat Enterprise Linux", "6.2 Beta"},
+ {"Red Hat Enterprise Linux Server release 6.2 (Santiago)", "Red Hat Enterprise Linux", "6.2"},
{"Red Hat Enterprise Linux 6.2", "Red Hat Enterprise Linux", "6.2"},
};
11 years, 3 months
[ABRT PATCH] applet: on requrest open gnome-abrt instead of abrt-gui
by Jakub Filak
- realted to hrbz#877328
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
abrt.spec.in | 9 ++-------
po/POTFILES.in | 1 -
src/applet/applet.c | 12 +++++++-----
src/gui-gtk/Makefile.am | 7 -------
src/gui-gtk/abrt.desktop.in | 10 ----------
5 files changed, 9 insertions(+), 30 deletions(-)
delete mode 100644 src/gui-gtk/abrt.desktop.in
diff --git a/abrt.spec.in b/abrt.spec.in
index a87308d..21645bb 100644
--- a/abrt.spec.in
+++ b/abrt.spec.in
@@ -84,6 +84,7 @@ Summary: %{name}'s gui
Group: User Interface/Desktops
Requires: %{name} = %{version}-%{release}
Requires: %{name}-dbus = %{version}-%{release}
+Requires: gnome-abrt
BuildRequires: libreport-gtk-devel
# we used to have abrt-applet, now abrt-gui includes it:
Provides: abrt-applet = %{version}-%{release}
@@ -210,6 +211,7 @@ Requires: abrt-addon-xorg
# Default config of addon-ccpp requires gdb
Requires: gdb >= 7.0-3
Requires: abrt-gui
+Requires: gnome-abrt
Requires: abrt-plugin-bodhi
Requires: libreport-plugin-logger, libreport-plugin-bugzilla
Requires: libreport-plugin-ureport
@@ -266,12 +268,6 @@ mkdir -p $RPM_BUILD_ROOT/var/spool/abrt
mkdir -p $RPM_BUILD_ROOT/var/spool/abrt-upload
desktop-file-install \
- --dir ${RPM_BUILD_ROOT}%{_datadir}/applications \
- --vendor %{desktopvendor} \
- --delete-original \
- ${RPM_BUILD_ROOT}%{_datadir}/applications/%{name}.desktop
-
-desktop-file-install \
--dir ${RPM_BUILD_ROOT}%{_sysconfdir}/xdg/autostart \
src/applet/abrt-applet.desktop
@@ -524,7 +520,6 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%{_bindir}/abrt-gui
%dir %{_datadir}/%{name}
# all glade, gtkbuilder and py files for gui
-%{_datadir}/applications/%{desktopvendor}-%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/*
%{_datadir}/icons/hicolor/*/status/*
%{_datadir}/%{name}/icons/hicolor/*/status/*
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d16d3e0..d0b22b6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,7 +8,6 @@ src/daemon/abrt-server.c
src/dbus/abrt-dbus.c
src/daemon/abrtd.c
src/daemon/abrt-handle-event.c
-src/gui-gtk/abrt.desktop.in
src/gui-gtk/main.c
src/lib/abrt_conf.c
src/lib/hooklib.c
diff --git a/src/applet/applet.c b/src/applet/applet.c
index e88f0a0..001fb4a 100644
--- a/src/applet/applet.c
+++ b/src/applet/applet.c
@@ -45,6 +45,8 @@
#define A_REPORT_REPORT "REPORT"
#define A_REPORT_AUTOREPORT "AUTOREPORT"
+#define GUI_EXECUTABLE "gnome-abrt"
+
enum
{
/*
@@ -448,12 +450,12 @@ static void fork_exec_gui(void)
}
/* grand child */
- //TODO: pass s_dirs[] as DIR param(s) to abrt-gui
- execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL);
- /* Did not find abrt-gui in installation directory. Oh well */
+ //TODO: pass s_dirs[] as DIR param(s) to 'gui executable'
+ execl(BIN_DIR"/"GUI_EXECUTABLE, GUI_EXECUTABLE, (char*) NULL);
+ /* Did not find 'gui executable' in installation directory. Oh well */
/* Trying to find it in PATH */
- execlp("abrt-gui", "abrt-gui", (char*) NULL);
- perror_msg_and_die(_("Can't execute '%s'"), "abrt-gui");
+ execlp(GUI_EXECUTABLE, GUI_EXECUTABLE, (char*) NULL);
+ perror_msg_and_die(_("Can't execute '%s'"), GUI_EXECUTABLE);
}
else
safe_waitpid(pid, /* status */ NULL, /* options */ 0);
diff --git a/src/gui-gtk/Makefile.am b/src/gui-gtk/Makefile.am
index 270ad1b..2274a41 100644
--- a/src/gui-gtk/Makefile.am
+++ b/src/gui-gtk/Makefile.am
@@ -36,10 +36,3 @@ abrt_gui_LDADD = \
# ../lib/libreport.la
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
-
-@INTLTOOL_DESKTOP_RULE@
-desktopdir = $(datadir)/applications
-desktop_in_files = abrt.desktop.in
-desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
-
-EXTRA_DIST = $(desktop_in_files)
diff --git a/src/gui-gtk/abrt.desktop.in b/src/gui-gtk/abrt.desktop.in
deleted file mode 100644
index 0605bb9..0000000
--- a/src/gui-gtk/abrt.desktop.in
+++ /dev/null
@@ -1,10 +0,0 @@
-[Desktop Entry]
-_Name=Automatic Bug Reporting Tool
-_Comment=View and report application crashes
-Exec=abrt-gui
-Icon=abrt
-Terminal=false
-Type=Application
-Categories=System;X-Red-Hat-Base;
-StartupNotify=true
-X-Desktop-File-Install-Version=0.15
--
1.7.11.7
11 years, 3 months
[LIBREPORT PATCH] spec: add requires section for pygobject3
by Jakub Filak
- http://abrt.fedoraproject.org/faf/reports/42535/
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
libreport.spec.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/libreport.spec.in b/libreport.spec.in
index 23bb659..f93099a 100644
--- a/libreport.spec.in
+++ b/libreport.spec.in
@@ -114,6 +114,7 @@ Requires: libreport = %{version}-%{release}
%if 0%{?rhel} >= 6
%else
Requires: recordmydesktop
+Requires: pygobject3
%endif
Provides: report-gtk = 0:0.23-1
Obsoletes: report-gtk < 0:0.23-1
--
1.7.11.7
11 years, 3 months
[ABRT PATCH 1/2] dbus: move dir accessibility check from abrt to libreport
by Jakub Filak
- related to trac#927
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/dbus/abrt-dbus.c | 64 ++++++----------------------------------------------
1 file changed, 7 insertions(+), 57 deletions(-)
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
index afda8d4..754ef97 100644
--- a/src/dbus/abrt-dbus.c
+++ b/src/dbus/abrt-dbus.c
@@ -128,55 +128,6 @@ static uid_t get_caller_uid(GDBusConnection *connection, GDBusMethodInvocation *
return caller_uid;
}
-static bool uid_in_group(uid_t uid, gid_t gid)
-{
- char **tmp;
- struct passwd *pwd = getpwuid(uid);
-
- if (!pwd)
- return FALSE;
-
- if (pwd->pw_gid == gid)
- return TRUE;
-
- struct group *grp = getgrgid(gid);
- if (!(grp && grp->gr_mem))
- return FALSE;
-
- for (tmp = grp->gr_mem; *tmp != NULL; tmp++)
- {
- if (g_strcmp0(*tmp, pwd->pw_name) == 0)
- {
- VERB3 log("user %s belongs to group: %s", pwd->pw_name, grp->gr_name);
- return TRUE;
- }
- }
-
- VERB2 log("user %s DOESN'T belong to group: %s", pwd->pw_name, grp->gr_name);
- return FALSE;
-}
-
-/*
- 0 - user doesn't have access
- 1 - user has access
-*/
-static int dir_accessible_by_uid(const char *dir_path, uid_t uid)
-{
- struct stat statbuf;
- if (stat(dir_path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))
- errno = ENOTDIR;
- else
- {
- if (uid == 0 || (statbuf.st_mode & S_IROTH) || uid_in_group(uid, statbuf.st_gid))
- {
- VERB1 log("caller has access to the requested directory %s", dir_path);
- return 1;
- }
- }
-
- return 0;
-}
-
/*
* Structure for simple conditions based on problem fields
*/
@@ -239,8 +190,7 @@ static GList* scan_directory(const char *path,
continue; /* skip "." and ".." */
char *full_name = concat_path_file(path, dent->d_name);
- struct stat statbuf;
- if (stat(full_name, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
+ if (dump_dir_accessible_by_uid(full_name, caller_uid))
{
/* Silently ignore *any* errors, not only EACCES.
* We saw "lock file is locked by process PID" error
@@ -253,15 +203,15 @@ static GList* scan_directory(const char *path,
/* or we could just setuid?
- but it would require locking, because we want to setuid back before we server another request..
*/
- if (dd && (caller_uid == 0 || statbuf.st_mode & S_IROTH || uid_in_group(caller_uid, statbuf.st_gid)))
+ if (dd)
{
if (problem_condition_evaluate_and(dd, condition))
{
list = g_list_prepend(list, full_name);
full_name = NULL;
}
+ dd_close(dd); //doesn't fail even if dd == NULL
}
- dd_close(dd); //doesn't fail even if dd == NULL
}
free(full_name);
}
@@ -449,7 +399,7 @@ static struct dump_dir *open_directory_for_modification_of_element(
}
}
- if (!dir_accessible_by_uid(problem_id, caller_uid))
+ if (!dump_dir_accessible_by_uid(problem_id, caller_uid))
{
if (errno == ENOTDIR)
return_InvalidProblemDir_error(invocation, problem_id);
@@ -555,7 +505,7 @@ static void handle_method_call(GDBusConnection *connection,
return;
}
- if (dir_accessible_by_uid(problem_dir, caller_uid)) //caller seems to be in group with access to this dir, so no action needed
+ if (dump_dir_accessible_by_uid(problem_dir, caller_uid)) //caller seems to be in group with access to this dir, so no action needed
{
VERB1 log("caller has access to the requested directory %s", problem_dir);
g_dbus_method_invocation_return_value(invocation, NULL);
@@ -612,7 +562,7 @@ static void handle_method_call(GDBusConnection *connection,
return;
}
- if (!dir_accessible_by_uid(problem_dir, caller_uid))
+ if (!dump_dir_accessible_by_uid(problem_dir, caller_uid))
{
if (errno == ENOENT)
{
@@ -777,7 +727,7 @@ static void handle_method_call(GDBusConnection *connection,
for (GList *l = problem_dirs; l; l = l->next)
{
const char *dir_name = (const char*)l->data;
- if (!dir_accessible_by_uid(dir_name, caller_uid))
+ if (!dump_dir_accessible_by_uid(dir_name, caller_uid))
{
if (errno == ENOENT)
{
--
1.7.11.7
11 years, 3 months
[LIBREPORT PATCH] dd: move dir accessibility check from abrt to libreport
by Jakub Filak
- related to trac#927
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/include/dump_dir.h | 4 ++++
src/lib/dump_dir.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
index 0a6a1b0..21169c8 100644
--- a/src/include/dump_dir.h
+++ b/src/include/dump_dir.h
@@ -114,6 +114,10 @@ report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix);
void delete_dump_dir(const char *dirname);
+/* Checks dump dir accessibility for particular uid
+ * Returns non zero if dump dir is accessible otherwise return 0 value.
+ */
+int dump_dir_accessible_by_uid(const char *dirname, uid_t uid);
#ifdef __cplusplus
}
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index e7e6e33..981f5e6 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -1152,3 +1152,54 @@ void delete_dump_dir(const char *dirname)
dd_delete(dd);
}
}
+
+#if DUMP_DIR_OWNED_BY_USER == 0
+static bool uid_in_group(uid_t uid, gid_t gid)
+{
+ char **tmp;
+ struct passwd *pwd = getpwuid(uid);
+
+ if (!pwd)
+ return FALSE;
+
+ if (pwd->pw_gid == gid)
+ return TRUE;
+
+ struct group *grp = getgrgid(gid);
+ if (!(grp && grp->gr_mem))
+ return FALSE;
+
+ for (tmp = grp->gr_mem; *tmp != NULL; tmp++)
+ {
+ if (g_strcmp0(*tmp, pwd->pw_name) == 0)
+ {
+ VERB3 log("user %s belongs to group: %s", pwd->pw_name, grp->gr_name);
+ return TRUE;
+ }
+ }
+
+ VERB2 log("user %s DOESN'T belong to group: %s", pwd->pw_name, grp->gr_name);
+ return FALSE;
+}
+#endif
+
+int dump_dir_accessible_by_uid(const char *dirname, uid_t uid)
+{
+ struct stat statbuf;
+ if (stat(dirname, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))
+ errno = ENOTDIR;
+ else
+ {
+#if DUMP_DIR_OWNED_BY_USER > 0
+ if (uid == 0 || (statbuf.st_mode & S_IROTH) || uid == statbuf.st_uid)
+#else
+ if (uid == 0 || (statbuf.st_mode & S_IROTH) || uid_in_group(uid, statbuf.st_gid))
+#endif
+ {
+ VERB1 log("directory '%s' is accessible by %ld uid", dirname, (long)uid);
+ return 1;
+ }
+ }
+
+ return 0;
+}
--
1.7.11.7
11 years, 3 months
[LIBREPORT PATCH] don't overwrite "type" rhbz#902828
by Jiri Moskovcak
---
src/lib/problem_data.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
index 724a702..6618ae2 100644
--- a/src/lib/problem_data.c
+++ b/src/lib/problem_data.c
@@ -60,12 +60,19 @@ problem_data_t *problem_data_new(void)
void problem_data_add_basics(problem_data_t *pd)
{
const char *analyzer = problem_data_get_content_or_NULL(pd, FILENAME_ANALYZER);
+ const char *type = problem_data_get_content_or_NULL(pd, FILENAME_TYPE);
if (analyzer == NULL)
{
analyzer = "libreport";
+
+ if (type)
+ analyzer = type;
+
problem_data_add_text_noteditable(pd, FILENAME_ANALYZER, analyzer);
}
- problem_data_add_text_noteditable(pd, FILENAME_TYPE, analyzer);
+
+ if (type == NULL)
+ problem_data_add_text_noteditable(pd, FILENAME_TYPE, analyzer);
/* If application didn't provide dupe hash, we generate it
* from all components, so we at least eliminate the exact same
--
1.8.1
11 years, 3 months
[LIBREPORT PATCH] move chown functionality from ABRT DBus to libreport
by Jakub Filak
- related to trac#927
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/include/dump_dir.h | 9 +++++++++
src/lib/dump_dir.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
index 89c7ff7..0a6a1b0 100644
--- a/src/include/dump_dir.h
+++ b/src/include/dump_dir.h
@@ -83,6 +83,15 @@ int dd_delete_item(struct dump_dir *dd, const char *name);
/* Returns 0 if directory is deleted or not found */
int dd_delete(struct dump_dir *dd);
int dd_rename(struct dump_dir *dd, const char *new_path);
+/* Changes owner of dump dir
+ * Uses two different strategies selected at build time by
+ * DUMP_DIR_OWNED_BY_USER configuration:
+ * <= 0 : owner = abrt user's uid, group = new_uid's gid
+ * > 0 : owner = new_uid, group = abrt group's gid
+ *
+ * On success, zero is returned. On error, -1 is returned.
+ */
+int dd_chown(struct dump_dir *dd, uid_t new_uid);
/* reported_to handling */
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index dfa19aa..f815848 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -760,6 +760,58 @@ int dd_delete(struct dump_dir *dd)
return r;
}
+int dd_chown(struct dump_dir *dd, uid_t new_uid)
+{
+ if (!dd->locked)
+ error_msg_and_die("dump_dir is not opened"); /* bug */
+
+ errno = 0;
+ struct stat statbuf;
+ if (!(stat(dd->dd_dirname, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)))
+ {
+ perror_msg("stat");
+ errno = 0;
+ return 1;
+ }
+
+ struct passwd *pw = getpwuid(new_uid);
+ if (!pw)
+ {
+ error_msg("UID %ld is not found in user database", (long)new_uid);
+ return 1;
+ }
+
+#if DUMP_DIR_OWNED_BY_USER > 0
+ uid_t owners_uid = pw->pw_uid;
+ gid_t groups_gid = statbuf.st_gid;
+#else
+ uid_t owners_uid = statbuf.st_uid;
+ gid_t groups_gid = pw->pw_gid;
+#endif
+
+ int chown_res = lchown(dd->dd_dirname, owners_uid, groups_gid);
+ int chown_errno = errno;
+ dd_init_next_file(dd);
+ char *full_name;
+ while (chown_res == 0 && dd_get_next_file(dd, /*short_name*/ NULL, &full_name))
+ {
+ VERB3 log("chowning %s", full_name);
+ chown_res = lchown(full_name, owners_uid, groups_gid);
+ chown_errno = errno;
+ free(full_name);
+ }
+
+ if (chown_res != 0)
+ {
+ errno = chown_errno;
+ perror_msg("chown");
+ errno = 0;
+ return 1;
+ }
+
+ return 0;
+}
+
static char *load_text_file(const char *path, unsigned flags)
{
int fd = open(path, O_RDONLY | ((flags & DD_OPEN_FOLLOW) ? 0 : O_NOFOLLOW));
--
1.7.11.7
11 years, 3 months
[ABRT PATCH] dbus: user dd_chown instead of own impl.
by Jakub Filak
- related to trac#927
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/dbus/abrt-dbus.c | 32 ++------------------------------
1 file changed, 2 insertions(+), 30 deletions(-)
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
index 5a58160..afda8d4 100644
--- a/src/dbus/abrt-dbus.c
+++ b/src/dbus/abrt-dbus.c
@@ -585,39 +585,11 @@ static void handle_method_call(GDBusConnection *connection,
return;
}
- struct passwd *pwd = getpwuid(caller_uid);
- if (!pwd)
- {
- error_msg("UID %ld is not found in user database", (long)caller_uid);
- dd_close(dd);
- return;
- }
-
- errno = 0;
- struct stat statbuf;
- if (!(stat(problem_dir, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)))
- {
- g_dbus_method_invocation_return_dbus_error(invocation,
- "org.freedesktop.problems.StatFailure",
- strerror(errno));
- dd_close(dd);
- return;
- }
-
- int chown_res = lchown(problem_dir, statbuf.st_uid, pwd->pw_gid);
- dd_init_next_file(dd);
- char *full_name;
- while (chown_res == 0 && dd_get_next_file(dd, /*short_name*/ NULL, &full_name))
- {
- VERB3 log("chowning %s", full_name);
- chown_res = lchown(full_name, statbuf.st_uid, pwd->pw_gid);
- free(full_name);
- }
-
+ int chown_res = dd_chown(dd, caller_uid);
if (chown_res != 0)
g_dbus_method_invocation_return_dbus_error(invocation,
"org.freedesktop.problems.ChownError",
- strerror(errno));
+ _("Chowning directory failed. Check system logs for more details."));
else
g_dbus_method_invocation_return_value(invocation, NULL);
--
1.7.11.7
11 years, 3 months