]> arthur.barton.de Git - netatalk.git/blob - contrib/acltests/uuidtest.c
fd4d208a5601d15c6a37c01f9ef0e23b09492dbb
[netatalk.git] / contrib / acltests / uuidtest.c
1 /*
2    $Id: uuidtest.c,v 1.1 2009-02-02 11:55:00 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 <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <unistd.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 int main( int argc, char **argv)
35 {
36     int ret, i;
37     uuid_t uuid;
38     uuidtype_t type;
39     char *uuidstring = NULL;
40     char *name = NULL;
41
42     if (argc <  2) {
43         printf("Usage: uuidtest <name> | -u<UUID> [<name> ... | -u<UUID> ...] \n");
44         return -1;
45     }
46     
47     set_processname("uuidtest");
48     log_init();
49     log_setup("uuid.log", log_maxdebug, logtype_default, logoption_cons);
50
51
52     /* Parse ldap.conf */
53     printf("Start parsing ldap.conf\n");
54     acl_ldap_readconfig(_PATH_ACL_LDAPCONF);
55     printf("Finished parsing ldap.conf\n");
56     if (ldap_config_valid) {
57         if (ldap_auth_method == LDAP_AUTH_NONE)
58             printf("ldap.conf is ok. Using anonymous bind.\n");
59         else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
60             printf("ldap.conf is ok. Using simple bind.\n");
61         else {
62             ldap_config_valid = 0;
63             printf("ldap.conf want SASL which is not yet supported.\n");        
64         }
65     } else {
66         printf("ldap.conf is not ok.\n");
67         return 1;
68     }
69
70     for (i=1; i+1 <= argc; i++) {
71         if (STRNCMP("-u", == , argv[i], 2)) {
72             printf("Searching uuid: %s\n", argv[i]+2);
73             uuid_string2bin(argv[i]+2, uuid);
74             ret = getnamefromuuid( uuid, &name, &type);
75             if (ret == 0) {
76                 printf("Got user: %s for uuid: %s, type:%d\n", name, argv[i]+2, type);
77                 free(uuidstring);
78             } else
79                 printf("uuid %s not found.\n", argv[i]+2);
80         } else {
81             printf("Searching user: %s\n", argv[i]);
82             ret = getuuidfromname( argv[i], UUID_USER, uuid);
83             if (ret == 0) {
84                 uuid_bin2string( uuid, &uuidstring);
85                 printf("Got uuid: %s for name: %s, type: USER\n", uuidstring, argv[i]);
86                 free(uuidstring);
87             } else {
88                 ret = getuuidfromname( argv[i], UUID_GROUP, uuid);
89                 if (ret == 0) {
90                     uuid_bin2string( uuid, &uuidstring);
91                     printf("Got uuid: %s for name: %s, type: GROUP\n", uuidstring, argv[i]);
92                     free(uuidstring);
93                 }
94                 else
95                     printf("User %s not found.\n", argv[i]);
96             }
97         }
98     }
99
100     return 0;
101 }
102
103 #endif  /* HAVE_NFSv4_ACLS */