summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-10-03 17:02:50 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-10-03 17:22:14 +0200
commit99a53eb2a4a6f0204f0f6e18f4f5698b79b4e330 (patch)
tree877edd05a8942a39e3befb7e2c812e2694698c7a
parent98608cbe2bed49eda0ecb9d72bf98d9f8d3a19ed (diff)
downloadcifs_idmap_sss-99a53eb2a4a6f0204f0f6e18f4f5698b79b4e330.tar.gz
cifs_idmap_sss-99a53eb2a4a6f0204f0f6e18f4f5698b79b4e330.tar.bz2
cifs_idmap_sss-99a53eb2a4a6f0204f0f6e18f4f5698b79b4e330.zip
Add debug makro
Convert syslog(3) calls to use it. Enable with: ./configure CFLAGS=-DDEBUG
-rw-r--r--cifs_idmap_sss.c56
-rw-r--r--configure.ac3
2 files changed, 33 insertions, 26 deletions
diff --git a/cifs_idmap_sss.c b/cifs_idmap_sss.c
index 4829e3d..5be3294 100644
--- a/cifs_idmap_sss.c
+++ b/cifs_idmap_sss.c
@@ -18,28 +18,36 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/* TODO: Support well known SIDs as in samba's
+ * - librpc/idl/security.idl or
+ * - source4/rpc_server/lsa/lsa_lookup.c?
+ */
+
+/* TODO: Support of [all] samba's Unix SIDs:
+ * Users: S-1-22-1-%UID
+ * Groups: S-1-22-2-%GID
+ */
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
+#include <stdarg.h>
#include <sss_idmap.h>
#include <sss_nss_idmap.h>
#include <cifsidmap.h>
-#include <syslog.h>
-
#define WORLD_SID "S-1-1-0"
-/* TODO: Support well known SIDs as in samba's
- * - librpc/idl/security.idl or
- * - source4/rpc_server/lsa/lsa_lookup.c?
- */
-
-/* TODO: Support of [all] samba's Unix SIDs:
- * Users: S-1-22-1-%UID
- * Groups: S-1-22-2-%GID
- */
+#ifdef DEBUG
+#include <syslog.h>
+#define debug(str, ...) \
+ syslog(0, "%s: " str "\n", \
+ __FUNCTION__, ##__VA_ARGS__ )
+#else
+#define debug(...) do { } while(0)
+#endif
struct sssd_ctx {
struct sss_idmap_ctx *idmap;
@@ -49,7 +57,7 @@ struct sssd_ctx {
#define ctx_set_error(ctx, error) \
do { \
*ctx->errmsg = error; \
- syslog(0, "%s: %s\n", __FUNCTION__, error ? error : ""); \
+ debug("%s", error ? error : ""); \
} while (0);
int
@@ -81,7 +89,7 @@ cifs_idmap_exit_plugin(void *handle)
{
struct sssd_ctx *ctx = handle;
- syslog(0, "%s\n", __FUNCTION__);
+ debug("exit");
sss_idmap_free(ctx->idmap);
@@ -98,8 +106,6 @@ int cifs_idmap_sid_to_str(void *handle, const struct cifs_sid *sid,
enum sss_id_type id_type;
int err;
- syslog(0, "%s\n", __FUNCTION__);
-
idmap_err = sss_idmap_bin_sid_to_sid(ctx->idmap,
(uint8_t *) sid, sizeof(*sid),
&str_sid);
@@ -109,7 +115,7 @@ int cifs_idmap_sid_to_str(void *handle, const struct cifs_sid *sid,
return -1;
}
- syslog(0, "%s: str_sid: %s\n", __FUNCTION__, str_sid);
+ debug("sid: %s", str_sid);
if (strcmp(str_sid, WORLD_SID) == 0) {
*name = strdup("\\Everyone");
@@ -127,7 +133,7 @@ int cifs_idmap_sid_to_str(void *handle, const struct cifs_sid *sid,
return -err;
}
- syslog(0, "%s: name: %s\n", __FUNCTION__, *name);
+ debug("name: %s", *name);
return 0;
}
@@ -145,10 +151,10 @@ int cifs_idmap_str_to_sid(void *handle, const char *name,
size_t length;
int success = 0;
- syslog(0, "%s: %s\n", __FUNCTION__, name);
+ debug("%s", name);
if (strncmp("S-", name, 2) == 0) {
- syslog(0, "%s: name is sid string representation\n", __FUNCTION__);
+ debug("%s: name is sid string representation\n", __FUNCTION__);
str_sid = strdup(name);
} else {
err = sss_nss_getsidbyname(name, &str_sid, &id_type);
@@ -168,7 +174,7 @@ int cifs_idmap_str_to_sid(void *handle, const char *name,
goto out;
}
if (length > sizeof(struct cifs_sid)) {
- syslog(0, "%s: length: %zd\n", __FUNCTION__, length);
+ debug("length: %zd", length);
ctx_set_error(ctx, "incompatible internal sid length\n");
success = -1;
goto out;
@@ -194,7 +200,7 @@ int cifs_idmap_sids_to_ids(void *handle, const struct cifs_sid *sid,
int success = -1;
int i;
- syslog(0, "%s: num: %zd\n", __FUNCTION__, num);
+ debug("num: %zd", num);
if (num > UINT_MAX) {
ctx_set_error(ctx, "num is too large.");
@@ -231,9 +237,9 @@ int cifs_idmap_sids_to_ids(void *handle, const struct cifs_sid *sid,
continue;
#endif
}
- syslog(0, "%s: setting uid of %s to %d\n", __FUNCTION__, str_sid, cuxid[i].id.uid);
+ debug("setting uid of %s to %d", str_sid, cuxid[i].id.uid);
}
- syslog(0, "%s: str_sid: %s, id: %d\n", __FUNCTION__, str_sid, cuxid[i].id.uid);
+ debug("str_sid: %s, id: %d\n", str_sid, cuxid[i].id.uid);
success = 0;
@@ -266,7 +272,7 @@ int cifs_idmap_ids_to_sids(void *handle, const struct cifs_uxid *cuxid,
int success = -1;
int i;
- syslog(0, "%s\n", __FUNCTION__);
+ debug("num ids: %zd", num);
for (i = 0; i < num; ++i) {
char *str_sid;
@@ -289,7 +295,7 @@ int cifs_idmap_ids_to_sids(void *handle, const struct cifs_uxid *cuxid,
continue;
}
if (length > sizeof(struct cifs_sid)) {
- syslog(0, "%s: length: %zd\n", __FUNCTION__, length);
+ debug("length: %zd", length);
ctx_set_error(ctx, "incompatible internal sid length\n");
success = -1;
continue;
diff --git a/configure.ac b/configure.ac
index 4fb829d..85bb264 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,11 +11,12 @@ PKG_CHECK_MODULES([SSS_IDMAP], [sss_idmap sss_nss_idmap])
# Checks for programs.
AC_PROG_CC
+AC_PROG_CC_C99
# Checks for libraries.
# Checks for header files.
-AC_CHECK_HEADERS([limits.h stdlib.h string.h syslog.h cifsidmap.h])
+AC_CHECK_HEADERS([limits.h stdlib.h string.h cifsidmap.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T