#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/rpc.h>
#include <rpc/rpcb_clnt.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/time.h>
#include <errno.h>
#include <nfs/nfs.h>
#include <rpcsvc/mount.h>
#include <unistd.h>
#include <clnt_subr.h>
int hflg;
void pr_exports(char *);
void free_ex(struct exportnode *);
void usage(void);
int
main(int argc, char *argv[])
{
char hostbuf[256];
int i, c;
while ((c = getopt(argc, argv, "h")) != EOF) {
switch (c) {
case 'h':
hflg++;
break;
default:
usage();
exit(1);
}
}
if (optind < argc) {
for (i = optind; i < argc; i++)
pr_exports(argv[i]);
} else {
if (gethostname(hostbuf, sizeof (hostbuf)) < 0) {
pr_err("gethostname: %s\n", strerror(errno));
exit(1);
}
pr_exports(hostbuf);
}
return (0);
}
struct timeval rpc_totout_new = {15, 0};
void
pr_exports(char *host)
{
CLIENT *cl;
struct exportnode *ex = NULL;
enum clnt_stat err;
struct timeval tout, rpc_totout_old;
(void) __rpc_control(CLCR_GET_RPCB_TIMEOUT, &rpc_totout_old);
(void) __rpc_control(CLCR_SET_RPCB_TIMEOUT, &rpc_totout_new);
cl = mountprog_client_create(host, &rpc_totout_old);
if (cl == NULL) {
exit(1);
}
(void) __rpc_control(CLCR_SET_RPCB_TIMEOUT, &rpc_totout_old);
tout.tv_sec = 10;
tout.tv_usec = 0;
err = clnt_call(cl, MOUNTPROC_EXPORT, xdr_void, 0, xdr_exports,
(caddr_t)&ex, tout);
if (err != 0) {
pr_err("%s\n", clnt_sperrno(err));
clnt_destroy(cl);
exit(1);
}
if (ex == NULL) {
clnt_destroy(cl);
exit(1);
}
if (!hflg) {
printf("%-35s %12s %-8s %s\n",
"RESOURCE", "SERVER", "ACCESS", "TRANSPORT");
hflg++;
}
while (ex) {
printf("%10s:%-24s %12s %-8s %s\n",
host, ex->ex_dir, host, " -", " -");
ex = ex->ex_next;
}
free_ex(ex);
clnt_destroy(cl);
}
void
free_ex(struct exportnode *ex)
{
struct groupnode *gr, *tmpgr;
struct exportnode *tmpex;
while (ex) {
free(ex->ex_dir);
gr = ex->ex_groups;
while (gr) {
tmpgr = gr->gr_next;
free(gr);
gr = tmpgr;
}
tmpex = ex;
ex = ex->ex_next;
free(tmpex);
}
}
void
usage(void)
{
(void) fprintf(stderr, "Usage: dfshares [-h] [host ...]\n");
}
void
pr_err(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
(void) fprintf(stderr, "nfs dfshares: ");
(void) vfprintf(stderr, fmt, ap);
va_end(ap);
}