[SCM] UID Wrapper Repository - branch master updated
Michael Adam
obnox at samba.org
Mon Jun 2 02:22:57 MDT 2014
The branch, master has been updated
via 80932d7 uwrap: Add logging if uwrap is enabled correctly.
via a4d3db5 uwrap: Log error if we are out of memory.
via 135582e uwrap: Add a better logging function.
via 334c562 cmake: Check for HAVE_FUNCTION_ATTRIBUTE_FORMAT.
from 690da04 uwrap: Fall back to RTLD_NEXT if we can't find libc.
http://gitweb.samba.org/?p=uid_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 80932d786bdf8ce6f8e4fb1f6b09f1252caba302
Author: Andreas Schneider <asn at samba.org>
Date: Fri May 30 15:52:19 2014 +0200
uwrap: Add logging if uwrap is enabled correctly.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit a4d3db55d723048ad07e76a3365b7500ad3262a5
Author: Andreas Schneider <asn at samba.org>
Date: Fri May 30 15:52:00 2014 +0200
uwrap: Log error if we are out of memory.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit 135582e8e9230ae0bfb0f99e3e549ec9e29c8183
Author: Andreas Schneider <asn at samba.org>
Date: Fri May 30 15:44:39 2014 +0200
uwrap: Add a better logging function.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit 334c562f100fb0bd007ee5461e0fef299ff768b4
Author: Andreas Schneider <asn at samba.org>
Date: Fri May 30 15:59:17 2014 +0200
cmake: Check for HAVE_FUNCTION_ATTRIBUTE_FORMAT.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
-----------------------------------------------------------------------
Summary of changes:
ConfigureChecks.cmake | 7 ++++
config.h.cmake | 1 +
src/uid_wrapper.c | 88 +++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 90 insertions(+), 6 deletions(-)
Changeset truncated at 500 lines:
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 123128f..899d905 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -143,6 +143,13 @@ int main(void) {
return 0;
}" HAVE_DESTRUCTOR_ATTRIBUTE)
+check_c_source_compiles("
+void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+
+int main(void) {
+ return 0;
+}" HAVE_FUNCTION_ATTRIBUTE_FORMAT)
+
# SYSTEM LIBRARIES
check_library_exists(dl dlopen "" HAVE_LIBDL)
diff --git a/config.h.cmake b/config.h.cmake
index 0e67b23..840b5d4 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -58,6 +58,7 @@
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
#cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
+#cmakedefine HAVE_FUNCTION_ATTRIBUTE_FORMAT 1
/*************************** ENDIAN *****************************/
diff --git a/src/uid_wrapper.c b/src/uid_wrapper.c
index e9c7d5a..f53aa47 100644
--- a/src/uid_wrapper.c
+++ b/src/uid_wrapper.c
@@ -49,11 +49,12 @@
#define DESTRUCTOR_ATTRIBUTE
#endif /* HAVE_DESTRUCTOR_ATTRIBUTE */
-#ifdef NDEBUG
-#define UWRAP_DEBUG(...)
+/* GCC have printf type attribute check. */
+#ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
+#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
#else
-#define UWRAP_DEBUG(...) fprintf(stderr, __VA_ARGS__)
-#endif
+#define PRINTF_ATTRIBUTE(a,b)
+#endif /* HAVE_FUNCTION_ATTRIBUTE_FORMAT */
#define UWRAP_DLIST_ADD(list,item) do { \
if (!(list)) { \
@@ -90,6 +91,70 @@
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
#endif
+/*****************
+ * LOGGING
+ *****************/
+
+enum uwrap_dbglvl_e {
+ UWRAP_LOG_ERROR = 0,
+ UWRAP_LOG_WARN,
+ UWRAP_LOG_DEBUG,
+ UWRAP_LOG_TRACE
+};
+
+#ifdef NDEBUG
+# define UWRAP_LOG(...)
+#else /* NDEBUG */
+static void uwrap_log(enum uwrap_dbglvl_e dbglvl, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
+# define UWRAP_LOG(dbglvl, ...) uwrap_log((dbglvl), __VA_ARGS__)
+
+static void uwrap_log(enum uwrap_dbglvl_e dbglvl, const char *format, ...)
+{
+ char buffer[1024];
+ va_list va;
+ const char *d;
+ unsigned int lvl = 0;
+
+ d = getenv("UID_WRAPPER_DEBUGLEVEL");
+ if (d != NULL) {
+ lvl = atoi(d);
+ }
+
+ va_start(va, format);
+ vsnprintf(buffer, sizeof(buffer), format, va);
+ va_end(va);
+
+ if (lvl >= dbglvl) {
+ switch (dbglvl) {
+ case UWRAP_LOG_ERROR:
+ fprintf(stderr,
+ "UWRAP_ERROR(%d): %s\n",
+ (int)getpid(), buffer);
+ break;
+ case UWRAP_LOG_WARN:
+ fprintf(stderr,
+ "UWRAP_WARN(%d): %s\n",
+ (int)getpid(), buffer);
+ break;
+ case UWRAP_LOG_DEBUG:
+ fprintf(stderr,
+ "UWRAP_DEBUG(%d): %s\n",
+ (int)getpid(), buffer);
+ break;
+ case UWRAP_LOG_TRACE:
+ fprintf(stderr,
+ "UWRAP_TRACE(%d): %s\n",
+ (int)getpid(), buffer);
+ break;
+ }
+ }
+}
+#endif /* NDEBUG */
+
+/*****************
+ * LIBC
+ *****************/
+
#define LIBC_NAME "libc.so"
struct uwrap_libc_fns {
@@ -425,12 +490,14 @@ static int uwrap_new_id(pthread_t tid, bool do_alloc)
if (do_alloc) {
id = malloc(sizeof(struct uwrap_thread));
if (id == NULL) {
+ UWRAP_LOG(UWRAP_LOG_ERROR, "Unable to allocate memory");
errno = ENOMEM;
return -1;
}
id->groups = malloc(sizeof(gid_t) * 1);
if (id->groups == NULL) {
+ UWRAP_LOG(UWRAP_LOG_ERROR, "Unable to allocate memory");
SAFE_FREE(id);
errno = ENOMEM;
return -1;
@@ -511,6 +578,8 @@ static void uwrap_init(void)
return;
}
+ UWRAP_LOG(UWRAP_LOG_DEBUG, "Initialize uid_wrapper");
+
/*
* If we hold a lock and the application forks, then the child
* is not able to unlock the mutex and we are in a deadlock.
@@ -544,9 +613,15 @@ static void uwrap_init(void)
}
uwrap.enabled = true;
+
+ UWRAP_LOG(UWRAP_LOG_DEBUG,
+ "Enabled uid_wrapper as %s",
+ uwrap.myuid == 0 ? "root" : "user");
}
pthread_mutex_unlock(&uwrap_id_mutex);
+
+ UWRAP_LOG(UWRAP_LOG_DEBUG, "Succeccfully initialized uid_wrapper");
}
bool uid_wrapper_enabled(void)
@@ -1110,8 +1185,9 @@ static long int uwrap_syscall (long int sysno, va_list vp)
}
break;
default:
- UWRAP_DEBUG("UID_WRAPPER calling non-wrapped syscall "
- "%lu\n", sysno);
+ UWRAP_LOG(UWRAP_LOG_DEBUG,
+ "UID_WRAPPER calling non-wrapped syscall %lu\n",
+ sysno);
rc = libc_vsyscall(sysno, vp);
break;
--
UID Wrapper Repository
More information about the samba-cvs
mailing list