File syslog-ng-avoid-getpwgrnam_-1.dif of Package syslog-ng
--- src/affile.c
+++ src/affile.c 2008/08/19 09:46:57
@@ -455,7 +455,7 @@ affile_dd_set_file_uid(LogDriver *s, con
AFFileDestDriver *self = (AFFileDestDriver *) s;
self->file_uid = 0;
- if (!resolve_user(file_uid, &self->file_uid))
+ if (!resolve_user(file_uid, &self->file_uid) && self->file_uid != (uid_t)-1)
{
msg_error("Error resolving user",
evt_tag_str("user", file_uid),
@@ -469,7 +469,7 @@ affile_dd_set_file_gid(LogDriver *s, con
AFFileDestDriver *self = (AFFileDestDriver *) s;
self->file_gid = 0;
- if (!resolve_group(file_gid, &self->file_gid))
+ if (!resolve_group(file_gid, &self->file_gid) && self->file_gid != (gid_t)-1)
{
msg_error("Error resolving group",
evt_tag_str("group", file_gid),
@@ -491,7 +491,7 @@ affile_dd_set_dir_uid(LogDriver *s, cons
AFFileDestDriver *self = (AFFileDestDriver *) s;
self->dir_uid = 0;
- if (!resolve_user(dir_uid, &self->dir_uid))
+ if (!resolve_user(dir_uid, &self->dir_uid) && self->dir_uid != (uid_t)-1)
{
msg_error("Error resolving user",
evt_tag_str("user", dir_uid),
@@ -505,7 +505,7 @@ affile_dd_set_dir_gid(LogDriver *s, cons
AFFileDestDriver *self = (AFFileDestDriver *) s;
self->dir_gid = 0;
- if (!resolve_group(dir_gid, &self->dir_gid))
+ if (!resolve_group(dir_gid, &self->dir_gid) && self->dir_gid != (gid_t)-1)
{
msg_error("Error resolving group",
evt_tag_str("group", dir_gid),
--- src/afunix.c
+++ src/afunix.c 2008/08/19 09:45:05
@@ -36,7 +36,7 @@ afunix_sd_set_uid(LogDriver *s, gchar *o
{
AFUnixSourceDriver *self = (AFUnixSourceDriver *) s;
- if (!resolve_user(owner, &self->owner))
+ if (!resolve_user(owner, &self->owner) && self->owner != (uid_t)-1)
msg_error("Error resolving username",
evt_tag_str("owner", owner),
NULL);
@@ -47,7 +47,7 @@ afunix_sd_set_gid(LogDriver *s, gchar *g
{
AFUnixSourceDriver *self = (AFUnixSourceDriver *) s;
- if (!resolve_group(group, &self->group))
+ if (!resolve_group(group, &self->group) && self->group != (gid_t)-1)
msg_error("Error resolving group",
evt_tag_str("group", group),
NULL);
--- src/cfg.c
+++ src/cfg.c 2008/08/19 10:18:38
@@ -91,6 +91,8 @@ cfg_file_owner_set(GlobalConfig *self, g
msg_error("Error resolving user",
evt_tag_str("user", owner),
NULL);
+ if (self->file_uid == (uid_t)-1)
+ self->file_uid = 0;
}
void
@@ -100,6 +102,8 @@ cfg_file_group_set(GlobalConfig *self, g
msg_error("Error resolving group",
evt_tag_str("group", group),
NULL);
+ if (self->file_gid == (gid_t)-1)
+ self->file_gid = 0;
}
void
@@ -115,6 +119,8 @@ cfg_dir_owner_set(GlobalConfig *self, gc
msg_error("Error resolving user",
evt_tag_str("user", owner),
NULL);
+ if (self->dir_uid == (uid_t)-1)
+ self->dir_uid = 0;
}
void
@@ -124,6 +130,8 @@ cfg_dir_group_set(GlobalConfig *self, gc
msg_error("Error resolving group",
evt_tag_str("group", group),
NULL);
+ if (self->dir_gid == (gid_t)-1)
+ self->dir_gid = 0;
}
void
--- src/misc.c
+++ src/misc.c 2008/08/19 09:36:15
@@ -250,7 +250,16 @@ resolve_user(const char *user, uid_t *ui
{
struct passwd *pw;
+ if (!uid || !user || !*user)
+ return FALSE;
+
*uid = 0;
+ if (*user == '-')
+ {
+ *uid = -1;
+ return FALSE;
+ }
+
pw = getpwnam(user);
if (pw)
{
@@ -270,7 +279,16 @@ resolve_group(const char *group, gid_t *
{
struct group *gr;
+ if (!gid || !group || !*group)
+ return FALSE;
+
*gid = 0;
+ if (*group == '-')
+ {
+ *gid = -1;
+ return FALSE;
+ }
+
gr = getgrnam(group);
if (gr)
{