]> arthur.barton.de Git - netatalk.git/blob - bin/misc/uuidtest.c
Rename uuidtest to afpldaptest
[netatalk.git] / bin / misc / uuidtest.c
1 /*
2   $Id: uuidtest.c,v 1.1 2009-11-27 21:15:48 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: uuidtest -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     uuid_t uuid;
72     uuidtype_t type;
73     char *uuidstring = NULL;
74     char *name = NULL;
75
76     setuplog("default log_error /dev/tty");
77
78     while ((c = getopt(argc, argv, ":vu:g:i:")) != -1) {
79         switch(c) {
80
81         case 'v':
82             if (! verbose) {
83                 verbose = 1;
84                 setuplog("default log_debug /dev/tty");
85             }
86             break;
87
88         case 'u':
89             parse_ldapconf();
90             printf("Searching user: %s\n", optarg);
91             ret = getuuidfromname( optarg, UUID_USER, uuid);
92             if (ret == 0) {
93                 uuid_bin2string( uuid, &uuidstring);
94                 printf("User: %s ==> UUID: %s\n", optarg, uuidstring);
95                 free(uuidstring);
96             } else {
97                 printf("User %s not found.\n", optarg);
98             }
99             break;
100
101         case 'g':
102             parse_ldapconf();
103             printf("Searching group: %s\n", optarg);
104             ret = getuuidfromname( optarg, UUID_GROUP, uuid);
105             if (ret == 0) {
106                 uuid_bin2string( uuid, &uuidstring);
107                 printf("Group: %s ==> UUID: %s\n", optarg, uuidstring);
108                 free(uuidstring);
109             } else {
110                 printf("Group %s not found.\n", optarg);
111             }
112             break;
113
114         case 'i':
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                 if (type == UUID_USER)
121                     printf("UUID: %s ==> User: %s\n", optarg, name);
122                 else
123                     printf("UUID: %s ==> Group: %s\n", optarg, name);
124                 free(name);
125             } else {
126                 printf("UUID: %s not found.\n", optarg);
127             }
128             break;
129
130         case ':':
131         case '?':
132             usage();
133             exit(EXIT_FAILURE);
134         }
135     }
136
137     return 0;
138 }
139
140 #endif  /* HAVE_NFSv4_ACLS */