]> arthur.barton.de Git - netatalk.git/blob - bin/misc/uuidtest.c
Update acl/ldap defines part 2
[netatalk.git] / bin / misc / uuidtest.c
1 /*
2   Copyright (c) 2008,2009 Frank Lahm <franklahm@gmail.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif /* HAVE_CONFIG_H */
18
19 #include <unistd.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdarg.h>
24
25 #include <atalk/ldapconfig.h>
26 #include <atalk/uuid.h>
27 #include <atalk/logger.h>
28
29 #define STRNCMP(a, R, b, l) (strncmp(a,b,l) R 0)
30
31 static void usage()
32 {
33     printf("Usage: afpldaptest -u <user> | -g <group> | -i <UUID>\n");
34 }
35
36 static void parse_ldapconf()
37 {
38     static int inited = 0;
39
40     if (! inited) {
41 #ifdef HAVE_LDAP
42         /* Parse afp_ldap.conf */
43         printf("Start parsing afp_ldap.conf\n");
44         acl_ldap_readconfig(_PATH_ACL_LDAPCONF);
45         printf("Finished parsing afp_ldap.conf\n");
46         if (ldap_config_valid) {
47             if (ldap_auth_method == LDAP_AUTH_NONE)
48                 printf("afp_ldap.conf is ok. Using anonymous bind.\n");
49             else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
50                 printf("afp_ldap.conf is ok. Using simple bind.\n");
51             else {
52                 ldap_config_valid = 0;
53                 printf("afp_ldap.conf wants SASL which is not yet supported.\n");
54                 exit(EXIT_FAILURE);
55             }
56         } else {
57             printf("afp_ldap.conf is not ok, not using LDAP. Only local UUID testing available.\n");
58         }
59 #else
60         printf("Built without LDAP support, only local UUID testing available.\n");
61 #endif
62         inited = 1;
63     }
64 }
65
66 int main( int argc, char **argv)
67 {
68     int ret, c;
69     int verbose = 0;
70     atalk_uuid_t uuid;
71     int logsetup = 0;
72     uuidtype_t type;
73     char *name = NULL;
74
75     while ((c = getopt(argc, argv, ":vu:g:i:")) != -1) {
76         switch(c) {
77
78         case 'v':
79             if (! verbose) {
80                 verbose = 1;
81                 setuplog("default log_maxdebug /dev/tty");
82                 logsetup = 1;
83             }
84             break;
85
86         case 'u':
87             if (! logsetup)
88                 setuplog("default log_info /dev/tty");
89             parse_ldapconf();
90             printf("Searching user: %s\n", optarg);
91             ret = getuuidfromname( optarg, UUID_USER, uuid);
92             if (ret == 0) {
93                 printf("User: %s ==> UUID: %s\n", optarg, uuid_bin2string(uuid));
94             } else {
95                 printf("User %s not found.\n", optarg);
96             }
97             break;
98
99         case 'g':
100             if (! logsetup)
101                 setuplog("default log_info /dev/tty");
102             parse_ldapconf();
103             printf("Searching group: %s\n", optarg);
104             ret = getuuidfromname( optarg, UUID_GROUP, uuid);
105             if (ret == 0) {
106                 printf("Group: %s ==> UUID: %s\n", optarg, uuid_bin2string(uuid));
107             } else {
108                 printf("Group %s not found.\n", optarg);
109             }
110             break;
111
112         case 'i':
113             if (! logsetup)
114                 setuplog("default log_info /dev/tty");
115             parse_ldapconf();
116             printf("Searching uuid: %s\n", optarg);
117             uuid_string2bin(optarg, uuid);
118             ret = getnamefromuuid( uuid, &name, &type);
119             if (ret == 0) {
120                 switch (type) {
121                 case UUID_LOCAL:
122                     printf("local UUID: %s\n", optarg);
123                     break;
124                 case UUID_USER:
125                     printf("UUID: %s ==> User: %s\n", optarg, name);
126                     break;
127                 case UUID_GROUP:
128                     printf("UUID: %s ==> Group: %s\n", optarg, name);
129                     break;
130                 }
131                 free(name);
132             } else {
133                 printf("UUID: %s not found.\n", optarg);
134             }
135             break;
136
137         case ':':
138         case '?':
139         case 'h':
140             usage();
141             exit(EXIT_FAILURE);
142         }
143     }
144
145     return 0;
146 }
147