aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blogc/funcvars.c4
-rw-r--r--src/blogc/sysinfo.c35
-rw-r--r--src/blogc/sysinfo.h10
3 files changed, 49 insertions, 0 deletions
diff --git a/src/blogc/funcvars.c b/src/blogc/funcvars.c
index 96bc3c5..beb5f8a 100644
--- a/src/blogc/funcvars.c
+++ b/src/blogc/funcvars.c
@@ -30,6 +30,10 @@ static const struct func_map {
{"BLOGC_SYSINFO_HOSTNAME", blogc_sysinfo_inject_hostname},
#endif
+#ifdef HAVE_SYSINFO_USERNAME
+ {"BLOGC_SYSINFO_USERNAME", blogc_sysinfo_inject_username},
+#endif
+
#ifdef HAVE_SYSINFO_DATETIME
{"BLOGC_SYSINFO_DATETIME", blogc_sysinfo_inject_datetime},
#endif
diff --git a/src/blogc/sysinfo.c b/src/blogc/sysinfo.c
index d934483..61c8b1d 100644
--- a/src/blogc/sysinfo.c
+++ b/src/blogc/sysinfo.c
@@ -14,6 +14,14 @@
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif /* HAVE_PWD_H */
+
#ifdef HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */
@@ -52,6 +60,33 @@ blogc_sysinfo_inject_hostname(bc_trie_t *global)
char*
+blogc_sysinfo_get_username(void)
+{
+#ifndef HAVE_SYSINFO_USERNAME
+ return NULL;
+#else
+ uid_t u = geteuid();
+ struct passwd *p = getpwuid(u);
+ if (p == NULL)
+ return NULL;
+
+ return bc_strdup(p->pw_name);
+#endif
+}
+
+
+void
+blogc_sysinfo_inject_username(bc_trie_t *global)
+{
+ char *username = blogc_sysinfo_get_username();
+ if (username == NULL)
+ return;
+
+ bc_trie_insert(global, "BLOGC_SYSINFO_USERNAME", username);
+}
+
+
+char*
blogc_sysinfo_get_datetime(void)
{
#ifndef HAVE_SYSINFO_DATETIME
diff --git a/src/blogc/sysinfo.h b/src/blogc/sysinfo.h
index f26662a..25f2177 100644
--- a/src/blogc/sysinfo.h
+++ b/src/blogc/sysinfo.h
@@ -19,6 +19,14 @@
#endif /* HAVE_GETHOSTNAME */
#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_UNISTD_H
+#ifdef HAVE_SYS_TYPES_H
+#ifdef HAVE_PWD_H
+#define HAVE_SYSINFO_USERNAME 1
+#endif /* HAVE_PWD_H */
+#endif /* HAVE_SYS_TYPES_H */
+#endif /* HAVE_UNISTD_H */
+
#ifdef HAVE_TIME_H
#define HAVE_SYSINFO_DATETIME 1
#endif /* HAVE_TIME_H */
@@ -27,6 +35,8 @@
char* blogc_sysinfo_get_hostname(void);
void blogc_sysinfo_inject_hostname(bc_trie_t *global);
+char* blogc_sysinfo_get_username(void);
+void blogc_sysinfo_inject_username(bc_trie_t *global);
char* blogc_sysinfo_get_datetime(void);
void blogc_sysinfo_inject_datetime(bc_trie_t *global);