138494Sobrien/*
2174294Sobrien * Copyright (c) 1997-2006 Erez Zadok
338494Sobrien * Copyright (c) 1990 Jan-Simon Pendry
438494Sobrien * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
538494Sobrien * Copyright (c) 1990 The Regents of the University of California.
638494Sobrien * All rights reserved.
738494Sobrien *
838494Sobrien * This code is derived from software contributed to Berkeley by
938494Sobrien * Jan-Simon Pendry at Imperial College, London.
1038494Sobrien *
1138494Sobrien * Redistribution and use in source and binary forms, with or without
1238494Sobrien * modification, are permitted provided that the following conditions
1338494Sobrien * are met:
1438494Sobrien * 1. Redistributions of source code must retain the above copyright
1538494Sobrien *    notice, this list of conditions and the following disclaimer.
1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1738494Sobrien *    notice, this list of conditions and the following disclaimer in the
1838494Sobrien *    documentation and/or other materials provided with the distribution.
1938494Sobrien * 3. All advertising materials mentioning features or use of this software
2042629Sobrien *    must display the following acknowledgment:
2138494Sobrien *      This product includes software developed by the University of
2238494Sobrien *      California, Berkeley and its contributors.
2338494Sobrien * 4. Neither the name of the University nor the names of its contributors
2438494Sobrien *    may be used to endorse or promote products derived from this software
2538494Sobrien *    without specific prior written permission.
2638494Sobrien *
2738494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2838494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2938494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3038494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3138494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3238494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3338494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3438494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3538494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3638494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3738494Sobrien * SUCH DAMAGE.
3838494Sobrien *
3938494Sobrien *
40174294Sobrien * File: am-utils/conf/checkmount/checkmount_bsd44.c
4138494Sobrien *
4238494Sobrien */
4338494Sobrien
4438494Sobrien#ifdef HAVE_CONFIG_H
4538494Sobrien# include <config.h>
4638494Sobrien#endif /* HAVE_CONFIG_H */
4738494Sobrien#include <am_defs.h>
4838494Sobrien
4938494Sobrienextern int is_same_host(char *name1, char *name2, struct in_addr addr2);
5038494Sobrienint fixmount_check_mount(char *host, struct in_addr hostaddr, char *path);
5138494Sobrien
5238494Sobrienint
5338494Sobrienfixmount_check_mount(char *host, struct in_addr hostaddr, char *path)
5438494Sobrien{
5538494Sobrien  struct statfs *mntbufp, *mntp;
5638494Sobrien  int nloc, i;
5738494Sobrien  char *colon;
5838494Sobrien
5938494Sobrien  /* read mount table from kernel */
6038494Sobrien  nloc = getmntinfo(&mntbufp, MNT_NOWAIT);
6138494Sobrien  if (nloc <= 0) {
6238494Sobrien    perror("getmntinfo");
6338494Sobrien    exit(1);
6438494Sobrien  }
6538494Sobrien
6638494Sobrien  mntp = mntbufp;
6738494Sobrien  for (i=0; i<nloc; ++i) {
6838494Sobrien    if ((colon = strchr(mntp->f_mntfromname, ':'))) {
6938494Sobrien      *colon = '\0';
7038494Sobrien      if (STREQ(colon + 1, path) &&
7138494Sobrien	  is_same_host(mntp->f_mntfromname, host, hostaddr))
7238494Sobrien	return 1;
7338494Sobrien    }
7438494Sobrien  }
7538494Sobrien
7638494Sobrien  return 0;
7738494Sobrien}
78