]> arthur.barton.de Git - netatalk.git/blob - bin/misc/uuidtest.c
Support for local UUIDs
[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 #ifdef HAVE_ACLS
20
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdarg.h>
26 #include <ldap.h>
27
28 #include <atalk/ldapconfig.h>
29 #include <atalk/uuid.h>
30 #include <atalk/logger.h>
31
32 #define STRNCMP(a, R, b, l) (strncmp(a,b,l) R 0)
33
34 static void usage()
35 {
36     printf("Usage: afpldaptest -u <user> | -g <group> | -i <UUID>\n");
37 }
38
39 static void parse_ldapconf()
40 {
41     static int inited = 0;
42
43     if (! inited) {
44         /* Parse afp_ldap.conf */
45         printf("Start parsing afp_ldap.conf\n");
46         acl_ldap_readconfig(_PATH_ACL_LDAPCONF);
47         printf("Finished parsing afp_ldap.conf\n");
48         if (ldap_config_valid) {
49             if (ldap_auth_method == LDAP_AUTH_NONE)
50                 printf("afp_ldap.conf is ok. Using anonymous bind.\n");
51             else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
52                 printf("afp_ldap.conf is ok. Using simple bind.\n");
53             else {
54                 ldap_config_valid = 0;
55                 printf("afp_ldap.conf wants SASL which is not yet supported.\n");
56                 exit(EXIT_FAILURE);
57             }
58         } else {
59             printf("afp_ldap.conf is not ok, not using LDAP. Only local UUID testing available.\n");
60         }
61         inited = 1;
62     }
63 }
64
65 int main( int argc, char **argv)
66 {
67     int ret, c;
68     int verbose = 0;
69     atalk_uuid_t uuid;
70     int logsetup = 0;
71     uuidtype_t type;
72     char *name = NULL;
73
74     while ((c = getopt(argc, argv, ":vu:g:i:")) != -1) {
75         switch(c) {
76
77         case 'v':
78             if (! verbose) {
79                 verbose = 1;
80                 setuplog("default log_maxdebug /dev/tty");
81                 logsetup = 1;
82             }
83             break;
84
85         case 'u':
86             if (! logsetup)
87                 setuplog("default log_info /dev/tty");
88             parse_ldapconf();
89             printf("Searching user: %s\n", optarg);
90             ret = getuuidfromname( optarg, UUID_USER, uuid);
91             if (ret == 0) {
92                 printf("User: %s ==> UUID: %s\n", optarg, uuid_bin2string(uuid));
93             } else {
94                 printf("User %s not found.\n", optarg);
95             }
96             break;
97
98         case 'g':
99             if (! logsetup)
100                 setuplog("default log_info /dev/tty");
101             parse_ldapconf();
102             printf("Searching group: %s\n", optarg);
103             ret = getuuidfromname( optarg, UUID_GROUP, uuid);
104             if (ret == 0) {
105                 printf("Group: %s ==> UUID: %s\n", optarg, uuid_bin2string(uuid));
106             } else {
107                 printf("Group %s not found.\n", optarg);
108             }
109             break;
110
111         case 'i':
112             if (! logsetup)
113                 setuplog("default log_info /dev/tty");
114             parse_ldapconf();
115             printf("Searching uuid: %s\n", optarg);
116             uuid_string2bin(optarg, uuid);
117             ret = getnamefromuuid( uuid, &name, &type);
118             if (ret == 0) {
119                 switch (type) {
120                 case UUID_LOCAL:
121                     printf("local UUID: %s\n", optarg);
122                     break;
123                 case UUID_USER:
124                     printf("UUID: %s ==> User: %s\n", optarg, name);
125                     break;
126                 case UUID_GROUP:
127                     printf("UUID: %s ==> Group: %s\n", optarg, name);
128                     break;
129                 }
130                 free(name);
131             } else {
132                 printf("UUID: %s not found.\n", optarg);
133             }
134             break;
135
136         case ':':
137         case '?':
138         case 'h':
139             usage();
140             exit(EXIT_FAILURE);
141         }
142     }
143
144     return 0;
145 }
146
147 #endif  /* HAVE_ACLS */