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