Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / libnfsidmap / libtest.c
blob1c717b81ae905ce99c6eae9d48d6bc756defbbe8
1 /*
2 * libtest.c
4 * nfs idmapping library, primarily for nfs4 client/server kernel idmapping
5 * and for userland nfs4 idmapping by acl libraries.
7 * Copyright (c) 2004 The Regents of the University of Michigan.
8 * All rights reserved.
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * libtest: Test the translation table functions
40 * Reads /etc/idmapd.conf
42 * To compile:
43 * gcc -g libtest.c -lnfsidmap -o libtest
47 #include <stdio.h>
48 #include <string.h>
49 #include <sys/types.h>
50 #include <nfsidmap.h>
52 #define QUIT_ON_ERROR 1
53 #define PATH_IDMAPDCONF "/etc/idmapd.conf"
54 char *conf_path = PATH_IDMAPDCONF;
56 main(int ac, char **av)
58 char *name, *princ;
59 int err, uid = 0, gid = 0;
60 char name_buf[32];
61 int gids[1000];
62 int i, ngids;
64 if (ac != 3) {
65 printf("Usage: %s <user@nfsv4domain> <k5princ@REALM>\n",av[0]);
66 return 1;
69 nfs4_set_debug(3, NULL);
71 name = av[1];
72 princ = av[2];
73 err = nfs4_init_name_mapping(NULL);
74 if (err) {
75 printf("nfs4_init_name_mapping: error %d\n", err);
76 return 1;
79 err = nfs4_gss_princ_to_ids("krb5", princ, &uid, &gid);
80 if (err)
81 printf("nfs4_gss_princ_to_ids: error %d\n", err);
82 else
83 printf("nfs4_gss_princ_to_ids: princ %s has uid %d gid %d\n",
84 princ, uid, gid);
85 #if QUIT_ON_ERROR
86 if (err) {
87 printf("calling it quits!\n");
88 return err;
90 #endif
92 err = nfs4_name_to_uid(name, &uid);
93 if (err)
94 printf("nfs4_name_to_uid: error %d\n", err);
95 else
96 printf("nfs4_name_to_uid: name %s has uid %d\n",
97 name, uid);
99 #if QUIT_ON_ERROR
100 if (err) {
101 printf("calling it quits!\n");
102 return err;
104 #endif
105 err = nfs4_name_to_gid(name, &gid);
106 if (err)
107 printf("nfs4_name_to_gid: error %d\n", err);
108 else
109 printf("nfs4_name_to_gid: name %s has gid %d\n",
110 name, gid);
112 ngids = 1000;
113 err = nfs4_gss_princ_to_grouplist("krb5", princ, gids, &ngids);
114 if (err){
115 printf(" nfs4_gss_princ_to_grouplist: error %d\n", err);
116 } else {
117 printf(" nfs4_gss_princ_to_grouplist: princ %s has gids ",
118 princ);
119 for (i = 0; i < ngids; i++) printf("%d ", gids[i]);
120 printf("\n");
123 #if QUIT_ON_ERROR
124 if (err) {
125 printf("calling it quits!\n");
126 return err;
128 #endif
129 /* uid is set by nfs4_name_to_uid() */
130 memset(name_buf, 0, 32);
131 err = nfs4_uid_to_name(uid, NULL, name_buf, 32);
132 if (err)
133 printf("nfs4_uid_to_name: error %d\n", err);
134 else
135 printf("nfs4_uid_to_name: uid %d has name %s\n",
136 uid, name_buf);
138 #if QUIT_ON_ERROR
139 if (err) {
140 printf("calling it quits!\n");
141 return err;
143 #endif
144 /* gid is set by nfs4_name_to_gid() */
145 memset(name_buf, 0, 32);
146 err = nfs4_gid_to_name(gid, NULL, name_buf, 32);
147 if (err)
148 printf("nfs4_gid_to_name: error %d\n", err);
149 else
150 printf("nfs4_gid_to_name: gid %d has name %s\n",
151 gid, name_buf);
153 #if QUIT_ON_ERROR
154 if (err) {
155 printf("calling it quits!\n");
156 return err;
158 #endif
159 return 0;