]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/acl/ldap.c
Fix automake var
[netatalk.git] / libatalk / acl / ldap.c
index 379ee73772f1ac99271827aa4096645afbceaae1..062bab72acbb5d487bc9cfec403b4dd21f9808cd 100644 (file)
@@ -1,5 +1,4 @@
 /*
-  $Id: ldap.c,v 1.7 2010-04-23 11:37:06 franklahm Exp $
   Copyright (c) 2008,2009 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#ifdef HAVE_LDAP
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/time.h>
 #include <string.h>
 #include <errno.h>
+#define LDAP_DEPRECATED 1
 #include <ldap.h>
 
 #include <atalk/logger.h>
@@ -47,36 +49,38 @@ int  ldap_userscope;
 char *ldap_groupbase;
 int  ldap_groupscope;
 char *ldap_uuid_attr;
+char *ldap_uuid_string;
 char *ldap_name_attr;
 char *ldap_group_attr;
 char *ldap_uid_attr;
 
 struct ldap_pref ldap_prefs[] = {
-    {&ldap_server,     "ldap_server",      0, 0, -1},
-    {&ldap_auth_method,"ldap_auth_method", 1, 1, -1},
-    {&ldap_auth_dn,    "ldap_auth_dn",     0, 0,  0},
-    {&ldap_auth_pw,    "ldap_auth_pw",     0, 0,  0},
-    {&ldap_userbase,   "ldap_userbase",    0, 0, -1},
-    {&ldap_userscope,  "ldap_userscope",   1 ,1, -1},
-    {&ldap_groupbase,  "ldap_groupbase",   0, 0, -1},
-    {&ldap_groupscope, "ldap_groupscope",  1 ,1, -1},
-    {&ldap_uuid_attr,  "ldap_uuid_attr",   0, 0, -1},
-    {&ldap_name_attr,  "ldap_name_attr",   0, 0, -1},
-    {&ldap_group_attr, "ldap_group_attr",  0, 0, -1},
-    {&ldap_uid_attr,   "ldap_uid_attr",    0, 0,  0},
+    {&ldap_server,     "ldap server",      0, 0, -1},
+    {&ldap_auth_method,"ldap auth method", 1, 1, -1},
+    {&ldap_auth_dn,    "ldap auth dn",     0, 0,  0},
+    {&ldap_auth_pw,    "ldap auth pw",     0, 0,  0},
+    {&ldap_userbase,   "ldap userbase",    0, 0, -1},
+    {&ldap_userscope,  "ldap userscope",   1 ,1, -1},
+    {&ldap_groupbase,  "ldap groupbase",   0, 0, -1},
+    {&ldap_groupscope, "ldap groupscope",  1 ,1, -1},
+    {&ldap_uuid_attr,  "ldap uuid attr",   0, 0, -1},
+    {&ldap_uuid_string,"ldap uuid string", 0, 0,  0},
+    {&ldap_name_attr,  "ldap name attr",   0, 0, -1},
+    {&ldap_group_attr, "ldap group attr",  0, 0, -1},
+    {&ldap_uid_attr,   "ldap uid attr",    0, 0,  0},
     {NULL,             NULL,               0, 0, -1}
 };
 
 struct pref_array prefs_array[] = {
-    {"ldap_auth_method", "none",   LDAP_AUTH_NONE},
-    {"ldap_auth_method", "simple", LDAP_AUTH_SIMPLE},
-    {"ldap_auth_method", "sasl",   LDAP_AUTH_SASL},
-    {"ldap_userscope",   "base",   LDAP_SCOPE_BASE},
-    {"ldap_userscope",   "one",    LDAP_SCOPE_ONELEVEL},
-    {"ldap_userscope",   "sub",    LDAP_SCOPE_SUBTREE},
-    {"ldap_groupscope",  "base",   LDAP_SCOPE_BASE},
-    {"ldap_groupscope",  "one",    LDAP_SCOPE_ONELEVEL},
-    {"ldap_groupscope",  "sub",    LDAP_SCOPE_SUBTREE},
+    {"ldap auth method", "none",   LDAP_AUTH_NONE},
+    {"ldap auth method", "simple", LDAP_AUTH_SIMPLE},
+    {"ldap auth method", "sasl",   LDAP_AUTH_SASL},
+    {"ldap userscope",   "base",   LDAP_SCOPE_BASE},
+    {"ldap userscope",   "one",    LDAP_SCOPE_ONELEVEL},
+    {"ldap userscope",   "sub",    LDAP_SCOPE_SUBTREE},
+    {"ldap groupscope",  "base",   LDAP_SCOPE_BASE},
+    {"ldap groupscope",  "one",    LDAP_SCOPE_ONELEVEL},
+    {"ldap groupscope",  "sub",    LDAP_SCOPE_SUBTREE},
     {NULL,               NULL,     0}
 };
 
@@ -247,9 +251,16 @@ cleanup:
  * Interface
  ********************************************************/
 
-/* 
- * returns allocated storage in uuid_string, caller must free it
- * returns 0 on success, -1 on error or not found
+/*! 
+ * Search UUID for name in LDAP
+ *
+ * Caller must free uuid_string when done with it
+ *
+ * @param name        (r) name to search
+ * @param type        (r) type of USER or GROUP
+ * @param uuid_string (w) result as pointer to allocated UUID-string
+ *
+ * @returns 0 on success, -1 on error or not found
  */
 int ldap_getuuidfromname( const char *name, uuidtype_t type, char **uuid_string) {
     int ret;
@@ -258,6 +269,9 @@ int ldap_getuuidfromname( const char *name, uuidtype_t type, char **uuid_string)
     char *attributes[]  = { ldap_uuid_attr, NULL};
     char *ldap_attr;
 
+    if (!ldap_config_valid)
+        return -1;
+
     /* make filter */
     if (type == UUID_GROUP)
         ldap_attr = ldap_group_attr;
@@ -283,13 +297,22 @@ int ldap_getuuidfromname( const char *name, uuidtype_t type, char **uuid_string)
  * LDAP search wrapper
  * returns allocated storage in name, caller must free it
  * returns 0 on success, -1 on error or not found
+ * 
+ * @param uuidstr  (r) uuid to search as ascii string
+ * @param name     (w) return pointer to name as allocated string
+ * @param type     (w) return type: USER or GROUP
+ *
+ * returns 0 on success, -1 on errror
  */
-int ldap_getnamefromuuid( char *uuidstr, char **name, uuidtype_t *type) {
+int ldap_getnamefromuuid( const char *uuidstr, char **name, uuidtype_t *type) {
     int ret;
     int len;
     char filter[256];       /* this should really be enough. we dont want to malloc everything! */
     char *attributes[]  = { NULL, NULL};
 
+    if (!ldap_config_valid)
+        return -1;
+
     /* make filter */
     len = snprintf( filter, 256, "%s=%s", ldap_uuid_attr, uuidstr);
     if (len >= 256 || len == -1) {
@@ -315,3 +338,4 @@ int ldap_getnamefromuuid( char *uuidstr, char **name, uuidtype_t *type) {
 
     return -1;
 }
+#endif  /* HAVE_LDAP */