xref: /netbsd-src/external/bsd/am-utils/dist/conf/checkmount/checkmount_aix.c (revision 8bae5d409deb915cf7c8f0539fae22ff2cb8a313)
1*8bae5d40Schristos /*	$NetBSD: checkmount_aix.c,v 1.1.1.3 2015/01/17 16:34:16 christos Exp $	*/
2a53f50b9Schristos 
3a53f50b9Schristos /*
4*8bae5d40Schristos  * Copyright (c) 1997-2014 Erez Zadok
5a53f50b9Schristos  * Copyright (c) 1990 Jan-Simon Pendry
6a53f50b9Schristos  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7a53f50b9Schristos  * Copyright (c) 1990 The Regents of the University of California.
8a53f50b9Schristos  * All rights reserved.
9a53f50b9Schristos  *
10a53f50b9Schristos  * This code is derived from software contributed to Berkeley by
11a53f50b9Schristos  * Jan-Simon Pendry at Imperial College, London.
12a53f50b9Schristos  *
13a53f50b9Schristos  * Redistribution and use in source and binary forms, with or without
14a53f50b9Schristos  * modification, are permitted provided that the following conditions
15a53f50b9Schristos  * are met:
16a53f50b9Schristos  * 1. Redistributions of source code must retain the above copyright
17a53f50b9Schristos  *    notice, this list of conditions and the following disclaimer.
18a53f50b9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
19a53f50b9Schristos  *    notice, this list of conditions and the following disclaimer in the
20a53f50b9Schristos  *    documentation and/or other materials provided with the distribution.
21*8bae5d40Schristos  * 3. Neither the name of the University nor the names of its contributors
22a53f50b9Schristos  *    may be used to endorse or promote products derived from this software
23a53f50b9Schristos  *    without specific prior written permission.
24a53f50b9Schristos  *
25a53f50b9Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26a53f50b9Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27a53f50b9Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28a53f50b9Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29a53f50b9Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30a53f50b9Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31a53f50b9Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32a53f50b9Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33a53f50b9Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34a53f50b9Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35a53f50b9Schristos  * SUCH DAMAGE.
36a53f50b9Schristos  *
37a53f50b9Schristos  *
38a53f50b9Schristos  * File: am-utils/conf/checkmount/checkmount_aix.c
39a53f50b9Schristos  *
40a53f50b9Schristos  */
41a53f50b9Schristos 
42a53f50b9Schristos #ifdef HAVE_CONFIG_H
43a53f50b9Schristos # include <config.h>
44a53f50b9Schristos #endif /* HAVE_CONFIG_H */
45a53f50b9Schristos #include <am_defs.h>
46a53f50b9Schristos 
47a53f50b9Schristos 
48a53f50b9Schristos /*
49a53f50b9Schristos  * These were missing external definitions from old AIX's headers.  They
50a53f50b9Schristos  * appear to be available in <sys/vmount.h> on AIX 5.3, and possibly
51a53f50b9Schristos  * earlier. Hence I commented this out.
52a53f50b9Schristos  */
53a53f50b9Schristos #ifndef HAVE_EXTERN_MNTCTL
54a53f50b9Schristos extern int mntctl(int cmd, int size, voidp buf);
55a53f50b9Schristos #endif /* not HAVE_EXTERN_MNTCTL */
56a53f50b9Schristos extern int is_same_host(char *name1, char *name2, struct in_addr addr2);
57a53f50b9Schristos 
58a53f50b9Schristos 
59a53f50b9Schristos int
fixmount_check_mount(char * host,struct in_addr hostaddr,char * path)60a53f50b9Schristos fixmount_check_mount(char *host, struct in_addr hostaddr, char *path)
61a53f50b9Schristos {
62a53f50b9Schristos   int ret, i;
63a53f50b9Schristos   char *mntinfo = NULL, *cp;
64a53f50b9Schristos   char *short_hostname, *long_hostname, *mount_point;
65a53f50b9Schristos   struct vmount *vp;
66a53f50b9Schristos 
67a53f50b9Schristos   /*
68a53f50b9Schristos    * First figure out size of mount table and allocate space for a copy...
69a53f50b9Schristos    * Then get mount table for real.
70a53f50b9Schristos    */
71a53f50b9Schristos   ret = mntctl(MCTL_QUERY, sizeof(i), (char *) &i);
72a53f50b9Schristos   if (ret == 0) {
73a53f50b9Schristos     mntinfo = xmalloc(i);
74a53f50b9Schristos     ret = mntctl(MCTL_QUERY, i, mntinfo);
75a53f50b9Schristos   }
76a53f50b9Schristos   if (ret <= 0) {
77a53f50b9Schristos     fprintf(stderr, "mntctl: %m");
78a53f50b9Schristos     XFREE(mntinfo);
79a53f50b9Schristos     exit(1);
80a53f50b9Schristos   }
81a53f50b9Schristos 
82a53f50b9Schristos   /* iterate over each vmount structure */
83a53f50b9Schristos   for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) {
84a53f50b9Schristos     vp = (struct vmount *) cp;
85a53f50b9Schristos     mount_point = vmt2dataptr(vp, VMT_STUB);
86a53f50b9Schristos     long_hostname = vmt2dataptr(vp, VMT_HOSTNAME);
87a53f50b9Schristos     short_hostname = vmt2dataptr(vp, VMT_HOST);
88a53f50b9Schristos     if (STREQ(path, mount_point) &&
89a53f50b9Schristos 	(is_same_host(long_hostname, host, hostaddr) ||
90a53f50b9Schristos 	 is_same_host(short_hostname, host, hostaddr)))
91a53f50b9Schristos       return 1;
92a53f50b9Schristos   }
93a53f50b9Schristos 
94a53f50b9Schristos   return 0;
95a53f50b9Schristos }
96