aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-06 15:32:47 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-06 15:32:47 +0200
commitfcecad2b77f54c1ce356190168db8ac2c216f30d (patch)
tree47bdf6a30375154474ba36a9676bff0cffffdf1b /src/libmdsserver
parentm (diff)
downloadmds-fcecad2b77f54c1ce356190168db8ac2c216f30d.tar.gz
mds-fcecad2b77f54c1ce356190168db8ac2c216f30d.tar.bz2
mds-fcecad2b77f54c1ce356190168db8ac2c216f30d.tar.xz
add strequals and startswith macros + add drop_privileges macro that drops the group before the user
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/macros.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index 0c2a2e2..bb4e1c3 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
+#include <string.h>
*/
@@ -180,5 +181,39 @@
buf_next(buffer, type, 1)
+/**
+ * Check whether two strings are equal
+ *
+ * @param a:char* One of the strings
+ * @param b:char* The other of the strings
+ * @return :int Whether the strings are equal
+ */
+#define strequals(a, b) \
+ (strcmp(a, b) == 0)
+
+
+/**
+ * Check whether a string starts with another string
+ *
+ * @param haystack:char* The string to inspect
+ * @param needle:char* The string `haystack` should start with
+ * @return :int Whether `haystack` starts with `needle`
+ */
+#define startswith(haystack, needle) \
+ (strstr(haystack, needle) == haystack)
+
+
+/**
+ * Set effective user and the effective group to the
+ * real user and the real group, respectively. If the
+ * group cannot be set, the user till not be set either.
+ *
+ * @return :int Non-zero on error
+ */
+#define drop_privileges() \
+ ((getegid() == getgid() ? 0 : setegid(getgid())) || \
+ (geteuid() == getuid() ? 0 : seteuid(getuid())))
+
+
#endif