]> arthur.barton.de Git - netatalk.git/blob - contrib/acltests/uuidtest.c
Untabify and reindent
[netatalk.git] / contrib / acltests / uuidtest.c
1 /*
2   $Id: uuidtest.c,v 1.4 2009-11-27 15:50:26 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
31 #define STRNCMP(a, R, b, l) (strncmp(a,b,l) R 0)
32
33 int main( int argc, char **argv)
34 {
35     int ret, i;
36     uuid_t uuid;
37     uuidtype_t type;
38     char *uuidstring = NULL;
39     char *name = NULL;
40
41     if (argc <  2) {
42         printf("Usage: uuidtest <name> | -u<UUID> [<name> ... | -u<UUID> ...] \n");
43         return -1;
44     }
45
46     /* Parse afp_ldap.conf */
47     printf("Start parsing afp_ldap.conf\n");
48     acl_ldap_readconfig(_PATH_ACL_LDAPCONF);
49     printf("Finished parsing afp_ldap.conf\n");
50     if (ldap_config_valid) {
51         if (ldap_auth_method == LDAP_AUTH_NONE)
52             printf("afp_ldap.conf is ok. Using anonymous bind.\n");
53         else if (ldap_auth_method == LDAP_AUTH_SIMPLE)
54             printf("afp_ldap.conf is ok. Using simple bind.\n");
55         else {
56             ldap_config_valid = 0;
57             printf("afp_ldap.conf want SASL which is not yet supported.\n");
58         }
59     } else {
60         printf("afp_ldap.conf is not ok.\n");
61         return 1;
62     }
63
64     for (i=1; i+1 <= argc; i++) {
65         if (STRNCMP("-u", == , argv[i], 2)) {
66             printf("Searching uuid: %s\n", argv[i]+2);
67             uuid_string2bin(argv[i]+2, uuid);
68             ret = getnamefromuuid( uuid, &name, &type);
69             if (ret == 0) {
70                 printf("Got user: %s for uuid: %s, type:%d\n", name, argv[i]+2, type);
71                 free(uuidstring);
72             } else
73                 printf("uuid %s not found.\n", argv[i]+2);
74         } else {
75             printf("Searching user: %s\n", argv[i]);
76             ret = getuuidfromname( argv[i], UUID_USER, uuid);
77             if (ret == 0) {
78                 uuid_bin2string( uuid, &uuidstring);
79                 printf("Got uuid: %s for name: %s, type: USER\n", uuidstring, argv[i]);
80                 free(uuidstring);
81             } else {
82                 ret = getuuidfromname( argv[i], UUID_GROUP, uuid);
83                 if (ret == 0) {
84                     uuid_bin2string( uuid, &uuidstring);
85                     printf("Got uuid: %s for name: %s, type: GROUP\n", uuidstring, argv[i]);
86                     free(uuidstring);
87                 }
88                 else
89                     printf("User %s not found.\n", argv[i]);
90             }
91         }
92     }
93
94     return 0;
95 }
96
97 #endif  /* HAVE_NFSv4_ACLS */