diff options
| author | Gergely Nagy <algernon@balabit.hu> | 2012-03-20 11:56:30 +0100 |
|---|---|---|
| committer | Gergely Nagy <algernon@balabit.hu> | 2012-03-20 11:56:30 +0100 |
| commit | 4b1861e787693113e759c44519dd4396ee3dc0cd (patch) | |
| tree | 47ece5b5b69ca3476a342000b18b5921b9c4c6dd /lib | |
| parent | 1e062b1f74e499e39564da1485063e149c883df3 (diff) | |
| download | libumberlog-4b1861e787693113e759c44519dd4396ee3dc0cd.tar.gz libumberlog-4b1861e787693113e759c44519dd4396ee3dc0cd.tar.xz libumberlog-4b1861e787693113e759c44519dd4396ee3dc0cd.zip | |
Implement UID/GID discovery.
We now cache the uid and gid upon openlog(), and add it to the
automatic fields unless discovery is disabled.
The caching can be turned off by passing either the LOG_CEE_NOCACHE or
the LOG_CEE_NOCACHE_UID flag to openlog(). The latter also disables
caching the gid.
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/cee-syslog.c | 28 | ||||
| -rw-r--r-- | lib/cee-syslog.h | 5 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c index 60d8517..0256164 100644 --- a/lib/cee-syslog.c +++ b/lib/cee-syslog.c @@ -53,6 +53,8 @@ static __thread struct int facility; pid_t pid; + uid_t uid; + gid_t gid; const char *ident; } cee_sys_settings; @@ -72,6 +74,8 @@ cee_openlog (const char *ident, int option, int facility) cee_sys_settings.flags = option; cee_sys_settings.facility = facility; cee_sys_settings.pid = getpid (); + cee_sys_settings.gid = getgid (); + cee_sys_settings.uid = getuid (); cee_sys_settings.ident = ident; } @@ -104,7 +108,7 @@ _find_prio (int prio) return "<unknown>"; } -static inline const pid_t +static inline pid_t _find_pid (void) { if (cee_sys_settings.flags & LOG_CEE_NOCACHE) @@ -113,6 +117,26 @@ _find_pid (void) return cee_sys_settings.pid; } +static inline uid_t +_get_uid (void) +{ + if (cee_sys_settings.flags & LOG_CEE_NOCACHE || + cee_sys_settings.flags & LOG_CEE_NOCACHE_UID) + return getuid (); + else + return cee_sys_settings.uid; +} + +static inline uid_t +_get_gid (void) +{ + if (cee_sys_settings.flags & LOG_CEE_NOCACHE || + cee_sys_settings.flags & LOG_CEE_NOCACHE_UID) + return getgid (); + else + return cee_sys_settings.gid; +} + static struct json_object * _cee_json_vappend (struct json_object *json, va_list ap) { @@ -153,6 +177,8 @@ _cee_discover (struct json_object *jo, int priority) "facility", "%s", _find_facility (), "priority", "%s", _find_prio (priority), "program", "%s", cee_sys_settings.ident, + "uid", "%d", _get_uid (), + "gid", "%d", _get_gid (), NULL); } diff --git a/lib/cee-syslog.h b/lib/cee-syslog.h index 171f3ae..bba25c4 100644 --- a/lib/cee-syslog.h +++ b/lib/cee-syslog.h @@ -31,8 +31,9 @@ #include <syslog.h> #include <stdarg.h> -#define LOG_CEE_NODISCOVER 0x40 -#define LOG_CEE_NOCACHE 0x80 +#define LOG_CEE_NODISCOVER 0x0040 +#define LOG_CEE_NOCACHE 0x0080 +#define LOG_CEE_NOCACHE_UID 0x0100 char *cee_format (int priority, const char *msg_format, ...); char *cee_vformat (int priority, const char *msg_format, va_list ap); |
