]> git.decadent.org.uk Git - nfs-utils.git/blob - tests/statdb_dump.c
mountd: fix exporting of "/" with sec= setting.
[nfs-utils.git] / tests / statdb_dump.c
1 /*
2  * statdb_dump.c -- dump contents of statd's monitor DB
3  *
4  * Copyright (C) 2010  Red Hat, Jeff Layton <jlayton@redhat.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <stdio.h>
27 #include <errno.h>
28 #include <arpa/inet.h>
29
30 #include "nsm.h"
31 #include "xlog.h"
32
33 static char cookiebuf[(SM_PRIV_SIZE * 2) + 1];
34 static char addrbuf[INET6_ADDRSTRLEN + 1];
35
36 static unsigned int
37 dump_host(const char *hostname, const struct sockaddr *sa, const struct mon *m,
38           const time_t timestamp)
39 {
40         int ret;
41         const char *addr;
42         const struct sockaddr_in *sin;
43         const struct sockaddr_in6 *sin6;
44
45         ret = nsm_priv_to_hex(m->priv, cookiebuf, sizeof(cookiebuf));
46         if (!ret) {
47                 xlog(L_ERROR, "Unable to convert cookie to hex string.\n");
48                 return ret;
49         }
50
51         switch (sa->sa_family) {
52         case AF_INET:
53                 sin = (struct sockaddr_in *)(char *)sa;
54                 addr = inet_ntop(sa->sa_family, &sin->sin_addr.s_addr, addrbuf,
55                                  (socklen_t)sizeof(addrbuf));
56                 break;
57         case AF_INET6:
58                 sin6 = (struct sockaddr_in6 *)(char *)sa;
59                 addr = inet_ntop(sa->sa_family, &sin6->sin6_addr, addrbuf,
60                                  (socklen_t)sizeof(addrbuf));
61                 break;
62         default:
63                 xlog(L_ERROR, "Unrecognized address family: %hu\n",
64                         sa->sa_family);
65                 return 0;
66         }
67
68         if (addr == NULL) {
69                 xlog(L_ERROR, "Unable to convert sockaddr to string: %s\n",
70                                 strerror(errno));
71                 return 0;
72         }
73
74         /*
75          * Callers of this program should assume that in the future, extra
76          * fields may be added to the output. Anyone adding extra fields to
77          * the output should add them to the end of the line.
78          */
79         printf("%s %s %s %s %s %d %d %d\n",
80                         hostname, addr, cookiebuf,
81                         m->mon_id.mon_name,
82                         m->mon_id.my_id.my_name,
83                         m->mon_id.my_id.my_prog,
84                         m->mon_id.my_id.my_vers,
85                         m->mon_id.my_id.my_proc); 
86
87         return 1;
88 }
89
90 int
91 main(int argc, char **argv)
92 {
93         xlog_syslog(0);
94         xlog_stderr(1);
95         xlog_open(argv[0]);
96         
97         nsm_load_monitor_list(dump_host);
98         return 0;
99 }