BSD 4.4 Lite usr.sbin Sources

This commit is contained in:
Rodney W. Grimes 1994-05-26 05:23:31 +00:00
parent 40a845cd5b
commit dea673e932
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/WIN_TUE_NL/; revision=1553
657 changed files with 183029 additions and 0 deletions

122
lib/libc/gen/pw_scan.c Normal file
View file

@ -0,0 +1,122 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)pw_scan.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
/*
* This module is used to "verify" password entries by chpass(1) and
* pwd_mkdb(8).
*/
#include <sys/param.h>
#include <err.h>
#include <fcntl.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "pw_scan.h"
int
pw_scan(bp, pw)
char *bp;
struct passwd *pw;
{
long id;
int root;
char *p, *sh;
if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
goto fmt;
root = !strcmp(pw->pw_name, "root");
if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
goto fmt;
if (!(p = strsep(&bp, ":"))) /* uid */
goto fmt;
id = atol(p);
if (root && id) {
warnx("root uid should be 0");
return (0);
}
if (id > USHRT_MAX) {
warnx("%s > max uid value (%d)", p, USHRT_MAX);
return (0);
}
pw->pw_uid = id;
if (!(p = strsep(&bp, ":"))) /* gid */
goto fmt;
id = atol(p);
if (id > USHRT_MAX) {
warnx("%s > max gid value (%d)", p, USHRT_MAX);
return (0);
}
pw->pw_gid = id;
pw->pw_class = strsep(&bp, ":"); /* class */
if (!(p = strsep(&bp, ":"))) /* change */
goto fmt;
pw->pw_change = atol(p);
if (!(p = strsep(&bp, ":"))) /* expire */
goto fmt;
pw->pw_expire = atol(p);
pw->pw_gecos = strsep(&bp, ":"); /* gecos */
pw->pw_dir = strsep(&bp, ":"); /* directory */
if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
goto fmt;
p = pw->pw_shell;
if (root && *p) /* empty == /bin/sh */
for (setusershell();;) {
if (!(sh = getusershell())) {
warnx("warning, unknown root shell");
break;
}
if (!strcmp(p, sh))
break;
}
if (p = strsep(&bp, ":")) { /* too many */
fmt: warnx("corrupted entry");
return (0);
}
return (1);
}

36
lib/libc/gen/pw_scan.h Normal file
View file

@ -0,0 +1,36 @@
/*-
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pw_scan.h 8.1 (Berkeley) 4/1/94
*/
extern int pw_scan __P((char *, struct passwd *));

204
lib/libutil/pw_util.c Normal file
View file

@ -0,0 +1,204 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
/*
* This file is used by all the "password" programs; vipw(8), chpass(1),
* and passwd(1).
*/
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pw_util.h"
extern char *tempname;
void
pw_init()
{
struct rlimit rlim;
/* Unlimited resource limits. */
rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
(void)setrlimit(RLIMIT_CPU, &rlim);
(void)setrlimit(RLIMIT_FSIZE, &rlim);
(void)setrlimit(RLIMIT_STACK, &rlim);
(void)setrlimit(RLIMIT_DATA, &rlim);
(void)setrlimit(RLIMIT_RSS, &rlim);
/* Don't drop core (not really necessary, but GP's). */
rlim.rlim_cur = rlim.rlim_max = 0;
(void)setrlimit(RLIMIT_CORE, &rlim);
/* Turn off signals. */
(void)signal(SIGALRM, SIG_IGN);
(void)signal(SIGHUP, SIG_IGN);
(void)signal(SIGINT, SIG_IGN);
(void)signal(SIGPIPE, SIG_IGN);
(void)signal(SIGQUIT, SIG_IGN);
(void)signal(SIGTERM, SIG_IGN);
(void)signal(SIGTSTP, SIG_IGN);
(void)signal(SIGTTOU, SIG_IGN);
/* Create with exact permissions. */
(void)umask(0);
}
static int lockfd;
int
pw_lock()
{
/*
* If the master password file doesn't exist, the system is hosed.
* Might as well try to build one. Set the close-on-exec bit so
* that users can't get at the encrypted passwords while editing.
* Open should allow flock'ing the file; see 4.4BSD. XXX
*/
lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
err(1, "%s", _PATH_MASTERPASSWD);
if (flock(lockfd, LOCK_EX|LOCK_NB))
errx(1, "the password db file is busy");
return (lockfd);
}
int
pw_tmp()
{
static char path[MAXPATHLEN] = _PATH_MASTERPASSWD;
int fd;
char *p;
if (p = strrchr(path, '/'))
++p;
else
p = path;
strcpy(p, "pw.XXXXXX");
if ((fd = mkstemp(path)) == -1)
err(1, "%s", path);
tempname = path;
return (fd);
}
int
pw_mkdb()
{
int pstat;
pid_t pid;
warnx("rebuilding the database...");
(void)fflush(stderr);
if (!(pid = vfork())) {
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL);
pw_error(_PATH_PWD_MKDB, 1, 1);
}
pid = waitpid(pid, &pstat, 0);
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
return (0);
warnx("done");
return (1);
}
void
pw_edit(notsetuid)
int notsetuid;
{
int pstat;
pid_t pid;
char *p, *editor;
if (!(editor = getenv("EDITOR")))
editor = _PATH_VI;
if (p = strrchr(editor, '/'))
++p;
else
p = editor;
if (!(pid = vfork())) {
if (notsetuid) {
(void)setgid(getgid());
(void)setuid(getuid());
}
execlp(editor, p, tempname, NULL);
_exit(1);
}
pid = waitpid(pid, (int *)&pstat, 0);
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
pw_error(editor, 1, 1);
}
void
pw_prompt()
{
int c;
(void)printf("re-edit the password file? [y]: ");
(void)fflush(stdout);
c = getchar();
if (c != EOF && c != '\n')
while (getchar() != '\n');
if (c == 'n')
pw_error(NULL, 0, 0);
}
void
pw_error(name, err, eval)
char *name;
int err, eval;
{
if (err)
warn(name);
warnx("%s: unchanged", _PATH_MASTERPASSWD);
(void)unlink(tempname);
exit(eval);
}

6
sbin/sysctl/Makefile Normal file
View file

@ -0,0 +1,6 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= sysctl
MAN8= sysctl.0
.include <bsd.prog.mk>

229
sbin/sysctl/pathconf.c Normal file
View file

@ -0,0 +1,229 @@
/*
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)pathconf.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PC_NAMES { \
{ 0, 0 }, \
{ "link_max", CTLTYPE_INT }, \
{ "max_canon", CTLTYPE_INT }, \
{ "max_input", CTLTYPE_INT }, \
{ "name_max", CTLTYPE_INT }, \
{ "path_max", CTLTYPE_INT }, \
{ "pipe_buf", CTLTYPE_INT }, \
{ "chown_restricted", CTLTYPE_INT }, \
{ "no_trunc", CTLTYPE_INT }, \
{ "vdisable", CTLTYPE_INT }, \
}
#define PC_MAXID 10
struct ctlname pcnames[] = PC_NAMES;
char names[BUFSIZ];
struct list {
struct ctlname *list;
int size;
};
struct list pclist = { pcnames, PC_MAXID };
int Aflag, aflag, nflag, wflag, stdinflag;
int
main(argc, argv)
int argc;
char *argv[];
{
extern char *optarg;
extern int optind;
char *path;
int ch;
while ((ch = getopt(argc, argv, "Aan")) != EOF) {
switch (ch) {
case 'A':
Aflag = 1;
break;
case 'a':
aflag = 1;
break;
case 'n':
nflag = 1;
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc == 0)
usage();
path = *argv++;
if (strcmp(path, "-") == 0)
stdinflag = 1;
argc--;
if (Aflag || aflag) {
listall(path, &pclist);
exit(0);
}
if (argc == 0)
usage();
while (argc-- > 0)
parse(path, *argv, 1);
exit(0);
}
/*
* List all variables known to the system.
*/
listall(path, lp)
char *path;
struct list *lp;
{
int lvl2;
if (lp->list == 0)
return;
for (lvl2 = 0; lvl2 < lp->size; lvl2++) {
if (lp->list[lvl2].ctl_name == 0)
continue;
parse(path, lp->list[lvl2].ctl_name, Aflag);
}
}
/*
* Parse a name into an index.
* Lookup and print out the attribute if it exists.
*/
parse(pathname, string, flags)
char *pathname;
char *string;
int flags;
{
int indx, value;
char *bufp, buf[BUFSIZ];
bufp = buf;
snprintf(buf, BUFSIZ, "%s", string);
if ((indx = findname(string, "top", &bufp, &pclist)) == -1)
return;
if (bufp) {
fprintf(stderr, "name %s in %s is unknown\n", *bufp, string);
return;
}
if (stdinflag)
value = fpathconf(0, indx);
else
value = pathconf(pathname, indx);
if (value == -1) {
if (flags == 0)
return;
switch (errno) {
case EOPNOTSUPP:
fprintf(stderr, "%s: value is not available\n", string);
return;
case ENOTDIR:
fprintf(stderr, "%s: specification is incomplete\n",
string);
return;
case ENOMEM:
fprintf(stderr, "%s: type is unknown to this program\n",
string);
return;
default:
perror(string);
return;
}
}
if (!nflag)
fprintf(stdout, "%s = ", string);
fprintf(stdout, "%d\n", value);
}
/*
* Scan a list of names searching for a particular name.
*/
findname(string, level, bufp, namelist)
char *string;
char *level;
char **bufp;
struct list *namelist;
{
char *name;
int i;
if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) {
fprintf(stderr, "%s: incomplete specification\n", string);
return (-1);
}
for (i = 0; i < namelist->size; i++)
if (namelist->list[i].ctl_name != NULL &&
strcmp(name, namelist->list[i].ctl_name) == 0)
break;
if (i == namelist->size) {
fprintf(stderr, "%s level name %s in %s is invalid\n",
level, name, string);
return (-1);
}
return (i);
}
usage()
{
(void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n",
"pathname [-n] variable ...",
"pathname [-n] -a", "pathname [-n] -A");
exit(1);
}

208
sbin/sysctl/sysctl.8 Normal file
View file

@ -0,0 +1,208 @@
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)sysctl.8 8.1 (Berkeley) 6/6/93
.\"
.Dd "June 6, 1993"
.Dt SYSCTL 8
.Os
.Sh NAME
.Nm sysctl
.Nd get or set kernel state
.Sh SYNOPSIS
.Nm sysctl
.Op Fl n
.Ar name ...
.Nm sysctl
.Op Fl n
.Fl w
.Ar name=value ...
.Nm sysctl
.Op Fl n
.Fl aA
.Sh DESCRIPTION
The
.Nm sysctl
utility retrieves kernel state and allows processes with
appropriate privilege to set kernel state.
The state to be retrieved or set is described using a
``Management Information Base'' (``MIB'') style name,
described as a dotted set of components.
The
.Fl a
flag can be used to list all the currently available string or integer values.
The
.Fl A
flag will list all the known MIB names including tables.
Those with string or integer values will be printed as with the
.Fl a
flag; for the table values,
the name of the utility to retrieve them is given.
.Pp
The
.Fl n
flag specifies that the printing of the field name should be
suppressed and that only its value should be output.
This flag is useful for setting shell variables.
For example, to save the pagesize in variable psize, use:
.Bd -literal -offset indent -compact
set psize=`sysctl -n hw.pagesize`
.Ed
.Pp
If just a MIB style name is given,
the corresponding value is retrieved.
If a value is to be set, the
.Fl w
flag must be specified and the MIB name followed
by an equal sign and the new value to be used.
.Pp
The information available from
.Nm sysctl
consists of integers, strings, and tables.
The tabular information can only be retrieved by special
purpose programs such as
.Nm ps ,
.Nm systat ,
and
.Nm netstat .
The string and integer information is summaried below.
For a detailed description of these variable see
.Xr sysctl 3 .
The changeable column indicates whether a process with appropriate
privilege can change the value.
.Bl -column net.inet.ip.forwardingxxxxxx integerxxx
.It Sy Name Type Changeable
.It kern.ostype string no
.It kern.osrelease string no
.It kern.osrevision integer no
.It kern.version string no
.It kern.maxvnodes integer yes
.It kern.maxproc integer yes
.It kern.maxfiles integer yes
.It kern.argmax integer no
.It kern.securelevel integer raise only
.It kern.hostname string yes
.It kern.hostid integer yes
.It kern.clockrate struct no
.It kern.posix1version integer no
.It kern.ngroups integer no
.It kern.job_control integer no
.It kern.saved_ids integer no
.It kern.link_max integer no
.It kern.max_canon integer no
.It kern.max_input integer no
.It kern.name_max integer no
.It kern.path_max integer no
.It kern.pipe_buf integer no
.It kern.chown_restricted integer no
.It kern.no_trunc integer no
.It kern.vdisable integer no
.It kern.boottime struct no
.It vm.loadavg struct no
.It machdep.console_device dev_t no
.It net.inet.ip.forwarding integer yes
.It net.inet.ip.redirect integer yes
.It net.inet.ip.ttl integer yes
.It net.inet.icmp.maskrepl integer yes
.It net.inet.udp.checksum integer yes
.It hw.machine string no
.It hw.model string no
.It hw.ncpu integer no
.It hw.byteorder integer no
.It hw.physmem integer no
.It hw.usermem integer no
.It hw.pagesize integer no
.It user.cs_path string no
.It user.bc_base_max integer no
.It user.bc_dim_max integer no
.It user.bc_scale_max integer no
.It user.bc_string_max integer no
.It user.coll_weights_max integer no
.It user.expr_nest_max integer no
.It user.line_max integer no
.It user.re_dup_max integer no
.It user.posix2_version integer no
.It user.posix2_c_bind integer no
.It user.posix2_c_dev integer no
.It user.posix2_char_term integer no
.It user.posix2_fort_dev integer no
.It user.posix2_fort_run integer no
.It user.posix2_localedef integer no
.It user.posix2_sw_dev integer no
.It user.posix2_upe integer no
.El
.Sh EXAMPLES
.Pp
For example, to retrieve the maximum number of processes allowed
in the system, one would use the follow request:
.Bd -literal -offset indent -compact
sysctl kern.maxproc
.Ed
.Pp
To set the maximum number of processes allowed
in the system to 1000, one would use the follow request:
.Bd -literal -offset indent -compact
sysctl -w kern.maxproc=1000
.Ed
.Pp
Information about the system clock rate may be obtained with:
.Bd -literal -offset indent -compact
sysctl kern.clockrate
.Ed
.Pp
Information about the load average history may be obtained with
.Bd -literal -offset indent -compact
sysctl vm.loadavg
.Ed
.Sh FILES
.Bl -tag -width <netinet/icmpXvar.h> -compact
.It Pa <sys/sysctl.h>
definitions for top level identifiers, second level kernel and hardware
identifiers, and user level identifiers
.It Pa <sys/socket.h>
definitions for second level network identifiers
.It Pa <sys/gmon.h>
definitions for third level profiling identifiers
.It Pa <vm/vm_param.h>
definitions for second level virtual memory identifiers
.It Pa <netinet/in.h>
definitions for third level Internet identifiers and
fourth level IP identifiers
.It Pa <netinet/icmp_var.h>
definitions for fourth level ICMP identifiers
.It Pa <netinet/udp_var.h>
definitions for fourth level UDP identifiers
.El
.Sh SEE ALSO
.Xr sysctl 3
.Sh HISTORY
.Nm sysctl
first appeared in 4.4BSD.

572
sbin/sysctl/sysctl.c Normal file
View file

@ -0,0 +1,572 @@
/*
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/param.h>
#include <sys/gmon.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <vm/vm_param.h>
#include <machine/cpu.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp_var.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct ctlname topname[] = CTL_NAMES;
struct ctlname kernname[] = CTL_KERN_NAMES;
struct ctlname vmname[] = CTL_VM_NAMES;
struct ctlname netname[] = CTL_NET_NAMES;
struct ctlname hwname[] = CTL_HW_NAMES;
struct ctlname username[] = CTL_USER_NAMES;
struct ctlname debugname[CTL_DEBUG_MAXID];
#ifdef CTL_MACHDEP_NAMES
struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
#endif
char names[BUFSIZ];
struct list {
struct ctlname *list;
int size;
};
struct list toplist = { topname, CTL_MAXID };
struct list secondlevel[] = {
{ 0, 0 }, /* CTL_UNSPEC */
{ kernname, KERN_MAXID }, /* CTL_KERN */
{ vmname, VM_MAXID }, /* CTL_VM */
{ 0, 0 }, /* CTL_FS */
{ netname, NET_MAXID }, /* CTL_NET */
{ 0, CTL_DEBUG_MAXID }, /* CTL_DEBUG */
{ hwname, HW_MAXID }, /* CTL_HW */
#ifdef CTL_MACHDEP_NAMES
{ machdepname, CPU_MAXID }, /* CTL_MACHDEP */
#else
{ 0, 0 }, /* CTL_MACHDEP */
#endif
{ username, USER_MAXID }, /* CTL_USER_NAMES */
};
int Aflag, aflag, nflag, wflag;
/*
* Variables requiring special processing.
*/
#define CLOCK 0x00000001
#define BOOTTIME 0x00000002
#define CONSDEV 0x00000004
int
main(argc, argv)
int argc;
char *argv[];
{
extern char *optarg;
extern int optind;
int ch, lvl1;
while ((ch = getopt(argc, argv, "Aanw")) != EOF) {
switch (ch) {
case 'A':
Aflag = 1;
break;
case 'a':
aflag = 1;
break;
case 'n':
nflag = 1;
break;
case 'w':
wflag = 1;
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (Aflag || aflag) {
debuginit();
for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
exit(0);
}
if (argc == 0)
usage();
while (argc-- > 0)
parse(*argv, 1);
exit(0);
}
/*
* List all variables known to the system.
*/
listall(prefix, lp)
char *prefix;
struct list *lp;
{
int lvl2;
char *cp, name[BUFSIZ];
if (lp->list == 0)
return;
strcpy(name, prefix);
cp = &name[strlen(name)];
*cp++ = '.';
for (lvl2 = 0; lvl2 < lp->size; lvl2++) {
if (lp->list[lvl2].ctl_name == 0)
continue;
strcpy(cp, lp->list[lvl2].ctl_name);
parse(name, Aflag);
}
}
/*
* Parse a name into a MIB entry.
* Lookup and print out the MIB entry if it exists.
* Set a new value if requested.
*/
parse(string, flags)
char *string;
int flags;
{
int indx, type, state, size, len;
int special = 0;
void *newval = 0;
int intval, newsize = 0;
quad_t quadval;
struct list *lp;
int mib[CTL_MAXNAME];
char *cp, *bufp, buf[BUFSIZ], strval[BUFSIZ];
bufp = buf;
snprintf(buf, BUFSIZ, "%s", string);
if ((cp = strchr(string, '=')) != NULL) {
if (!wflag) {
fprintf(stderr, "Must specify -w to set variables\n");
exit(2);
}
*strchr(buf, '=') = '\0';
*cp++ = '\0';
while (isspace(*cp))
cp++;
newval = cp;
newsize = strlen(cp);
}
if ((indx = findname(string, "top", &bufp, &toplist)) == -1)
return;
mib[0] = indx;
if (indx == CTL_DEBUG)
debuginit();
lp = &secondlevel[indx];
if (lp->list == 0) {
fprintf(stderr, "%s: class is not implemented\n",
topname[indx]);
return;
}
if (bufp == NULL) {
listall(topname[indx].ctl_name, lp);
return;
}
if ((indx = findname(string, "second", &bufp, lp)) == -1)
return;
mib[1] = indx;
type = lp->list[indx].ctl_type;
len = 2;
switch (mib[0]) {
case CTL_KERN:
switch (mib[1]) {
case KERN_PROF:
mib[2] = GPROF_STATE;
size = sizeof state;
if (sysctl(mib, 3, &state, &size, NULL, 0) < 0) {
if (flags == 0)
return;
if (!nflag)
fprintf(stdout, "%s: ", string);
fprintf(stderr,
"kernel is not compiled for profiling\n");
return;
}
if (!nflag)
fprintf(stdout, "%s: %s\n", string,
state == GMON_PROF_OFF ? "off" : "running");
return;
case KERN_VNODE:
case KERN_FILE:
if (flags == 0)
return;
fprintf(stderr,
"Use pstat to view %s information\n", string);
return;
case KERN_PROC:
if (flags == 0)
return;
fprintf(stderr,
"Use ps to view %s information\n", string);
return;
case KERN_CLOCKRATE:
special |= CLOCK;
break;
case KERN_BOOTTIME:
special |= BOOTTIME;
break;
}
break;
case CTL_HW:
break;
case CTL_VM:
if (mib[1] == VM_LOADAVG) {
double loads[3];
getloadavg(loads, 3);
if (!nflag)
fprintf(stdout, "%s: ", string);
fprintf(stdout, "%.2f %.2f %.2f\n",
loads[0], loads[1], loads[2]);
return;
}
if (flags == 0)
return;
fprintf(stderr,
"Use vmstat or systat to view %s information\n", string);
return;
case CTL_NET:
if (mib[1] == PF_INET) {
len = sysctl_inet(string, &bufp, mib, flags, &type);
if (len >= 0)
break;
return;
}
if (flags == 0)
return;
fprintf(stderr, "Use netstat to view %s information\n", string);
return;
case CTL_DEBUG:
mib[2] = CTL_DEBUG_VALUE;
len = 3;
break;
case CTL_MACHDEP:
#ifdef CPU_CONSDEV
if (mib[1] == CPU_CONSDEV)
special |= CONSDEV;
#endif
break;
case CTL_FS:
case CTL_USER:
break;
default:
fprintf(stderr, "Illegal top level value: %d\n", mib[0]);
return;
}
if (bufp) {
fprintf(stderr, "name %s in %s is unknown\n", *bufp, string);
return;
}
if (newsize > 0) {
switch (type) {
case CTLTYPE_INT:
intval = atoi(newval);
newval = &intval;
newsize = sizeof intval;
break;
case CTLTYPE_QUAD:
sscanf(newval, "%qd", &quadval);
newval = &quadval;
newsize = sizeof quadval;
break;
}
}
size = BUFSIZ;
if (sysctl(mib, len, buf, &size, newsize ? newval : 0, newsize) == -1) {
if (flags == 0)
return;
switch (errno) {
case EOPNOTSUPP:
fprintf(stderr, "%s: value is not available\n", string);
return;
case ENOTDIR:
fprintf(stderr, "%s: specification is incomplete\n",
string);
return;
case ENOMEM:
fprintf(stderr, "%s: type is unknown to this program\n",
string);
return;
default:
perror(string);
return;
}
}
if (special & CLOCK) {
struct clockinfo *clkp = (struct clockinfo *)buf;
if (!nflag)
fprintf(stdout, "%s: ", string);
fprintf(stdout,
"hz = %d, tick = %d, profhz = %d, stathz = %d\n",
clkp->hz, clkp->tick, clkp->profhz, clkp->stathz);
return;
}
if (special & BOOTTIME) {
struct timeval *btp = (struct timeval *)buf;
if (!nflag)
fprintf(stdout, "%s = %s\n", string,
ctime(&btp->tv_sec));
else
fprintf(stdout, "%d\n", btp->tv_sec);
return;
}
if (special & CONSDEV) {
dev_t dev = *(dev_t *)buf;
if (!nflag)
fprintf(stdout, "%s = %s\n", string,
devname(dev, S_IFCHR));
else
fprintf(stdout, "0x%x\n", dev);
return;
}
switch (type) {
case CTLTYPE_INT:
if (newsize == 0) {
if (!nflag)
fprintf(stdout, "%s = ", string);
fprintf(stdout, "%d\n", *(int *)buf);
} else {
if (!nflag)
fprintf(stdout, "%s: %d -> ", string,
*(int *)buf);
fprintf(stdout, "%d\n", *(int *)newval);
}
return;
case CTLTYPE_STRING:
if (newsize == 0) {
if (!nflag)
fprintf(stdout, "%s = ", string);
fprintf(stdout, "%s\n", buf);
} else {
if (!nflag)
fprintf(stdout, "%s: %s -> ", string, buf);
fprintf(stdout, "%s\n", newval);
}
return;
case CTLTYPE_QUAD:
if (newsize == 0) {
if (!nflag)
fprintf(stdout, "%s = ", string);
fprintf(stdout, "%qd\n", *(quad_t *)buf);
} else {
if (!nflag)
fprintf(stdout, "%s: %qd -> ", string,
*(quad_t *)buf);
fprintf(stdout, "%qd\n", *(quad_t *)newval);
}
return;
case CTLTYPE_STRUCT:
fprintf(stderr, "%s: unknown structure returned\n",
string);
return;
default:
case CTLTYPE_NODE:
fprintf(stderr, "%s: unknown type returned\n",
string);
return;
}
}
/*
* Initialize the set of debugging names
*/
debuginit()
{
int mib[3], size, loc, i;
if (secondlevel[CTL_DEBUG].list != 0)
return;
secondlevel[CTL_DEBUG].list = debugname;
mib[0] = CTL_DEBUG;
mib[2] = CTL_DEBUG_NAME;
for (loc = 0, i = 0; i < CTL_DEBUG_MAXID; i++) {
mib[1] = i;
size = BUFSIZ - loc;
if (sysctl(mib, 3, &names[loc], &size, NULL, 0) == -1)
continue;
debugname[i].ctl_name = &names[loc];
debugname[i].ctl_type = CTLTYPE_INT;
loc += size;
}
}
struct ctlname inetname[] = CTL_IPPROTO_NAMES;
struct ctlname ipname[] = IPCTL_NAMES;
struct ctlname icmpname[] = ICMPCTL_NAMES;
struct ctlname udpname[] = UDPCTL_NAMES;
struct list inetlist = { inetname, IPPROTO_MAXID };
struct list inetvars[] = {
{ ipname, IPCTL_MAXID }, /* ip */
{ icmpname, ICMPCTL_MAXID }, /* icmp */
{ 0, 0 }, /* igmp */
{ 0, 0 }, /* ggmp */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 }, /* tcp */
{ 0, 0 },
{ 0, 0 }, /* egp */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 }, /* pup */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ udpname, UDPCTL_MAXID }, /* udp */
};
/*
* handle internet requests
*/
sysctl_inet(string, bufpp, mib, flags, typep)
char *string;
char **bufpp;
int mib[];
int flags;
int *typep;
{
struct list *lp;
int indx;
if (*bufpp == NULL) {
listall(string, &inetlist);
return (-1);
}
if ((indx = findname(string, "third", bufpp, &inetlist)) == -1)
return (-1);
mib[2] = indx;
if (indx <= IPPROTO_UDP && inetvars[indx].list != NULL)
lp = &inetvars[indx];
else if (!flags)
return (-1);
else {
fprintf(stderr, "%s: no variables defined for this protocol\n",
string);
return (-1);
}
if (*bufpp == NULL) {
listall(string, lp);
return (-1);
}
if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
return (-1);
mib[3] = indx;
*typep = lp->list[indx].ctl_type;
return (4);
}
/*
* Scan a list of names searching for a particular name.
*/
findname(string, level, bufp, namelist)
char *string;
char *level;
char **bufp;
struct list *namelist;
{
char *name;
int i;
if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) {
fprintf(stderr, "%s: incomplete specification\n", string);
return (-1);
}
for (i = 0; i < namelist->size; i++)
if (namelist->list[i].ctl_name != NULL &&
strcmp(name, namelist->list[i].ctl_name) == 0)
break;
if (i == namelist->size) {
fprintf(stderr, "%s level name %s in %s is invalid\n",
level, name, string);
return (-1);
}
return (i);
}
usage()
{
(void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n",
"sysctl [-n] variable ...", "sysctl [-n] -w variable=value ...",
"sysctl [-n] -a", "sysctl [-n] -A");
exit(1);
}

View file

@ -0,0 +1,24 @@
# @(#)Makefile 8.4 (Berkeley) 4/22/94
SUBDIR= src mailstats makemap praliases cf/cf
FTPDIR= barad-dur:/disks/barad-dur/ftp/sendmail/.
VER= XX
tar: Files.base Files.cf Files.misc Files.xdoc
(cd src; ${MAKE})
(cd doc; PRINTER=ps ${MAKE})
(cd doc; chmod 444 op/op.ps intro/intro.ps usenix/usenix.ps)
(cd cf/cf; ${MAKE})
pax -w -x tar -L -f sendmail.${VER}.base.tar `grep -v ^# Files.base`
compress sendmail.${VER}.base.tar
pax -w -x tar -L -f sendmail.${VER}.cf.tar `grep -v ^# Files.cf`
compress sendmail.${VER}.cf.tar
pax -w -x tar -L -f sendmail.${VER}.misc.tar `grep -v ^# Files.misc`
compress sendmail.${VER}.misc.tar
pax -w -x tar -L -f sendmail.${VER}.xdoc.tar `grep -v ^# Files.xdoc`
compress sendmail.${VER}.xdoc.tar
ftp: sendmail.${VER}.base.tar.Z sendmail.${VER}.cf.tar.Z sendmail.${VER}.misc.tar.Z sendmail.${VER}.xdoc.tar.Z
rcp sendmail.${VER}.*.tar.Z RELEASE_NOTES FAQ KNOWNBUGS ${FTPDIR}
.include <bsd.subdir.mk>

View file

@ -0,0 +1,11 @@
# @(#)slip.hosts 8.1 (Berkeley) 6/6/93
#
# login local-addr remote-addr mask opt1 opt2
# (normal,compress,noicmp)
#
Schez vangogh chez 0xffffff00 compress
Sjun vangogh 128.32.130.36 0xffffff00 normal
Sleconte vangogh leconte 0xffffff00 compress
Sleeb vangogh leeb 0xffffff00 compress
Smjk vangogh pissaro-sl 0xffffff00 compress
Soxford vangogh oxford 0xffffff00 compress

View file

@ -0,0 +1,12 @@
#!/bin/sh -
#
# @(#)slip.login 8.1 (Berkeley) 6/6/93
#
# generic login file for a slip line. sliplogin invokes this with
# the parameters:
# 1 2 3 4 5 6 7-n
# slipunit ttyspeed loginname local-addr remote-addr mask opt-args
#
/sbin/ifconfig sl$1 inet $4 $5 netmask $6
exit

26
usr.sbin/Makefile Normal file
View file

@ -0,0 +1,26 @@
# @(#)Makefile 5.20 (Berkeley) 6/12/93
SUBDIR= ac accton amd arp chown chroot cron dev_mkdb diskpart edquota \
inetd kgmon kvm_mkdb lpr mkproto mtree portmap pstat pwd_mkdb \
quot quotaon repquota rmt rwhod sa sendmail sliplogin sysctl \
syslogd traceroute trpt trsp update vipw
.if make(clean) || make(cleandir)
SUBDIR+=bad144 config config.new eeprom iostat timed
.elif ${MACHINE} == "hp300"
SUBDIR+=config iostat timed
.elif ${MACHINE} == "i386"
SUBDIR+=bad144 config iostat
.elif ${MACHINE} == "luna68k"
SUBDIR+=config iostat timed
.elif ${MACHINE} == "mips"
SUBDIR+=config iostat timed
.elif ${MACHINE} == "sparc"
SUBDIR+=config.new eeprom timed
.elif ${MACHINE} == "tahoe"
SUBDIR+=config iostat timed
.elif ${MACHINE} == "vax"
SUBDIR+=bad144 config iostat timed
.endif
.include <bsd.subdir.mk>

3
usr.sbin/Makefile.inc Normal file
View file

@ -0,0 +1,3 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/6/93
BINDIR?= /usr/sbin

107
usr.sbin/ac/ac.8 Normal file
View file

@ -0,0 +1,107 @@
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)ac.8 8.2 (Berkeley) 4/19/94
.\"
.Dd April 19, 1994
.Dt AC 8
.Os BSD 4
.Sh NAME
.Nm ac
.Nd display connect time accounting
.Sh SYNOPSIS
.Nm ac
.Op Fl d
.Op Fl p
.Op Fl w Ar file
.Op Ar users ...
.Sh DESCRIPTION
If the file
.Pa /var/log/wtmp
exists,
a record of individual
login and logout times are written to it by
.Xr init 8
and
.Xr login 8
respectively.
The program
.Nm ac
examines these
records and writes the accumulated connect time for all logins to the
standard output.
.Pp
Options available:
.Bl -tag -width people
.It Fl d
Display the connect times in 24 hour chunks.
.It Fl p
Display individual user totals.
.It Fl w Ar file
Read raw connect time data from
.Ar file
instead of the default file
.Pa /var/log/wtmp .
.It Ar users ...
Display totals for the given individuals
only.
.El
.Pp
If no arguments are given,
.Nm
displays the total amount of login time for all active accounts on the
system.
.Pp
The default
.Pa wtmp
file is an infinitely increasing file
unless frequently truncated. This is normally
done by the daily daemon scripts scheduled by
.Xr cron 8
which rename and rotate the
.Pa wtmp
files before truncating them (and keeping about a weeks worth on hand).
No login times are collected however, if the file does not exist.
.Sh FILES
.Bl -tag -width /var/log/wtmp.[0-7] -compact
.It Pa /var/log/wtmp
.It Pa /var/log/wtmp.[0-7]
rotated files
.El
.Sh SEE ALSO
.Xr init 8 ,
.Xr sa 8 ,
.Xr login 1 ,
.Xr utmp 5 .
.Sh HISTORY
A
.Nm
command appeared in Version 6 AT&T UNIX.

6
usr.sbin/accton/Makefile Normal file
View file

@ -0,0 +1,6 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= accton
NOMAN= noman
.include <bsd.prog.mk>

95
usr.sbin/accton/accton.c Normal file
View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)accton.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
{
int ch;
while ((ch = getopt(argc, argv, "")) != EOF)
switch(ch) {
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
switch(argc) {
case 0:
if (acct(NULL)) {
(void)fprintf(stderr,
"accton: %s\n", strerror(errno));
exit(1);
}
break;
case 1:
if (acct(*argv)) {
(void)fprintf(stderr,
"accton: %s: %s\n", *argv, strerror(errno));
exit(1);
}
break;
default:
usage();
}
exit(0);
}
void
usage()
{
(void)fprintf(stderr, "usage: accton [file]\n");
exit(1);
}

5
usr.sbin/amd/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
SUBDIR= amd amq fsinfo mk-amd-map
.include <bsd.subdir.mk>

1169
usr.sbin/amd/amd/ChangeLog Normal file

File diff suppressed because it is too large Load diff

33
usr.sbin/amd/amd/Makefile Normal file
View file

@ -0,0 +1,33 @@
# @(#)Makefile 8.2 (Berkeley) 4/22/94
PROG= amd
MAN8= amd.0
OS= bsd44
SRCS= afs_ops.c am_ops.c clock.c util.c xutil.c \
efs_ops.c mapc.c info_file.c info_hes.c \
info_ndbm.c info_passwd.c info_nis.c \
info_union.c map.c srvr_afs.c srvr_nfs.c \
mntfs.c misc_rpc.c mount_fs.c mount_xdr.c \
mtab.c mtab_bsd.c nfs_ops.c nfs_prot_svc.c \
nfs_start.c nfs_subr.c nfs_prot_xdr.c opts.c \
pfs_ops.c rpc_fwd.c sched.c sfs_ops.c amq_svc.c \
amq_subr.c umount_fs.c host_ops.c nfsx_ops.c \
ufs_ops.c ifs_ops.c amd.c get_args.c restart.c wire.c
OBJS+= vers.${PROG}.o
LDADD+= -lrpc
CFLAGS+=-I${.CURDIR}/../rpcx
CFLAGS+=-I${.CURDIR}/../config
CFLAGS+=-I${.CURDIR}/../include
CFLAGS+=-DARCH_REP=\"${MACHINE}\"
CFLAGS+=-DOS_REP=\"${OS}\"
CFLAGS+=-DOS_HDR=\"os-${OS}.h\"
CFLAGS+=${CONFIG}
CLEANFILES+=vers.${PROG}.c vers.${PROG}.o version.amd
vers.${PROG}.c: ${SRCS:.c=.o}
@d=${.CURDIR}/ sh ${.CURDIR}/../config/newvers.sh ${PROG} ${MACHINE} ${OS}
.PATH: ${.CURDIR}/../rpcx ${.CURDIR}/../config
.include "Makefile.config"
.include "../../Makefile.inc"
.include <bsd.prog.mk>

1816
usr.sbin/amd/amd/afs_ops.c Normal file

File diff suppressed because it is too large Load diff

181
usr.sbin/amd/amd/am_ops.c Normal file
View file

@ -0,0 +1,181 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)am_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: am_ops.c,v 5.2.2.1 1992/02/09 15:08:17 jsp beta $
*
*/
#include "am.h"
static am_ops *vops[] = {
#ifdef HAS_UFS
&ufs_ops,
#endif
#ifdef HAS_NFS
&nfs_ops,
#endif
#ifdef HAS_NFSX
&nfsx_ops,
#endif
#ifdef HAS_HOST
&host_ops,
#endif
#ifdef HAS_SFS
&sfs_ops,
#endif
#ifdef HAS_SFSX
&sfsx_ops,
#endif
#ifdef HAS_LOFS
&lofs_ops,
#endif
#ifdef HAS_PFS
&pfs_ops,
#endif
#ifdef HAS_UNION_FS
&union_ops,
#endif
&afs_ops, /* These four should be last ... */
&dfs_ops, /* ... */
&toplvl_ops, /* ... */
&efs_ops, /* ... in the order afs; dfs; toplvl; efs */
0
};
void ops_showfstypes P((FILE *fp));
void ops_showfstypes(fp)
FILE *fp;
{
struct am_ops **ap;
int l = 0;
for (ap = vops; *ap; ap++) {
fputs((*ap)->fs_type, fp);
if (ap[1]) fputs(", ", fp);
l += strlen((*ap)->fs_type) + 2;
if (l > 60) { l = 0; fputs("\n ", fp); }
}
}
#ifdef SUNOS4_COMPAT
#ifdef nomore
/*
* Crack a SunOS4-style host:fs:sub-link line
* Construct an amd-style line and call the
* normal amd matcher.
*/
am_ops *sunos4_match(fo, key, g_key, path, keym, map)
am_opts *fo;
char *key;
char *g_key;
char *path;
char *keym;
char *map;
{
char *host = key;
char *fs = strchr(host, ':');
char *sublink = fs ? strchr(fs+1, ':') : 0;
char keybuf[MAXPATHLEN];
sprintf(keybuf, "type:=nfs;rhost:=%s;rfs:=%s;sublink:=%s;opts:=%s", host,
fs ? fs+1 : "",
sublink ? sublink+1 : "",
g_key);
return ops_match(fo, keybuf, "", path, keym, map);
}
#endif
#endif /* SUNOS4_COMPAT */
am_ops *ops_match(fo, key, g_key, path, keym, map)
am_opts *fo;
char *key;
char *g_key;
char *path;
char *keym;
char *map;
{
am_ops **vp;
am_ops *rop = 0;
/*
* First crack the global opts and the local opts
*/
if (!eval_fs_opts(fo, key, g_key, path, keym, map)) {
rop = &efs_ops;
} else if (fo->opt_type == 0) {
plog(XLOG_USER, "No fs type specified (key = \"%s\", map = \"%s\")", keym, map);
rop = &efs_ops;
} else {
/*
* Next find the correct filesystem type
*/
for (vp = vops; rop = *vp; vp++)
if (strcmp(rop->fs_type, fo->opt_type) == 0)
break;
if (!rop) {
plog(XLOG_USER, "fs type \"%s\" not recognised", fo->opt_type);
rop = &efs_ops;
}
}
/*
* Make sure we have a default mount option.
* Otherwise skip past any leading '-'.
*/
if (fo->opt_opts == 0)
fo->opt_opts = "rw,defaults";
else if (*fo->opt_opts == '-')
fo->opt_opts++;
/*
* Check the filesystem is happy
*/
if (fo->fs_mtab)
free((voidp) fo->fs_mtab);
if (fo->fs_mtab = (*rop->fs_match)(fo))
return rop;
/*
* Return error file system
*/
fo->fs_mtab = (*efs_ops.fs_match)(fo);
return &efs_ops;
}

232
usr.sbin/amd/amd/amd.8 Normal file
View file

@ -0,0 +1,232 @@
.\"
.\" Copyright (c) 1989 Jan-Simon Pendry
.\" Copyright (c) 1989 Imperial College of Science, Technology & Medicine
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Jan-Simon Pendry at Imperial College, London.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)amd.8 5.10 (Berkeley) 4/19/94
.\"
.\" $Id: amd.8,v 5.2.2.1 1992/02/09 15:11:39 jsp beta $
.\"
.Dd "April 19, 1994"
.Dt AMD 8
.Os
.Sh NAME
.Nm amd
.Nd automatically mount file systems
.Sh SYNOPSIS
.Nm amd
.Op Fl nprv
.Op Fl a Ar mount_point
.Op Fl c Ar duration
.Op Fl d Ar domain
.Bk -words
.Op Fl k Ar kernel-arch
.Ek
.Op Fl l Ar logfile
.Op Fl t Ar interval.interval
.Bk -words
.Op Fl w Ar interval
.Ek
.Op Fl x Ar log-option
.Op Fl y Ar YP-domain
.Bk -words
.Op Fl C Ar cluster-name
.Ek
.Op Fl D Ar option
.Oo
.Ar directory mapname
.Op Fl map-options
.Oc
.Ar ...
.Sh DESCRIPTION
.Nm Amd
is a daemon that automatically mounts filesystems
whenever a file or directory
within that filesystem is accessed.
Filesystems are automatically unmounted when they
appear to be quiescent.
.Pp
.Nm Amd
operates by attaching itself as an
.Tn NFS
server to each of the specified
.Ar directories .
Lookups within the specified directories
are handled by
.Nm amd ,
which uses the map defined by
.Ar mapname
to determine how to resolve the lookup.
Generally, this will be a host name, some filesystem information
and some mount options for the given filesystem.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl a Ar temporary-directory
Specify an alternative location for the real mount points.
The default is
.Pa /a .
.It Fl c Ar duration
Specify a
.Ar duration ,
in seconds, that a looked up name remains
cached when not in use. The default is 5 minutes.
.It Fl d Ar domain
Specify the local domain name. If this option is not
given the domain name is determined from the hostname.
.It Fl k Ar kernel-arch
Specifies the kernel architecture. This is used solely
to set the ${karch} selector.
.It Fl l Ar logfile
Specify a logfile in which to record mount and unmount events.
If
.Ar logfile
is the string
.Em syslog ,
the log messages will be sent to the system log daemon by
.Xr syslog 3 .
.It Fl n
Normalize hostnames.
The name referred to by ${rhost} is normalized relative to the
host database before being used. The effect is to translate
aliases into ``official'' names.
.It Fl p
Print
.Em PID .
Outputs the process-id of
.Nm amd
to standard output where it can be saved into a file.
.It Fl r
Restart existing mounts.
.Nm Amd
will scan the mount file table to determine which filesystems
are currently mounted. Whenever one of these would have
been auto-mounted,
.Nm amd
.Em inherits
it.
.It Fl t Ar interval.interval
Specify the
.Ar interval ,
in tenths of a second, between
.Tn NFS/RPC/UDP
retries.
The default is 0.8 seconds.
The second values alters the retransmit counter.
Useful defaults are supplied if either or both
values are missing.
.It Fl v
Version. Displays version and configuration information on standard error.
.It Fl w Ar interval
Specify an
.Ar interval ,
in seconds, between attempts to dismount
filesystems that have exceeded their cached times.
The default is 2 minutes.
.It Fl y Ar domain
Specify an alternative
.Tn NIS
domain from which to fetch the
.Tn NIS
maps.
The default is the system domain name.
This option is ignored if
.Tn NIS
support is not available.
.It Fl x Ar options
Specify run-time logging options. The options are a comma separated
list chosen from: fatal, error, user, warn, info, map, stats, all.
.It Fl D Ar option
Select from a variety of debug options. Prefixing an
option with the string
.Em no
reverses the effect of that option. Options are cumulative.
The most useful option is
.Ar all .
.El
.Pp
Since
.Fl D
is only used for debugging other options are not documented here:
the current supported set of options is listed by the
.Fl v
option
and a fuller description is available in the program source.
.Sh FILES
.Bl -tag -width /axx
.It Pa /a
directory under which filesystems are dynamically mounted
.El
.Sh CAVEATS
Some care may be required when creating a mount map.
.Pp
Symbolic links on an
.Tn NFS
filesystem can be incredibly inefficient.
In most implementations of
.Tn NFS ,
their interpolations are not cached by
the kernel and each time a symbolic link is
encountered during a
.Em lookuppn
translation it costs an
.Tn RPC
call to the
.Tn NFS
server.
A large improvement in real-time
performance could be gained by adding a cache somewhere.
Replacing
.Xr symlinks 2
with a suitable incarnation of the auto-mounter
results in a large real-time speedup, but also causes a large
number of process context switches.
.Pp
A weird imagination is most useful to gain full advantage of all
the features.
.Sh SEE ALSO
.Xr amq 8 ,
.Xr hostname 1 ,
.Xr mount 8 ,
.Xr umount 8 ,
.Rs
.%T Amd \- The 4.4 BSD Automounter
.Re
.Sh AUTHOR
.An Jan-Simon Pendry
<jsp@doc.ic.ac.uk>, Department of Computing, Imperial College, London, UK.
.Sh HISTORY
The
.Nm amd
utility first appeared in 4.4BSD.

344
usr.sbin/amd/amd/amd.c Normal file
View file

@ -0,0 +1,344 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)amd.c 8.1 (Berkeley) 6/6/93
*
* $Id: amd.c,v 5.2.2.1 1992/02/09 15:08:15 jsp beta $
*
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
/*
* Automounter
*/
#include "am.h"
#include <sys/signal.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <setjmp.h>
char pid_fsname[16 + MAXHOSTNAMELEN]; /* "kiska.southseas.nz:(pid%d)" */
char *progname; /* "amd" */
#ifdef HAS_HOST
#ifdef HOST_EXEC
char *host_helper;
#endif /* HOST_EXEC */
#endif /* HAS_HOST */
char *auto_dir = "/a";
char *hostdomain = "unknown.domain";
char hostname[MAXHOSTNAMELEN] = "localhost"; /* Hostname */
char hostd[2*MAXHOSTNAMELEN]; /* Host+domain */
char *op_sys = OS_REP; /* Name of current op_sys */
char *arch = ARCH_REP; /* Name of current architecture */
char *endian = ARCH_ENDIAN; /* Big or Little endian */
char *wire;
int foreground = 1; /* This is the top-level server */
int mypid; /* Current process id */
int immediate_abort; /* Should close-down unmounts be retried */
struct in_addr myipaddr; /* (An) IP address of this host */
serv_state amd_state;
struct amd_stats amd_stats; /* Server statistics */
time_t do_mapc_reload = 0; /* mapc_reload() call required? */
jmp_buf select_intr;
int select_intr_valid;
int orig_umask;
/*
* Signal handler:
* SIGINT - tells amd to do a full shutdown, including unmounting all filesystem.
* SIGTERM - tells amd to shutdown now. Just unmounts the automount nodes.
*/
static void sigterm(sig)
int sig;
{
#ifdef SYS5_SIGNALS
signal(sig, sigterm);
#endif /* SYS5_SIGNALS */
switch (sig) {
case SIGINT:
immediate_abort = 15;
break;
case SIGTERM:
immediate_abort = -1;
/* fall through... */
default:
plog(XLOG_WARNING, "WARNING: automounter going down on signal %d", sig);
break;
}
if (select_intr_valid)
longjmp(select_intr, sig);
}
/*
* Hook for cache reload.
* When a SIGHUP arrives it schedules a call to mapc_reload
*/
/*ARGSUSED*/
static void sighup(sig)
int sig;
{
#ifdef SYS5_SIGNALS
signal(sig, sighup);
#endif /* SYS5_SIGNALS */
#ifdef DEBUG
if (sig != SIGHUP)
dlog("spurious call to sighup");
#endif /* DEBUG */
/*
* Force a reload by zero'ing the timer
*/
if (amd_state == Run)
do_mapc_reload = 0;
}
/*ARGSUSED*/
static void parent_exit(sig)
int sig;
{
exit(0);
}
static int daemon_mode(P_void)
{
int bgpid;
signal(SIGQUIT, parent_exit);
bgpid = background();
if (bgpid != 0) {
if (print_pid) {
printf("%d\n", bgpid);
fflush(stdout);
}
/*
* Now wait for the automount points to
* complete.
*/
for (;;)
pause();
}
signal(SIGQUIT, SIG_DFL);
/*
* Pretend we are in the foreground again
*/
foreground = 1;
#ifdef TIOCNOTTY
{
int t = open("/dev/tty", O_RDWR);
if (t < 0) {
if (errno != ENXIO) /* not an error if already no controlling tty */
plog(XLOG_WARNING, "Could not open controlling tty: %m");
} else {
if (ioctl(t, TIOCNOTTY, 0) < 0 && errno != ENOTTY)
plog(XLOG_WARNING, "Could not disassociate tty (TIOCNOTTY): %m");
(void) close(t);
}
}
#else
(void) setpgrp();
#endif /* TIOCNOTTY */
return getppid();
}
main(argc, argv)
int argc;
char *argv[];
{
char *domdot;
int ppid = 0;
int error;
/*
* Make sure some built-in assumptions are true before we start
*/
assert(sizeof(nfscookie) >= sizeof (unsigned int));
assert(sizeof(int) >= 4);
/*
* Set processing status.
*/
amd_state = Start;
/*
* Determine program name
*/
if (argv[0]) {
progname = strrchr(argv[0], '/');
if (progname && progname[1])
progname++;
else
progname = argv[0];
}
if (!progname)
progname = "amd";
/*
* Initialise process id. This is kept
* cached since it is used for generating
* and using file handles.
*/
mypid = getpid();
/*
* Get local machine name
*/
if (gethostname(hostname, sizeof(hostname)) < 0) {
plog(XLOG_FATAL, "gethostname: %m");
going_down(1);
}
/*
* Check it makes sense
*/
if (!*hostname) {
plog(XLOG_FATAL, "host name is not set");
going_down(1);
}
/*
* Partially initialise hostd[]. This
* is completed in get_args().
*/
if (domdot = strchr(hostname, '.')) {
/*
* Hostname already contains domainname.
* Split out hostname and domainname
* components
*/
*domdot++ = '\0';
hostdomain = domdot;
}
strcpy(hostd, hostname);
/*
* Trap interrupts for shutdowns.
*/
(void) signal(SIGINT, sigterm);
/*
* Hangups tell us to reload the cache
*/
(void) signal(SIGHUP, sighup);
/*
* Trap Terminate so that we can shutdown gracefully (some chance)
*/
(void) signal(SIGTERM, sigterm);
/*
* Trap Death-of-a-child. These allow us to
* pick up the exit status of backgrounded mounts.
* See "sched.c".
*/
(void) signal(SIGCHLD, sigchld);
/*
* Fix-up any umask problems. Most systems default
* to 002 which is not too convenient for our purposes
*/
orig_umask = umask(0);
/*
* Figure out primary network name
*/
wire = getwire();
/*
* Determine command-line arguments
*/
get_args(argc, argv);
/*
* Get our own IP address so that we
* can mount the automounter.
*/
{ struct sockaddr_in sin;
get_myaddress(&sin);
myipaddr.s_addr = sin.sin_addr.s_addr;
}
/*
* Now check we are root.
*/
if (geteuid() != 0) {
plog(XLOG_FATAL, "Must be root to mount filesystems (euid = %d)", geteuid());
going_down(1);
}
#ifdef HAS_NIS_MAPS
/*
* If the domain was specified then bind it here
* to circumvent any default bindings that may
* be done in the C library.
*/
if (domain && yp_bind(domain)) {
plog(XLOG_FATAL, "Can't bind to domain \"%s\"", domain);
going_down(1);
}
#endif /* HAS_NIS_MAPS */
#ifdef DEBUG
Debug(D_DAEMON)
#endif /* DEBUG */
ppid = daemon_mode();
sprintf(pid_fsname, "%s:(pid%d)", hostname, mypid);
do_mapc_reload = clocktime() + ONE_HOUR;
/*
* Register automounter with system
*/
error = mount_automounter(ppid);
if (error && ppid)
kill(SIGALRM, ppid);
going_down(error);
abort();
}

464
usr.sbin/amd/amd/amq_subr.c Normal file
View file

@ -0,0 +1,464 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)amq_subr.c 8.1 (Berkeley) 6/6/93
*
* $Id: amq_subr.c,v 5.2.2.1 1992/02/09 15:08:18 jsp beta $
*
*/
/*
* Auxilliary routines for amq tool
*/
#include "am.h"
#include "amq.h"
#include <ctype.h>
/*ARGSUSED*/
voidp
amqproc_null_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static char res;
return (voidp) &res;
}
/*
* Return a sub-tree of mounts
*/
/*ARGSUSED*/
amq_mount_tree_p *
amqproc_mnttree_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static am_node *mp;
mp = find_ap(*(char **) argp);
return (amq_mount_tree_p *) &mp;
}
/*
* Unmount a single node
*/
/*ARGSUSED*/
voidp
amqproc_umnt_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static char res;
am_node *mp = find_ap(*(char **) argp);
if (mp)
forcibly_timeout_mp(mp);
return (voidp) &res;
}
/*
* Return global statistics
*/
/*ARGSUSED*/
amq_mount_stats *
amqproc_stats_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
return (amq_mount_stats *) &amd_stats;
}
/*
* Return the entire tree of mount nodes
*/
/*ARGSUSED*/
amq_mount_tree_list *
amqproc_export_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static amq_mount_tree_list aml;
aml.amq_mount_tree_list_val = (amq_mount_tree_p *) &exported_ap[0];
aml.amq_mount_tree_list_len = 1; /* XXX */
return &aml;
}
int *
amqproc_setopt_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static int rc;
amq_setopt *opt = (amq_setopt *) argp;
rc = 0;
switch (opt->as_opt) {
case AMOPT_DEBUG:
#ifdef DEBUG
if (debug_option(opt->as_str))
rc = EINVAL;
#else
rc = EINVAL;
#endif /* DEBUG */
break;
case AMOPT_LOGFILE:
#ifdef not_yet
if (switch_to_logfile(opt->as_str))
rc = EINVAL;
#else
rc = EACCES;
#endif /* not_yet */
break;
case AMOPT_XLOG:
if (switch_option(opt->as_str))
rc = EINVAL;
break;
case AMOPT_FLUSHMAPC:
if (amd_state == Run) {
plog(XLOG_INFO, "amq says flush cache");
do_mapc_reload = 0;
flush_nfs_fhandle_cache((fserver *) 0);
flush_srvr_nfs_cache();
}
break;
}
return &rc;
}
amq_mount_info_list *
amqproc_getmntfs_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
extern qelem mfhead;
return (amq_mount_info_list *) &mfhead; /* XXX */
}
static int ok_security(rqstp)
struct svc_req *rqstp;
{
struct sockaddr_in *sin;
sin = svc_getcaller(rqstp->rq_xprt);
if (ntohs(sin->sin_port) >= 1024 ||
!(sin->sin_addr.s_addr == htonl(0x7f000001) ||
sin->sin_addr.s_addr == myipaddr.s_addr)) {
char dq[20];
plog(XLOG_INFO, "AMQ request from %s.%d DENIED",
inet_dquad(dq, sin->sin_addr.s_addr),
ntohs(sin->sin_port));
return(0);
}
return(1);
}
int *
amqproc_mount_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static int rc;
char *s = *(amq_string *) argp;
char *cp;
plog(XLOG_INFO, "amq requested mount of %s", s);
/*
* Minimalist security check.
*/
if (!ok_security(rqstp)) {
rc = EACCES;
return &rc;
}
/*
* Find end of key
*/
for (cp = (char *) s; *cp&&(!isascii(*cp)||!isspace(*cp)); cp++)
;
if (!*cp) {
plog(XLOG_INFO, "amqproc_mount: Invalid arguments");
rc = EINVAL;
return &rc;
}
*cp++ = '\0';
/*
* Find start of value
*/
while (*cp && isascii(*cp) && isspace(*cp))
cp++;
root_newmap(s, cp, (char *) 0);
rc = mount_auto_node(s, (voidp) root_node);
if (rc < 0)
return 0;
return &rc;
}
amq_string *
amqproc_getvers_1(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static amq_string res;
res = version;
return &res;
}
/*
* XDR routines.
*/
bool_t
xdr_amq_string(xdrs, objp)
XDR *xdrs;
amq_string *objp;
{
if (!xdr_string(xdrs, objp, AMQ_STRLEN)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_setopt(xdrs, objp)
XDR *xdrs;
amq_setopt *objp;
{
if (!xdr_enum(xdrs, (enum_t *)&objp->as_opt)) {
return (FALSE);
}
if (!xdr_string(xdrs, &objp->as_str, AMQ_STRLEN)) {
return (FALSE);
}
return (TRUE);
}
/*
* More XDR routines - Should be used for OUTPUT ONLY.
*/
bool_t
xdr_amq_mount_tree_node(xdrs, objp)
XDR *xdrs;
amq_mount_tree *objp;
{
am_node *mp = (am_node *) objp;
if (!xdr_amq_string(xdrs, &mp->am_mnt->mf_info)) {
return (FALSE);
}
if (!xdr_amq_string(xdrs, &mp->am_path)) {
return (FALSE);
}
if (!xdr_amq_string(xdrs, mp->am_link ? &mp->am_link : &mp->am_mnt->mf_mount)) {
return (FALSE);
}
if (!xdr_amq_string(xdrs, &mp->am_mnt->mf_ops->fs_type)) {
return (FALSE);
}
if (!xdr_long(xdrs, &mp->am_stats.s_mtime)) {
return (FALSE);
}
if (!xdr_u_short(xdrs, &mp->am_stats.s_uid)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mp->am_stats.s_getattr)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mp->am_stats.s_lookup)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mp->am_stats.s_readdir)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mp->am_stats.s_readlink)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mp->am_stats.s_statfs)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_mount_subtree(xdrs, objp)
XDR *xdrs;
amq_mount_tree *objp;
{
am_node *mp = (am_node *) objp;
if (!xdr_amq_mount_tree_node(xdrs, objp)) {
return (FALSE);
}
if (!xdr_pointer(xdrs, (char **)&mp->am_osib, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
return (FALSE);
}
if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_mount_tree(xdrs, objp)
XDR *xdrs;
amq_mount_tree *objp;
{
am_node *mp = (am_node *) objp;
am_node *mnil = 0;
if (!xdr_amq_mount_tree_node(xdrs, objp)) {
return (FALSE);
}
if (!xdr_pointer(xdrs, (char **)&mnil, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
return (FALSE);
}
if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_mount_tree_p(xdrs, objp)
XDR *xdrs;
amq_mount_tree_p *objp;
{
if (!xdr_pointer(xdrs, (char **)objp, sizeof(amq_mount_tree), xdr_amq_mount_tree)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_mount_stats(xdrs, objp)
XDR *xdrs;
amq_mount_stats *objp;
{
if (!xdr_int(xdrs, &objp->as_drops)) {
return (FALSE);
}
if (!xdr_int(xdrs, &objp->as_stale)) {
return (FALSE);
}
if (!xdr_int(xdrs, &objp->as_mok)) {
return (FALSE);
}
if (!xdr_int(xdrs, &objp->as_merr)) {
return (FALSE);
}
if (!xdr_int(xdrs, &objp->as_uerr)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_mount_tree_list(xdrs, objp)
XDR *xdrs;
amq_mount_tree_list *objp;
{
if (!xdr_array(xdrs, (char **)&objp->amq_mount_tree_list_val, (u_int *)&objp->amq_mount_tree_list_len, ~0, sizeof(amq_mount_tree_p), xdr_amq_mount_tree_p)) {
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_amq_mount_info_qelem(xdrs, qhead)
XDR *xdrs;
qelem *qhead;
{
/*
* Compute length of list
*/
mntfs *mf;
u_int len = 0;
for (mf = LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
if (!(mf->mf_ops->fs_flags & FS_AMQINFO))
continue;
len++;
}
xdr_u_int(xdrs, &len);
/*
* Send individual data items
*/
for (mf = LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
int up;
if (!(mf->mf_ops->fs_flags & FS_AMQINFO))
continue;
if (!xdr_amq_string(xdrs, &mf->mf_ops->fs_type)) {
return (FALSE);
}
if (!xdr_amq_string(xdrs, &mf->mf_mount)) {
return (FALSE);
}
if (!xdr_amq_string(xdrs, &mf->mf_info)) {
return (FALSE);
}
if (!xdr_amq_string(xdrs, &mf->mf_server->fs_host)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mf->mf_error)) {
return (FALSE);
}
if (!xdr_int(xdrs, &mf->mf_refc)) {
return (FALSE);
}
if (mf->mf_server->fs_flags & FSF_ERROR)
up = 0;
else switch (mf->mf_server->fs_flags & (FSF_DOWN|FSF_VALID)) {
case FSF_DOWN|FSF_VALID: up = 0; break;
case FSF_VALID: up = 1; break;
default: up = -1; break;
}
if (!xdr_int(xdrs, &up)) {
return (FALSE);
}
}
return (TRUE);
}

241
usr.sbin/amd/amd/clock.c Normal file
View file

@ -0,0 +1,241 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)clock.c 8.1 (Berkeley) 6/6/93
*
* $Id: clock.c,v 5.2.2.1 1992/02/09 15:08:20 jsp beta $
*
*/
/*
* Callouts.
*
* Modelled on kernel object of the same name.
* See usual references.
*
* Use of a heap-based mechanism was rejected:
* 1. more complex implementation needed.
* 2. not obvious that a list is too slow for Amd.
*/
#include "am.h"
typedef struct callout callout;
struct callout {
callout *c_next; /* List of callouts */
void (*c_fn)(); /* Function to call */
voidp c_closure; /* Closure to pass to call */
time_t c_time; /* Time of call */
int c_id; /* Unique identifier */
};
static callout callouts; /* List of pending callouts */
static callout *free_callouts; /* Cache of free callouts */
static int nfree_callouts; /* Number on free list */
static int callout_id; /* Next free callout identifier */
time_t next_softclock; /* Time of next call to softclock() */
/*
* Number of callout slots we keep on the free list
*/
#define CALLOUT_FREE_SLOP 10
/*
* Global assumption: valid id's are non-zero.
*/
#define CID_ALLOC() (++callout_id)
#define CID_UNDEF (0)
static callout *alloc_callout(P_void);
static callout *alloc_callout()
{
callout *cp = free_callouts;
if (cp) {
--nfree_callouts;
free_callouts = free_callouts->c_next;
return cp;
}
return ALLOC(callout);
}
static void free_callout P((callout *cp));
static void free_callout(cp)
callout *cp;
{
if (nfree_callouts > CALLOUT_FREE_SLOP) {
free((voidp) cp);
} else {
cp->c_next = free_callouts;
free_callouts = cp;
nfree_callouts++;
}
}
/*
* Schedule a callout.
*
* (*fn)(closure) will be called at clocktime() + secs
*/
int timeout P((unsigned int secs, void (*fn)(), voidp closure));
int timeout(secs, fn, closure)
unsigned int secs;
void (*fn)();
voidp closure;
{
callout *cp, *cp2;
time_t t = clocktime() + secs;
/*
* Allocate and fill in a new callout structure
*/
callout *cpnew = alloc_callout();
cpnew->c_closure = closure;
cpnew->c_fn = fn;
cpnew->c_time = t;
cpnew->c_id = CID_ALLOC();
if (t < next_softclock)
next_softclock = t;
/*
* Find the correct place in the list
*/
for (cp = &callouts; cp2 = cp->c_next; cp = cp2)
if (cp2->c_time >= t)
break;
/*
* And link it in
*/
cp->c_next = cpnew;
cpnew->c_next = cp2;
/*
* Return callout identifier
*/
return cpnew->c_id;
}
/*
* De-schedule a callout
*/
void untimeout P((int id));
void untimeout(id)
int id;
{
callout *cp, *cp2;
for (cp = &callouts; cp2 = cp->c_next; cp = cp2) {
if (cp2->c_id == id) {
cp->c_next = cp2->c_next;
free_callout(cp2);
break;
}
}
}
/*
* Reschedule after clock changed
*/
void reschedule_timeouts P((time_t now, time_t then));
void reschedule_timeouts(now, then)
time_t now;
time_t then;
{
callout *cp;
for (cp = callouts.c_next; cp; cp = cp->c_next) {
if (cp->c_time >= now && cp->c_time <= then) {
plog(XLOG_WARNING, "job %d rescheduled to run immediately", cp->c_id);
#ifdef DEBUG
dlog("rescheduling job %d back %d seconds",
cp->c_id, cp->c_time - now);
#endif
next_softclock = cp->c_time = now;
}
}
}
/*
* Clock handler
*/
int softclock(P_void);
int softclock()
{
time_t now;
callout *cp;
do {
if (task_notify_todo)
do_task_notify();
now = clocktime();
/*
* While there are more callouts waiting...
*/
while ((cp = callouts.c_next) && cp->c_time <= now) {
/*
* Extract first from list, save fn & closure and
* unlink callout from list and free.
* Finally call function.
*
* The free is done first because
* it is quite common that the
* function will call timeout()
* and try to allocate a callout
*/
void (*fn)() = cp->c_fn;
voidp closure = cp->c_closure;
callouts.c_next = cp->c_next;
free_callout(cp);
#ifdef DEBUG
/*dlog("Calling %#x(%#x)", fn, closure);*/
#endif /* DEBUG */
(*fn)(closure);
}
} while (task_notify_todo);
/*
* Return number of seconds to next event,
* or 0 if there is no event.
*/
if (cp = callouts.c_next)
return cp->c_time - now;
return 0;
}

135
usr.sbin/amd/amd/efs_ops.c Normal file
View file

@ -0,0 +1,135 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)efs_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: efs_ops.c,v 5.2.2.1 1992/02/09 15:08:21 jsp beta $
*
*/
#include "am.h"
#ifdef HAS_EFS
/*
* Error file system.
* This is used as a last resort catchall if
* nothing else worked. EFS just returns lots
* of error codes, except for unmount which
* always works of course.
*/
/*
* EFS file system always matches
*/
static char *efs_match(fo)
am_opts *fo;
{
return strdup("(error-hook)");
}
/*ARGSUSED*/
static int efs_fmount(mf)
mntfs *mf;
{
return ENOENT;
}
/*ARGSUSED*/
static int efs_fumount(mf)
mntfs *mf;
{
/*
* Always succeed
*/
return 0;
}
/*
* EFS interface to RPC lookup() routine.
* Should never get here in the automounter.
* If we do then just give an error.
*/
/*ARGSUSED*/
am_node *efs_lookuppn(mp, fname, error_return, op)
am_node *mp;
char *fname;
int *error_return;
int op;
{
*error_return = ESTALE;
return 0;
}
/*
* EFS interface to RPC readdir() routine.
* Should never get here in the automounter.
* If we do then just give an error.
*/
/*ARGSUSED*/
int efs_readdir(mp, cookie, dp, ep, count)
am_node *mp;
nfscookie cookie;
dirlist *dp;
entry *ep;
int count;
{
return ESTALE;
}
/*
* Ops structure
*/
am_ops efs_ops = {
"error",
efs_match,
0, /* efs_init */
auto_fmount,
efs_fmount,
auto_fumount,
efs_fumount,
efs_lookuppn,
efs_readdir,
0, /* efs_readlink */
0, /* efs_mounted */
0, /* efs_umounted */
find_afs_srvr,
FS_DISCARD
};
#endif /* HAS_EFS */

336
usr.sbin/amd/amd/get_args.c Normal file
View file

@ -0,0 +1,336 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)get_args.c 8.1 (Berkeley) 6/6/93
*
* $Id: get_args.c,v 5.2.2.1 1992/02/09 15:08:23 jsp beta $
*
*/
/*
* Argument decode
*/
#include "am.h"
#ifdef HAS_SYSLOG
#include <syslog.h>
#endif /* HAS_SYSLOG */
#include <sys/stat.h>
extern int optind;
extern char *optarg;
#if defined(DEBUG) && defined(PARANOID)
char **gargv;
#endif /* defined(DEBUG) && defined(PARANOID) */
int restart_existing_mounts;
int print_pid;
int normalize_hosts;
char *karch; /* Kernel architecture */
char *cluster; /* Cluster name */
#ifdef HAS_NIS_MAPS
char *domain; /* YP domain */
#endif /* HAS_NIS_MAPS */
#ifdef UPDATE_MTAB
char *mtab;
#endif /* UPDATE_MTAB */
int afs_timeo = -1;
int afs_retrans = -1;
int am_timeo = AM_TTL;
int am_timeo_w = AM_TTL_W;
#ifdef DEBUG
/*
* List of debug options.
*/
static struct opt_tab dbg_opt[] = {
{ "all", D_ALL }, /* All */
{ "amq", D_AMQ }, /* Register for AMQ program */
{ "daemon", D_DAEMON }, /* Enter daemon mode */
{ "full", D_FULL }, /* Program trace */
{ "mem", D_MEM }, /* Trace memory allocations */
{ "mtab", D_MTAB }, /* Use local mtab file */
{ "str", D_STR }, /* Debug string munging */
{ "test", D_TEST }, /* Full debug - but no daemon */
{ "trace", D_TRACE }, /* Protocol trace */
{ 0, 0 }
};
int debug_flags = D_AMQ /* Register AMQ */
|D_DAEMON /* Enter daemon mode */
;
/*
* Switch on/off debug options
*/
int debug_option(opt)
char *opt;
{
return cmdoption(opt, dbg_opt, &debug_flags);
}
#endif /* DEBUG */
void get_args(c, v)
int c;
char *v[];
{
int opt_ch;
int usage = 0;
char *logfile = 0;
char *sub_domain = 0;
while ((opt_ch = getopt(c, v, "mnprva:c:d:h:k:l:t:w:x:y:C:D:")) != EOF)
switch (opt_ch) {
case 'a':
if (*optarg != '/') {
fprintf(stderr, "%s: -a option must begin with a '/'\n",
progname);
exit(1);
}
auto_dir = optarg;
break;
case 'c':
am_timeo = atoi(optarg);
if (am_timeo <= 0)
am_timeo = AM_TTL;
break;
case 'd':
sub_domain = optarg;
break;
case 'h':
#if defined(HAS_HOST) && defined(HOST_EXEC)
host_helper = optarg;
#else
plog(XLOG_USER, "-h: option ignored. HOST_EXEC is not enabled.");
break;
#endif /* defined(HAS_HOST) && defined(HOST_EXEC) */
case 'k':
karch = optarg;
break;
case 'l':
logfile = optarg;
break;
case 'm':
plog(XLOG_USER, "The -m option is no longer supported.");
plog(XLOG_USER, "... Use `ypcat -k am.master` on the command line instead");
break;
case 'n':
normalize_hosts = 1;
break;
case 'p':
print_pid = 1;
break;
case 'r':
restart_existing_mounts = 1;
break;
case 't':
/* timeo.retrans */
{ char *dot = strchr(optarg, '.');
if (dot) *dot = '\0';
if (*optarg) {
afs_timeo = atoi(optarg);
}
if (dot) {
afs_retrans = atoi(dot+1);
*dot = '.';
}
}
break;
case 'v':
fprintf(stderr, "%s%s (%s-endian).\n", copyright, version, endian);
fputs("Map support for: ", stderr);
mapc_showtypes(stderr);
fputs(".\nFS: ", stderr);
ops_showfstypes(stderr);
fputs(".\n", stderr);
fprintf(stderr, "Primary network is %s.\n", wire);
exit(0);
break;
case 'w':
am_timeo_w = atoi(optarg);
if (am_timeo_w <= 0)
am_timeo_w = AM_TTL_W;
break;
case 'x':
usage += switch_option(optarg);
break;
case 'y':
#ifdef HAS_NIS_MAPS
domain = optarg;
#else
plog(XLOG_USER, "-y: option ignored. No NIS support available.");
#endif /* HAS_NIS_MAPS */
break;
case 'C':
cluster = optarg;
break;
case 'D':
#ifdef DEBUG
usage += debug_option(optarg);
#else
fprintf(stderr, "%s: not compiled with DEBUG option -- sorry.\n", progname);
#endif /* DEBUG */
break;
default:
usage = 1;
break;
}
if (xlog_level_init == ~0) {
(void) switch_option("");
#ifdef DEBUG
usage += switch_option("debug");
#endif /* DEBUG */
} else {
#ifdef DEBUG
usage += switch_option("debug");
#endif /* DEBUG */
}
if (usage)
goto show_usage;
while (optind <= c-2) {
char *dir = v[optind++];
char *map = v[optind++];
char *opts = "";
if (v[optind] && *v[optind] == '-')
opts = &v[optind++][1];
root_newmap(dir, opts, map);
}
if (optind == c) {
#ifdef hpux
/*
* HP-UX can't handle ./mtab
* That system is sick - really.
*/
#ifdef DEBUG
debug_option("nomtab");
#endif /* DEBUG */
#endif /* hpux */
/*
* Append domain name to hostname.
* sub_domain overrides hostdomain
* if given.
*/
if (sub_domain)
hostdomain = sub_domain;
if (*hostdomain == '.')
hostdomain++;
strcat(hostd, ".");
strcat(hostd, hostdomain);
#ifdef UPDATE_MTAB
#ifdef DEBUG
if (debug_flags & D_MTAB)
mtab = DEBUG_MTAB;
else
#endif /* DEBUG */
mtab = MOUNTED;
#else
#ifdef DEBUG
{ if (debug_flags & D_MTAB) {
dlog("-D mtab option ignored");
} }
#endif /* DEBUG */
#endif /* UPDATE_MTAB */
if (switch_to_logfile(logfile) != 0)
plog(XLOG_USER, "Cannot switch logfile");
/*
* If the kernel architecture was not specified
* then use the machine architecture.
*/
if (karch == 0)
karch = arch;
if (cluster == 0)
cluster = hostdomain;
if (afs_timeo <= 0)
afs_timeo = AFS_TIMEO;
if (afs_retrans <= 0)
afs_retrans = AFS_RETRANS;
if (afs_retrans <= 0)
afs_retrans = 3; /* XXX */
return;
}
show_usage:
fprintf(stderr,
"Usage: %s [-mnprv] [-a mnt_point] [-c cache_time] [-d domain]\n\
\t[-k kernel_arch] [-l logfile|\"syslog\"] [-t afs_timeout]\n\
\t[-w wait_timeout] [-C cluster_name]", progname);
#if defined(HAS_HOST) && defined(HOST_EXEC)
fputs(" [-h host_helper]\n", stderr);
#endif /* defined(HAS_HOST) && defined(HOST_EXEC) */
#ifdef HAS_NIS_MAPS
fputs(" [-y nis-domain]\n", stderr);
#else
fputc('\n', stderr);
#endif /* HAS_NIS_MAPS */
show_opts('x', xlog_opt);
#ifdef DEBUG
show_opts('D', dbg_opt);
#endif /* DEBUG */
fprintf(stderr, "\t{directory mapname [-map_options]} ...\n");
exit(1);
}

681
usr.sbin/amd/amd/host_ops.c Normal file
View file

@ -0,0 +1,681 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)host_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: host_ops.c,v 5.2.2.2 1992/05/31 16:36:08 jsp Exp $
*
*/
#include "am.h"
#ifdef HAS_HOST
#include "mount.h"
#include <sys/stat.h>
/*
* NFS host file system.
* Mounts all exported filesystems from a given host.
* This has now degenerated into a mess but will not
* be rewritten. Amd 6 will support the abstractions
* needed to make this work correctly.
*/
/*
* Define HOST_RPC_UDP to use dgram instead of stream RPC.
* Datagrams are generally much faster.
*/
/*#define HOST_RPC_UDP*/
/*
* Define HOST_MKDIRS to make Amd automatically try
* to create the mount points.
*/
#define HOST_MKDIRS
/*
* Determine the mount point
*/
#define MAKE_MNTPT(mntpt, ex, mf) { \
if (strcmp((ex)->ex_dir, "/") == 0) \
strcpy((mntpt), (mf)->mf_mount); \
else \
sprintf((mntpt), "%s%s", (mf)->mf_mount, (ex)->ex_dir); \
}
/*
* Execute needs the same as NFS plus a helper command
*/
static char *host_match P((am_opts *fo));
static char *host_match(fo)
am_opts *fo;
{
#ifdef HOST_EXEC
if (!host_helper) {
plog(XLOG_USER, "No host helper command given");
return FALSE;
}
#endif /* HOST_EXEC */
/*
* Make sure rfs is specified to keep nfs_match happy...
*/
if (!fo->opt_rfs)
fo->opt_rfs = "/";
return (*nfs_ops.fs_match)(fo);
}
static int host_init(mf)
mntfs *mf;
{
if (strchr(mf->mf_info, ':') == 0)
return ENOENT;
return 0;
}
/*
* Two implementations:
* HOST_EXEC gets you the external version. The program specified with
* the -h option is called. The external program is not published...
* roll your own.
*
* Otherwise you get the native version. Faster but makes the program
* bigger.
*/
#ifndef HOST_EXEC
static bool_t
xdr_pri_free(xdr_args, args_ptr)
xdrproc_t xdr_args;
caddr_t args_ptr;
{
XDR xdr;
xdr.x_op = XDR_FREE;
return ((*xdr_args)(&xdr, args_ptr));
}
static int do_mount P((fhstatus *fhp, char *dir, char *fs_name, char *opts, mntfs *mf));
static int do_mount(fhp, dir, fs_name, opts, mf)
fhstatus *fhp;
char *dir;
char *fs_name;
char *opts;
mntfs *mf;
{
struct stat stb;
#ifdef DEBUG
dlog("host: mounting fs %s on %s\n", fs_name, dir);
#endif /* DEBUG */
#ifdef HOST_MKDIRS
(void) mkdirs(dir, 0555);
#endif /* HOST_MKDIRS */
if (stat(dir, &stb) < 0 || (stb.st_mode & S_IFMT) != S_IFDIR) {
plog(XLOG_ERROR, "No mount point for %s - skipping", dir);
return ENOENT;
}
return mount_nfs_fh(fhp, dir, fs_name, opts, mf);
}
static int sortfun P((exports *a, exports *b));
static int sortfun(a, b)
exports *a,*b;
{
return strcmp((*a)->ex_dir, (*b)->ex_dir);
}
/*
* Get filehandle
*/
static int fetch_fhandle P((CLIENT *client, char *dir, fhstatus *fhp));
static int fetch_fhandle(client, dir, fhp)
CLIENT *client;
char *dir;
fhstatus *fhp;
{
struct timeval tv;
enum clnt_stat clnt_stat;
/*
* Pick a number, any number...
*/
tv.tv_sec = 20;
tv.tv_usec = 0;
#ifdef DEBUG
dlog("Fetching fhandle for %s", dir);
#endif /* DEBUG */
/*
* Call the mount daemon on the remote host to
* get the filehandle.
*/
clnt_stat = clnt_call(client, MOUNTPROC_MNT, xdr_dirpath, &dir, xdr_fhstatus, fhp, tv);
if (clnt_stat != RPC_SUCCESS) {
extern char *clnt_sperrno();
char *msg = clnt_sperrno(clnt_stat);
plog(XLOG_ERROR, "mountd rpc failed: %s", msg);
return EIO;
}
/*
* Check status of filehandle
*/
if (fhp->fhs_status) {
#ifdef DEBUG
errno = fhp->fhs_status;
dlog("fhandle fetch failed: %m");
#endif /* DEBUG */
return fhp->fhs_status;
}
return 0;
}
/*
* Scan mount table to see if something already mounted
*/
static int already_mounted P((mntlist *mlist, char*dir));
static int already_mounted(mlist, dir)
mntlist *mlist;
char *dir;
{
mntlist *ml;
for (ml = mlist; ml; ml = ml->mnext)
if (strcmp(ml->mnt->mnt_dir, dir) == 0)
return 1;
return 0;
}
/*
* Mount the export tree from a host
*/
static int host_fmount P((mntfs *mf));
static int host_fmount(mf)
mntfs *mf;
{
struct timeval tv2;
CLIENT *client;
enum clnt_stat clnt_stat;
int n_export;
int j, k;
exports exlist = 0, ex;
exports *ep = 0;
fhstatus *fp = 0;
char *host = mf->mf_server->fs_host;
int error = 0;
struct sockaddr_in sin;
int sock = RPC_ANYSOCK;
int ok = FALSE;
mntlist *mlist;
char fs_name[MAXPATHLEN], *rfs_dir;
char mntpt[MAXPATHLEN];
struct timeval tv;
tv.tv_sec = 10; tv.tv_usec = 0;
/*
* Read the mount list
*/
mlist = read_mtab(mf->mf_mount);
/*
* Unlock the mount list
*/
unlock_mntlist();
/*
* Take a copy of the server address
*/
sin = *mf->mf_server->fs_ip;
/*
* Zero out the port - make sure we recompute
*/
sin.sin_port = 0;
/*
* Make a client end-point.
* Try TCP first
*/
if ((client = clnttcp_create(&sin, MOUNTPROG, MOUNTVERS, &sock, 0, 0)) == NULL &&
(client = clntudp_create(&sin, MOUNTPROG, MOUNTVERS, tv, &sock)) == NULL) {
plog(XLOG_ERROR, "Failed to make rpc connection to mountd on %s", host);
error = EIO;
goto out;
}
if (!nfs_auth) {
error = make_nfs_auth();
if (error)
goto out;
}
client->cl_auth = nfs_auth;
#ifdef DEBUG
dlog("Fetching export list from %s", host);
#endif /* DEBUG */
/*
* Fetch the export list
*/
tv2.tv_sec = 10; tv2.tv_usec = 0;
clnt_stat = clnt_call(client, MOUNTPROC_EXPORT, xdr_void, 0, xdr_exports, &exlist, tv2);
if (clnt_stat != RPC_SUCCESS) {
/*clnt_perror(client, "rpc");*/
error = EIO;
goto out;
}
/*
* Figure out how many exports were returned
*/
for (n_export = 0, ex = exlist; ex; ex = ex->ex_next) {
/*printf("export %s\n", ex->ex_dir);*/
n_export++;
}
#ifdef DEBUG
/*dlog("%d exports returned\n", n_export);*/
#endif /* DEBUG */
/*
* Allocate an array of pointers into the list
* so that they can be sorted. If the filesystem
* is already mounted then ignore it.
*/
ep = (exports *) xmalloc(n_export * sizeof(exports));
for (j = 0, ex = exlist; ex; ex = ex->ex_next) {
MAKE_MNTPT(mntpt, ex, mf);
if (!already_mounted(mlist, mntpt))
ep[j++] = ex;
}
n_export = j;
/*
* Sort into order.
* This way the mounts are done in order down the tree,
* instead of any random order returned by the mount
* daemon (the protocol doesn't specify...).
*/
qsort(ep, n_export, sizeof(exports), sortfun);
/*
* Allocate an array of filehandles
*/
fp = (fhstatus *) xmalloc(n_export * sizeof(fhstatus));
/*
* Try to obtain filehandles for each directory.
* If a fetch fails then just zero out the array
* reference but discard the error.
*/
for (j = k = 0; j < n_export; j++) {
/* Check and avoid a duplicated export entry */
if (j > k && ep[k] && strcmp(ep[j]->ex_dir, ep[k]->ex_dir) == 0) {
#ifdef DEBUG
dlog("avoiding dup fhandle requested for %s", ep[j]->ex_dir);
#endif
ep[j] = 0;
} else {
k = j;
if (error = fetch_fhandle(client, ep[j]->ex_dir, &fp[j]))
ep[j] = 0;
}
}
/*
* Mount each filesystem for which we have a filehandle.
* If any of the mounts succeed then mark "ok" and return
* error code 0 at the end. If they all fail then return
* the last error code.
*/
strncpy(fs_name, mf->mf_info, sizeof(fs_name));
if ((rfs_dir = strchr(fs_name, ':')) == (char *) 0) {
plog(XLOG_FATAL, "host_fmount: mf_info has no colon");
error = EINVAL;
goto out;
}
++rfs_dir;
for (j = 0; j < n_export; j++) {
ex = ep[j];
if (ex) {
strcpy(rfs_dir, ex->ex_dir);
MAKE_MNTPT(mntpt, ex, mf);
if (do_mount(&fp[j], mntpt, fs_name, mf->mf_mopts, mf) == 0)
ok = TRUE;
}
}
/*
* Clean up and exit
*/
out:
discard_mntlist(mlist);
if (ep)
free(ep);
if (fp)
free(fp);
if (client)
clnt_destroy(client);
if (exlist)
xdr_pri_free(xdr_exports, &exlist);
if (ok)
return 0;
return error;
}
/*
* Return true if pref is a directory prefix of dir.
*
* TODO:
* Does not work if pref is "/".
*/
static int directory_prefix P((char *pref, char *dir));
static int directory_prefix(pref, dir)
char *pref;
char *dir;
{
int len = strlen(pref);
if (strncmp(pref, dir, len) != 0)
return FALSE;
if (dir[len] == '/' || dir[len] == '\0')
return TRUE;
return FALSE;
}
/*
* Unmount a mount tree
*/
static int host_fumount P((mntfs *mf));
static int host_fumount(mf)
mntfs *mf;
{
mntlist *ml, *mprev;
int xerror = 0;
/*
* Read the mount list
*/
mntlist *mlist = read_mtab(mf->mf_mount);
/*
* Unlock the mount list
*/
unlock_mntlist();
/*
* Reverse list...
*/
ml = mlist;
mprev = 0;
while (ml) {
mntlist *ml2 = ml->mnext;
ml->mnext = mprev;
mprev = ml;
ml = ml2;
}
mlist = mprev;
/*
* Unmount all filesystems...
*/
for (ml = mlist; ml && !xerror; ml = ml->mnext) {
char *dir = ml->mnt->mnt_dir;
if (directory_prefix(mf->mf_mount, dir)) {
int error;
#ifdef DEBUG
dlog("host: unmounts %s", dir);
#endif /* DEBUG */
/*
* Unmount "dir"
*/
error = UMOUNT_FS(dir);
/*
* Keep track of errors
*/
if (error) {
if (!xerror)
xerror = error;
if (error != EBUSY) {
errno = error;
plog("Tree unmount of %s failed: %m", ml->mnt->mnt_dir);
}
} else {
#ifdef HOST_MKDIRS
(void) rmdirs(dir);
#endif /* HOST_MKDIRS */
}
}
}
/*
* Throw away mount list
*/
discard_mntlist(mlist);
/*
* Try to remount, except when we are shutting down.
*/
if (xerror && amd_state != Finishing) {
xerror = host_fmount(mf);
if (!xerror) {
/*
* Don't log this - it's usually too verbose
plog(XLOG_INFO, "Remounted host %s", mf->mf_info);
*/
xerror = EBUSY;
}
}
return xerror;
}
/*
* Tell mountd we're done.
* This is not quite right, because we may still
* have other filesystems mounted, but the existing
* mountd protocol is badly broken anyway.
*/
static void host_umounted(mp)
am_node *mp;
{
#ifdef INFORM_MOUNTD
mntfs *mf = mp->am_mnt;
char *host;
CLIENT *client;
enum clnt_stat clnt_stat;
struct sockaddr_in sin;
int sock = RPC_ANYSOCK;
struct timeval tv;
tv.tv_sec = 10; tv.tv_usec = 0;
if (mf->mf_error || mf->mf_refc > 1 || ! mf->mf_server)
return;
host = mf->mf_server->fs_host;
sin = *mf->mf_server->fs_ip;
/*
* Zero out the port - make sure we recompute
*/
sin.sin_port = 0;
/*
* Make a client end-point.
* Try TCP first
*/
if ((client = clnttcp_create(&sin, MOUNTPROG, MOUNTVERS, &sock, 0, 0)) == NULL &&
(client = clntudp_create(&sin, MOUNTPROG, MOUNTVERS, tv, &sock)) == NULL) {
plog(XLOG_ERROR, "Failed to make rpc connection to mountd on %s", host);
goto out;
}
if (!nfs_auth) {
if (make_nfs_auth())
goto out;
}
client->cl_auth = nfs_auth;
#ifdef DEBUG
dlog("Unmounting all from %s", host);
#endif /* DEBUG */
clnt_stat = clnt_call(client, MOUNTPROC_UMNTALL, xdr_void, 0, xdr_void, 0, tv);
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_SYSTEMERROR) {
/* RPC_SYSTEMERROR seems to be returned for no good reason ...*/
extern char *clnt_sperrno();
char *msg = clnt_sperrno(clnt_stat);
plog(XLOG_ERROR, "unmount all from %s rpc failed: %s", host, msg, clnt_stat);
goto out;
}
out:
if (client)
clnt_destroy(client);
#endif /* INFORM_MOUNTD */
}
#else /* HOST_EXEC */
static int host_exec P((char*op, char*host, char*fs, char*opts));
static int host_exec(op, host, fs, opts)
char *op;
char *host;
char *fs;
char *opts;
{
int error;
char *argv[7];
/*
* Build arg vector
*/
argv[0] = host_helper;
argv[1] = host_helper;
argv[2] = op;
argv[3] = host;
argv[4] = fs;
argv[5] = opts && *opts ? opts : "rw,default";
argv[6] = 0;
/*
* Put stdout to stderr
*/
(void) fclose(stdout);
(void) dup(fileno(logfp));
if (fileno(logfp) != fileno(stderr)) {
(void) fclose(stderr);
(void) dup(fileno(logfp));
}
/*
* Try the exec
*/
#ifdef DEBUG
Debug(D_FULL) {
char **cp = argv;
plog(XLOG_DEBUG, "executing (un)mount command...");
while (*cp) {
plog(XLOG_DEBUG, "arg[%d] = '%s'", cp-argv, *cp);
cp++;
}
}
#endif /* DEBUG */
if (argv[0] == 0 || argv[1] == 0) {
errno = EINVAL;
plog(XLOG_USER, "1st/2nd args missing to (un)mount program");
} else {
(void) execv(argv[0], argv+1);
}
/*
* Save error number
*/
error = errno;
plog(XLOG_ERROR, "exec %s failed: %m", argv[0]);
/*
* Return error
*/
return error;
}
static int host_mount P((am_node *mp));
static int host_mount(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
return host_exec("mount", mf->mf_server->fs_host, mf->mf_mount, mf->mf_opts);
}
static int host_umount P((am_node *mp));
static int host_umount(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
return host_exec("unmount", mf->mf_server->fs_host, mf->mf_mount, "xxx");
}
#endif /* HOST_EXEC */
/*
* Ops structure
*/
am_ops host_ops = {
"host",
host_match,
host_init,
auto_fmount,
host_fmount,
auto_fumount,
host_fumount,
efs_lookuppn,
efs_readdir,
0, /* host_readlink */
0, /* host_mounted */
#ifdef HOST_EXEC
0, /* host_umounted */
#else
host_umounted,
#endif
find_nfs_srvr,
FS_MKMNT|FS_BACKGROUND|FS_AMQINFO
};
#endif /* HAS_HOST */

195
usr.sbin/amd/amd/ifs_ops.c Normal file
View file

@ -0,0 +1,195 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)ifs_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: ifs_ops.c,v 5.2.2.1 1992/02/09 15:08:26 jsp beta $
*
*/
#include "am.h"
#ifdef HAS_IFS
/*
* Inheritance file system.
* This implements a filesystem restart.
*
* This is a *gross* hack - it knows far too
* much about the way other parts of the
* sytem work. See restart.c too.
*/
static char not_a_filesystem[] = "Attempting to inherit not-a-filesystem";
/*
* This should never be called.
*/
/*ARGSUSED*/
static char *ifs_match P((am_opts *fo));
static char *ifs_match(fo)
am_opts *fo;
{
plog(XLOG_FATAL, "ifs_match called!");
return 0;
}
static int ifs_init P((mntfs *mf));
static int ifs_init(mf)
mntfs *mf;
{
mntfs *mf_link = (mntfs *) mf->mf_private;
if (mf_link == 0) {
plog(XLOG_FATAL, not_a_filesystem);
return EINVAL;
}
#ifdef notdef
/*
* Fill in attribute fields
*/
mf_link->mf_fattr.type = NFLNK;
mf_link->mf_fattr.mode = NFSMODE_LNK | 0777;
mf_link->mf_fattr.nlink = 1;
mf_link->mf_fattr.size = MAXPATHLEN / 4;
#endif
if (mf_link->mf_ops->fs_init)
return (*mf_link->mf_ops->fs_init)(mf_link);
return 0;
}
static mntfs *ifs_inherit P((mntfs *mf));
static mntfs *ifs_inherit(mf)
mntfs *mf;
{
/*
* Take the linked mount point and
* propogate.
*/
mntfs *mf_link = (mntfs *) mf->mf_private;
if (mf_link == 0) {
plog(XLOG_FATAL, not_a_filesystem);
return 0; /*XXX*/
}
mf_link->mf_fo = mf->mf_fo;
#ifdef notdef
mf_link->mf_fattr.fileid = mf->mf_fattr.fileid;
#endif /* notdef */
/*
* Discard the old map.
* Don't call am_unmounted since this
* node was never really mounted in the
* first place.
*/
mf->mf_private = 0;
free_mntfs(mf);
/*
* Free the dangling reference
* to the mount link.
*/
free_mntfs(mf_link);
/*
* Get a hold of the other entry
*/
mf_link->mf_flags &= ~MFF_RESTART;
/* Say what happened */
plog(XLOG_INFO, "restarting %s on %s", mf_link->mf_info, mf_link->mf_mount);
return mf_link;
}
static int ifs_mount P((am_node *mp));
static int ifs_mount(mp)
am_node *mp;
{
mntfs *newmf = ifs_inherit(mp->am_mnt);
if (newmf) {
mp->am_mnt = newmf;
/*
* XXX - must do the am_mounted call here
*/
if (newmf->mf_ops->fs_flags & FS_MBACKGROUND)
am_mounted(mp);
new_ttl(mp);
return 0;
}
return EINVAL;
}
static int ifs_fmount P((mntfs *mf));
static int ifs_fmount(mf)
mntfs *mf;
{
am_node *mp = find_mf(mf);
if (mp)
return ifs_mount(mp);
return ifs_inherit(mf) ? 0 : EINVAL;
}
/*ARGSUSED*/
static int ifs_fumount P((mntfs *mf));
static int ifs_fumount(mf)
mntfs *mf;
{
/*
* Always succeed
*/
return 0;
}
/*
* Ops structure
*/
am_ops ifs_ops = {
"inherit",
ifs_match,
ifs_init,
ifs_mount,
ifs_fmount,
auto_fumount,
ifs_fumount,
efs_lookuppn,
efs_readdir,
0, /* ifs_readlink */
0, /* ifs_mounted */
0, /* ifs_umounted */
find_afs_srvr,
FS_DISCARD
};
#endif /* HAS_IFS */

View file

@ -0,0 +1,276 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)info_file.c 8.1 (Berkeley) 6/6/93
*
* $Id: info_file.c,v 5.2.2.1 1992/02/09 15:08:28 jsp beta $
*
*/
/*
* Get info from file
*/
#include "am.h"
#ifdef HAS_FILE_MAPS
#include <ctype.h>
#include <sys/stat.h>
#define MAX_LINE_LEN 2048
static int read_line P((char *buf, int size, FILE *fp));
static int read_line(buf, size, fp)
char *buf;
int size;
FILE *fp;
{
int done = 0;
do {
while (fgets(buf, size, fp)) {
int len = strlen(buf);
done += len;
if (len > 1 && buf[len-2] == '\\' &&
buf[len-1] == '\n') {
int ch;
buf += len - 2;
size -= len - 2;
*buf = '\n'; buf[1] = '\0';
/*
* Skip leading white space on next line
*/
while ((ch = getc(fp)) != EOF &&
isascii(ch) && isspace(ch))
;
(void) ungetc(ch, fp);
} else {
return done;
}
}
} while (size > 0 && !feof(fp));
return done;
}
/*
* Try to locate a key in a file
*/
static int search_or_reload_file P((FILE *fp, char *map, char *key, char **val, mnt_map *m, void (*fn)(mnt_map *m, char*, char*)));
static int search_or_reload_file(fp, map, key, val, m, fn)
FILE *fp;
char *map;
char *key;
char **val;
mnt_map *m;
void (*fn) P((mnt_map*, char*, char*));
{
char key_val[MAX_LINE_LEN];
int chuck = 0;
int line_no = 0;
while (read_line(key_val, sizeof(key_val), fp)) {
char *kp;
char *cp;
char *hash;
int len = strlen(key_val);
line_no++;
/*
* Make sure we got the whole line
*/
if (key_val[len-1] != '\n') {
plog(XLOG_WARNING, "line %d in \"%s\" is too long", line_no, map);
chuck = 1;
} else {
key_val[len-1] = '\0';
}
/*
* Strip comments
*/
hash = strchr(key_val, '#');
if (hash)
*hash = '\0';
/*
* Find start of key
*/
for (kp = key_val; *kp && isascii(*kp) && isspace(*kp); kp++)
;
/*
* Ignore blank lines
*/
if (!*kp)
goto again;
/*
* Find end of key
*/
for (cp = kp; *cp&&(!isascii(*cp)||!isspace(*cp)); cp++)
;
/*
* Check whether key matches
*/
if (*cp)
*cp++ = '\0';
if (fn || (*key == *kp && strcmp(key, kp) == 0)) {
while (*cp && isascii(*cp) && isspace(*cp))
cp++;
if (*cp) {
/*
* Return a copy of the data
*/
char *dc = strdup(cp);
if (fn) {
(*fn)(m, strdup(kp), dc);
} else {
*val = dc;
#ifdef DEBUG
dlog("%s returns %s", key, dc);
#endif /* DEBUG */
}
if (!fn)
return 0;
} else {
plog(XLOG_USER, "%s: line %d has no value field", map, line_no);
}
}
again:
/*
* If the last read didn't get a whole line then
* throw away the remainder before continuing...
*/
if (chuck) {
while (fgets(key_val, sizeof(key_val), fp) &&
!strchr(key_val, '\n'))
;
chuck = 0;
}
}
return fn ? 0 : ENOENT;
}
static FILE *file_open P((char *map, time_t *tp));
static FILE *file_open(map, tp)
char *map;
time_t *tp;
{
FILE *mapf = fopen(map, "r");
if (mapf && tp) {
struct stat stb;
if (fstat(fileno(mapf), &stb) < 0)
*tp = clocktime();
else
*tp = stb.st_mtime;
}
return mapf;
}
int file_init P((char *map, time_t *tp));
int file_init(map, tp)
char *map;
time_t *tp;
{
FILE *mapf = file_open(map, tp);
if (mapf) {
(void) fclose(mapf);
return 0;
}
return errno;
}
int file_reload P((mnt_map *m, char *map, void (*fn)()));
int file_reload(m, map, fn)
mnt_map *m;
char *map;
void (*fn)();
{
FILE *mapf = file_open(map, (time_t *) 0);
if (mapf) {
int error = search_or_reload_file(mapf, map, 0, 0, m, fn);
(void) fclose(mapf);
return error;
}
return errno;
}
int file_search P((mnt_map *m, char *map, char *key, char **pval, time_t *tp));
int file_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
time_t t;
FILE *mapf = file_open(map, &t);
if (mapf) {
int error;
if (*tp < t) {
*tp = t;
error = -1;
} else {
error = search_or_reload_file(mapf, map, key, pval, 0, 0);
}
(void) fclose(mapf);
return error;
}
return errno;
}
int file_mtime P((char *map, time_t *tp));
int file_mtime(map, tp)
char *map;
time_t *tp;
{
FILE *mapf = file_open(map, tp);
if (mapf) {
(void) fclose(mapf);
return 0;
}
return errno;
}
#endif /* HAS_FILE_MAPS */

697
usr.sbin/amd/amd/info_hes.c Normal file
View file

@ -0,0 +1,697 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)info_hes.c 8.1 (Berkeley) 6/6/93
*
* $Id: info_hes.c,v 5.2.2.1 1992/02/09 15:08:29 jsp beta $
*
*/
/*
* Get info from Hesiod
*
* Zone transfer code from Bruce Cole <cole@cs.wisc.edu>
*/
#include "am.h"
#ifdef HAS_HESIOD_MAPS
#include <hesiod.h>
#define HES_PREFIX "hesiod."
#define HES_PREFLEN 7
#ifdef HAS_HESIOD_RELOAD
#include <arpa/nameser.h>
#include <resolv.h>
#include <sys/uio.h>
#include <netdb.h>
/*
* Patch up broken system include files
*/
#ifndef C_HS
#define C_HS 4
#endif
#ifndef T_TXT
#define T_TXT 16
#endif
static int soacnt;
static struct timeval hs_timeout;
static int servernum;
#endif /* HAS_HESIOD_RELOAD */
/*
* No easy way to probe the server - check the map name begins with "hesiod."
*/
int hesiod_init P((char *map, time_t *tp));
int hesiod_init(map, tp)
char *map;
time_t *tp;
{
#ifdef DEBUG
dlog("hesiod_init(%s)", map);
#endif
*tp = 0;
return strncmp(map, HES_PREFIX, HES_PREFLEN) == 0 ? 0 : ENOENT;
}
/*
* Make Hesiod name. Skip past the "hesiod."
* at the start of the map name and append
* ".automount". The net effect is that a lookup
* of /defaults in hesiod.home will result in a
* call to hes_resolve("/defaults", "home.automount");
*/
#ifdef notdef
#define MAKE_HES_NAME(dest, src) sprintf(dest, "%s%s", src + HES_PREFLEN, ".automount")
#endif
/*
* Do a Hesiod nameserver call.
* Modify time is ignored by Hesiod - XXX
*/
int hesiod_search P((mnt_map *m, char *map, char **pval, time_t *tp));
int hesiod_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
int error;
char hes_key[MAXPATHLEN];
char **rvec;
#ifdef DEBUG
dlog("hesiod_search(m=%x, map=%s, key=%s, pval=%x tp=%x)", m, map, key, pval, tp);
#endif
/*MAKE_HES_NAME(hes_map, map);*/
sprintf(hes_key, "%s.%s", key, map+HES_PREFLEN);
/*
* Call the resolver
*/
#ifdef DEBUG
dlog("hesiod_search: hes_resolve(%s, %s)", hes_key, "automount");
#ifdef HAS_HESIOD_RELOAD
if (debug_flags & D_FULL)
_res.options |= RES_DEBUG;
#endif
#endif
rvec = hes_resolve(hes_key, "automount");
/*
* If a reply was forthcoming then return
* it (and free subsequent replies)
*/
if (rvec && *rvec) {
*pval = *rvec;
while (*++rvec)
free(*rvec);
return 0;
}
/*
* Otherwise reflect the hesiod error into a Un*x error
*/
#ifdef DEBUG
dlog("hesiod_search: Error: %d", hes_error());
#endif
switch (hes_error()) {
case HES_ER_NOTFOUND: error = ENOENT; break;
case HES_ER_CONFIG: error = EIO; break;
case HES_ER_NET: error = ETIMEDOUT; break;
default: error = EINVAL; break;
}
#ifdef DEBUG
dlog("hesiod_search: Returning: %d", error);
#endif
return error;
}
#ifdef HAS_HESIOD_RELOAD
/*
* Zone transfer...
*/
#define MAXHSNS 8
#define MAX_NSADDR 16
static char *hs_domain;
static mnt_map *hs_map;
static int hs_nscount;
static char nsaddr_list[MAX_NSADDR][sizeof(struct in_addr)];
int hesiod_reload P((mnt_map *m, char *map, void (*fn)()));
int hesiod_reload(m, map, fn)
mnt_map *m;
char *map;
void (*fn)();
{
char *zone_name, *cp;
short domainlen;
int status;
#ifdef DEBUG
dlog("hesiod_reload (%x %s %x)", m, map, fn);
#endif DEBUG
if (status = res_init()) {
#ifdef DEBUG
dlog("hesiod_reload: res_init failed with %d", status);
#endif
return(status);
}
_res.retrans = 90;
hs_map = m;
domainlen = strlen(hostdomain);
zone_name = hes_to_bind(map+HES_PREFLEN, "automount");
if (*zone_name == '.')
zone_name++;
hs_domain = zone_name;
/* Traverse the DNS tree until we find an SOA we can transfer from.
(Our initial zone_name is likely to just be a subtree of a
real zone). */
do {
/* If we can't find any NS records, go up a level in the
DNS tree */
if (hs_get_ns_list(zone_name) == 0 &&
hs_zone_transfer(zone_name) == 0)
return(0);
/* Move up DNS tree by one component */
if (cp = strchr(zone_name, '.'))
zone_name = ++cp;
else
break;
} while (strlen(zone_name) >= domainlen);
#ifdef DEBUG
dlog("hesiod_reload: Giving up on %s", hs_domain);
#endif
return(-1);
}
hs_zone_transfer(domain)
char *domain;
{
int status, len;
char buf[PACKETSZ];
/* Want to make sure ansbuf is well alligned */
long ansbuf[PACKETSZ/sizeof(long)];
#ifdef DEBUG
dlog("hs_zone_transfer (%s)", domain);
#endif
if ((len = res_mkquery(QUERY, domain, C_HS, T_AXFR,
(char *)NULL, 0, NULL, buf, PACKETSZ)) == -1) {
#ifdef DEBUG
dlog("hs_zone_transfer: res_mkquery failed");
#endif
errno = 0;
return(-1);
}
if ((status = hs_res_send(buf, len, (char *)ansbuf, PACKETSZ)) == -1) {
#ifdef DEBUG
dlog("hs_zone_transfer: hs_res_send failed. status %d errno %d",
status, errno);
#endif
errno = 0;
return(-1);
}
return(0);
}
#define hs_server_addr(ns) ((struct in_addr *) nsaddr_list[ns])
hs_res_send(buf, buflen, answer, anslen)
char *buf;
int buflen;
char *answer;
int anslen;
{
int retry, ns;
u_short id, len;
HEADER *hp = (HEADER *) buf;
struct iovec iov[2];
static int s = -1;
int status;
struct sockaddr_in server;
soacnt = 0;
id = hp->id;
/*
* Send request, RETRY times, or until successful
*/
for (retry = _res.retry; retry > 0; retry--) {
for (ns = 0; ns < hs_nscount; ns++) {
hs_timeout.tv_sec =
(_res.retrans << (_res.retry - retry))
/ hs_nscount;
if (hs_timeout.tv_sec <= 0)
hs_timeout.tv_sec = 1;
hs_timeout.tv_usec = 0;
if (s < 0) {
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
continue;
}
servernum = ns;
bcopy(hs_server_addr(ns), &server.sin_addr,
sizeof(struct in_addr));
server.sin_family = AF_INET;
server.sin_port = htons(NAMESERVER_PORT);
if (connect(s, &server,
sizeof(struct sockaddr)) < 0) {
(void) close(s);
s = -1;
continue;
}
}
/*
* Send length & message
*/
len = htons((u_short)buflen);
iov[0].iov_base = (caddr_t)&len;
iov[0].iov_len = sizeof(len);
iov[1].iov_base = buf;
iov[1].iov_len = buflen;
if (writev(s, iov, 2) != sizeof(len) + buflen) {
(void) close(s);
s = -1;
continue;
}
status = 0;
while (s != -1 && soacnt < 2 && status != -2) {
if ((status =
hs_readresp(s, answer, anslen)) == -1) {
(void) close(s);
s = -1;
continue;
}
}
if (status == -2) {
/* There was a permanent error transfering this
zone. Give up. */
if (s != -1) {
(void) close(s);
s = -1;
}
return(-1);
}
if (s == -1)
continue;
return (0);
}
}
if (errno == 0)
errno = ETIMEDOUT;
return (-1);
}
/* Returns:
0: Success
-1: Error
-2: Permanent failure
*/
hs_readresp(s, answer, anslen)
int s;
char *answer;
int anslen;
{
register int len, n;
char *cp;
cp = answer;
len = sizeof(short);
while (len != 0 &&
(n = hs_res_vcread(s, (char *)cp, (int)len, &hs_timeout)) > 0) {
cp += n;
len -= n;
}
if (n <= 0)
return(-1);
cp = answer;
if ((len = _getshort(cp)) > anslen) {
#ifdef DEBUG
dlog("hs_readresp: response too long: %d", len);
#endif
return(-1);
}
while (len != 0 &&
(n = hs_res_vcread(s, (char *)cp, (int)len, &hs_timeout)) > 0) {
cp += n;
len -= n;
}
if (n <= 0)
return(-1);
return(hs_parse(answer, answer+PACKETSZ));
}
hs_res_vcread(sock, buf, buflen, timeout)
int sock, buflen;
char *buf;
struct timeval *timeout;
{
register int n;
if ((n = hs_res_selwait(sock, timeout)) > 0)
return(read(sock, buf, buflen));
else
return(n);
}
hs_res_selwait(sock, timeout)
int sock;
struct timeval *timeout;
{
fd_set dsmask;
register int n;
/*
* Wait for reply
*/
FD_ZERO(&dsmask);
FD_SET(sock, &dsmask);
n = select(sock+1, &dsmask, (fd_set *)NULL,
(fd_set *)NULL, timeout);
return(n);
}
/* Returns:
0: Success
-1: Error
-2: Permanent failure
*/
hs_parse(msg, eom)
char *msg, *eom;
{
register char *cp;
register HEADER *hp;
register int n, len;
int qdcount, ancount;
char key[PACKETSZ];
char *key_cpy, *value, *hs_make_value();
short type;
hp = (HEADER *)msg;
if (hp->rcode != NOERROR || hp->opcode != QUERY) {
char dq[20];
#ifdef DEBUG
dlog("Bad response (%d) from nameserver %s", hp->rcode, inet_dquad(dq, hs_server_addr(servernum)->s_addr));
#endif DEBUG
return(-1);
}
cp = msg + sizeof(HEADER);
ancount = ntohs(hp->ancount);
qdcount = ntohs(hp->qdcount);
while (qdcount-- > 0)
cp += dn_skipname(cp, eom) + QFIXEDSZ;
if (soacnt == 0 && ancount == 0) {
/* XXX We should look for NS records to find SOA */
#ifdef DEBUG
dlog("No SOA found");
#endif
return(-2);
}
while (ancount-- > 0 && cp < eom) {
if ((n = dn_expand(msg, eom, cp, key, PACKETSZ)) < 0)
break;
cp += n;
if ((type = _getshort(cp)) == T_SOA) {
soacnt++;
}
cp += 2*sizeof(u_short) + sizeof(u_long);
len = _getshort(cp);
cp += sizeof(u_short);
/* Check to see if key is in our domain */
if (type == T_TXT && hs_strip_our_domain(key)) {
value = hs_make_value(cp, len);
if (value == NULL)
return(-1);
key_cpy = strdup(key);
#ifdef DEBUG
dlog("hs_parse: Parsed key: %s, value: %s", key,
value);
#endif
mapc_add_kv(hs_map, key_cpy, value);
}
cp += len;
errno = 0;
}
return(0);
}
/* Check to see if the domain name in the supplied argument matches
hs_domain. Strip hs_domain from supplied argument if so. */
hs_strip_our_domain(name)
char *name;
{
char *end_pos;
short targ_len, cur_len;
targ_len = strlen(hs_domain);
cur_len = strlen(name);
if (cur_len <= targ_len)
return(0);
end_pos = &name[cur_len - targ_len];
if (strcmp(end_pos, hs_domain) != 0)
return(0);
if (*--end_pos != '.')
return(0);
*end_pos = '\0';
return(1);
}
#define MAXDATA 8*1024
char *
hs_make_value(cp, len)
char *cp;
int len;
{
char *value, *cpcpy, *valuep;
int cnt, nextcnt, totalcnt, lencpy;
#ifdef DEBUG
char *dbgname;
dbgname = &cp[1];
#endif DEBUG
lencpy = len;
cpcpy = cp;
totalcnt = 0;
cnt = *cpcpy++;
while (cnt) {
totalcnt += cnt;
lencpy -= cnt+1;
if (lencpy == 0)
break;
nextcnt = cpcpy[cnt];
cpcpy = &cpcpy[cnt+1];
cnt = nextcnt;
}
if (totalcnt < 1 || totalcnt > MAXDATA || totalcnt > len) {
#ifdef DEBUG
dlog("TXT RR not of expected length (%d %d): %s", totalcnt,
len, dbgname);
#endif DEBUG
return(NULL);
}
/* Allocate null terminated string */
value = (char *) xmalloc(totalcnt+1);
value[totalcnt] = '\0';
cnt = *cp++;
valuep = value;
while (cnt) {
bcopy(cp, valuep, cnt);
len -= cnt+1;
if (len == 0)
break;
valuep = &valuep[cnt];
nextcnt = cp[cnt];
cp = &cp[cnt+1];
cnt = nextcnt;
}
return(value);
}
hs_make_ns_query(domain, ansbuf)
char *domain;
char *ansbuf;
{
int status, len;
char buf[PACKETSZ];
if ((len = res_mkquery(QUERY, domain, C_HS, T_NS,
(char *)NULL, 0, NULL, buf, PACKETSZ)) == -1) {
#ifdef DEBUG
dlog("hs_get_ns_list: res_mkquery failed");
#endif
errno = 0;
return(-1);
}
if ((status = res_send(buf, len, (char *)ansbuf, PACKETSZ)) == -1) {
#ifdef DEBUG
dlog("hs_get_ns_list: res_send failed. status %d errno %d",
status, errno);
#endif
errno = 0;
return(-1);
}
return(0);
}
static void
add_address(addr)
struct in_addr *addr;
{
char dq[20];
bcopy((char *)addr, nsaddr_list[hs_nscount++], sizeof(struct in_addr));
#ifdef DEBUG
dlog("Adding NS address %s", inet_dquad(dq, addr->s_addr));
#endif DEBUG
}
hs_get_ns_list(domain)
char *domain;
{
register HEADER *hp;
int qdcount, nscount;
register char *cp;
register int n, len;
char key[PACKETSZ], name[PACKETSZ], msg[PACKETSZ], *eom;
register long **hptr;
struct hostent *ghp;
int numns;
char nsname[MAXHSNS][MAXDATA];
int nshaveaddr[MAXHSNS], i;
short type;
if (hs_make_ns_query(domain, msg) == -1)
return(-1);
numns = hs_nscount = 0;
eom = &msg[PACKETSZ];
bzero(nsname, sizeof(nsname));
hp = (HEADER *)msg;
if (hp->rcode != NOERROR || hp->opcode != QUERY) {
#ifdef DEBUG
dlog("Bad response (%d) from nameserver %#x", hp->rcode,
hs_server_addr(servernum)->s_addr);
#endif DEBUG
return(-1);
}
cp = msg + sizeof(HEADER);
qdcount = ntohs(hp->qdcount);
while (qdcount-- > 0)
cp += dn_skipname(cp, eom) + QFIXEDSZ;
nscount = ntohs(hp->ancount) + ntohs(hp->nscount) + ntohs(hp->arcount);
#ifdef DEBUG
dlog("hs_get_ns_list: Processing %d response records", nscount);
#endif
for (;nscount; nscount--) {
if ((n = dn_expand(msg, eom, cp, key, PACKETSZ)) < 0)
break;
cp += n;
type = _getshort(cp);
cp += 2*sizeof(u_short) + sizeof(u_long);
len = _getshort(cp);
cp += sizeof(u_short);
#ifdef DEBUG
dlog("hs_get_ns_list: Record type: %d", type);
#endif
switch (type) {
case T_NS:
if (numns >= MAXHSNS || strcasecmp(domain, key) != 0)
break;
if ((n = dn_expand(msg, eom, cp, name, PACKETSZ)) < 0)
break;
#ifdef DEBUG
dlog("hs_get_ns_list: NS name: %s", name);
#endif
for (i = 0; i < numns; i++)
if (strcasecmp(nsname[i], name) == 0)
break;
if (i == numns) {
#ifdef DEBUG
dlog("hs_get_ns_list: Saving name %s", name);
#endif
strncpy(nsname[numns], name, MAXDATA);
nshaveaddr[numns] = 0;
numns++;
}
break;
case T_A:
if (hs_nscount == MAX_NSADDR)
break;
for (i = 0; i < numns; i++) {
if (strcasecmp(nsname[i], domain) == 0) {
nshaveaddr[i]++;
add_address((struct in_addr *) cp);
break;
}
}
break;
default:
break;
}
if (hs_nscount == MAX_NSADDR)
break;
cp += len;
errno = 0;
}
#ifdef DEBUG
dlog("hs_get_ns_list: Found %d NS records", numns);
#endif
for (i = 0; i < numns; i++) {
if (nshaveaddr[i])
continue;
if ((ghp = gethostbyname(nsname[i])) == 0)
continue;
for (hptr = (long **)ghp->h_addr_list;
*hptr && hs_nscount < MAX_NSADDR; hptr++) {
add_address((struct in_addr *) *hptr);
}
}
if (hs_nscount)
return(0);
#ifdef DEBUG
dlog("No NS records found for %s", domain);
return(-1);
#endif DEBUG
}
#endif /* HAS_HESIOD_RELOAD */
#endif /* HAS_HESIOD_MAPS */

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)info_ndbm.c 8.1 (Berkeley) 6/6/93
*
* $Id: info_ndbm.c,v 5.2.2.1 1992/02/09 15:08:31 jsp beta $
*
*/
/*
* Get info from NDBM map
*/
#include "am.h"
#ifdef HAS_NDBM_MAPS
#include <ndbm.h>
#include <fcntl.h>
#include <sys/stat.h>
static int search_ndbm P((DBM *db, char *key, char **val));
static int search_ndbm(db, key, val)
DBM *db;
char *key;
char **val;
{
datum k, v;
k.dptr = key;
k.dsize = strlen(key) + 1;
v = dbm_fetch(db, k);
if (v.dptr) {
*val = strdup(v.dptr);
return 0;
}
return ENOENT;
}
int ndbm_search P((mnt_map *m, char *map, char *key, char **pval, time_t *tp));
int ndbm_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
DBM *db;
db = dbm_open(map, O_RDONLY, 0);
if (db) {
struct stat stb;
int error;
error = fstat(dbm_pagfno(db), &stb);
if (!error && *tp < stb.st_mtime) {
*tp = stb.st_mtime;
error = -1;
} else {
error = search_ndbm(db, key, pval);
}
(void) dbm_close(db);
return error;
}
return errno;
}
int ndbm_init P((char *map, time_t *tp));
int ndbm_init(map, tp)
char *map;
time_t *tp;
{
DBM *db;
db = dbm_open(map, O_RDONLY, 0);
if (db) {
struct stat stb;
if (fstat(dbm_pagfno(db), &stb) < 0)
*tp = clocktime();
else
*tp = stb.st_mtime;
dbm_close(db);
return 0;
}
return errno;
}
#endif /* HAS_NDBM_MAPS */

247
usr.sbin/amd/amd/info_nis.c Normal file
View file

@ -0,0 +1,247 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)info_nis.c 8.1 (Berkeley) 6/6/93
*
* $Id: info_nis.c,v 5.2.2.1 1992/02/09 15:08:32 jsp beta $
*
*/
/*
* Get info from NIS map
*/
#include "am.h"
#ifdef HAS_NIS_MAPS
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
/*
* Figure out the nis domain name
*/
static int determine_nis_domain(P_void)
{
static int nis_not_running = 0;
char default_domain[YPMAXDOMAIN];
if (nis_not_running)
return ENOENT;
if (getdomainname(default_domain, sizeof(default_domain)) < 0) {
nis_not_running = 1;
plog(XLOG_ERROR, "getdomainname: %m");
return EIO;
}
if (!*default_domain) {
nis_not_running = 1;
plog(XLOG_WARNING, "NIS domain name is not set. NIS ignored.");
return ENOENT;
}
domain = strdup(default_domain);
return 0;
}
#ifdef HAS_NIS_RELOAD
struct nis_callback_data {
mnt_map *ncd_m;
char *ncd_map;
void (*ncd_fn)();
};
/*
* Callback from yp_all
*/
static int callback(status, key, kl, val, vl, data)
int status;
char *key;
int kl;
char *val;
int vl;
struct nis_callback_data *data;
{
if (status == YP_TRUE) {
/*
* Add to list of maps
*/
char *kp = strnsave(key, kl);
char *vp = strnsave(val, vl);
(*data->ncd_fn)(data->ncd_m, kp, vp);
/*
* We want more ...
*/
return FALSE;
} else {
/*
* NOMORE means end of map - otherwise log error
*/
if (status != YP_NOMORE) {
/*
* Check what went wrong
*/
int e = ypprot_err(status);
#ifdef DEBUG
plog(XLOG_ERROR, "yp enumeration of %s: %s, status=%d, e=%d",
data->ncd_map, yperr_string(e), status, e);
#else
plog(XLOG_ERROR, "yp enumeration of %s: %s", data->ncd_map, yperr_string(e));
#endif
}
return TRUE;
}
}
int nis_reload P((mnt_map *m, char *map, void (*fn)()));
int nis_reload(m, map, fn)
mnt_map *m;
char *map;
void (*fn)();
{
struct ypall_callback cbinfo;
int error;
struct nis_callback_data data;
if (!domain) {
error = determine_nis_domain();
if (error)
return error;
}
data.ncd_m = m;
data.ncd_map = map;
data.ncd_fn = fn;
cbinfo.data = (voidp) &data;
cbinfo.foreach = callback;
error = yp_all(domain, map, &cbinfo);
if (error)
plog(XLOG_ERROR, "error grabbing nis map of %s: %s", map, yperr_string(ypprot_err(error)));
return error;
}
#endif /* HAS_NIS_RELOAD */
/*
* Try to locate a key using NIS.
*/
int nis_search P((mnt_map *m, char *map, char *key, char **val, time_t *tp));
int nis_search(m, map, key, val, tp)
mnt_map *m;
char *map;
char *key;
char **val;
time_t *tp;
{
int outlen;
int res;
int order;
/*
* Make sure domain initialised
*/
if (!domain) {
int error = determine_nis_domain();
if (error)
return error;
}
/*
* Check if map has changed
*/
if (yp_order(domain, map, &order))
return EIO;
if ((time_t) order > *tp) {
*tp = (time_t) order;
return -1;
}
/*
* Lookup key
*/
res = yp_match(domain, map, key, strlen(key), val, &outlen);
/*
* Do something interesting with the return code
*/
switch (res) {
case 0:
return 0;
case YPERR_KEY:
return ENOENT;
default:
plog(XLOG_ERROR, "%s: %s", map, yperr_string(res));
return EIO;
}
}
int nis_init P((char *map, time_t *tp));
int nis_init(map, tp)
char *map;
time_t *tp;
{
int order;
if (!domain) {
int error = determine_nis_domain();
if (error)
return error;
}
/*
* To see if the map exists, try to find
* a master for it.
*/
if (yp_order(domain, map, &order))
return ENOENT;
*tp = (time_t) order;
#ifdef DEBUG
dlog("NIS master for %s@%s has order %d", map, domain, order);
#endif
return 0;
}
#endif /* HAS_NIS_MAPS */

View file

@ -0,0 +1,162 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)info_passwd.c 8.1 (Berkeley) 6/6/93
*
* $Id: info_passwd.c,v 5.2.2.1 1992/02/09 15:08:33 jsp beta $
*
*/
/*
* Get info from password "file"
*
* This is experimental and probably doesn't
* do what you expect.
*/
#include "am.h"
#ifdef HAS_PASSWD_MAPS
#include <pwd.h>
#define PASSWD_MAP "/etc/passwd"
/*
* Nothing to probe - check the map name is PASSWD_MAP.
*/
int passwd_init P((char *map, time_t *tp));
int passwd_init(map, tp)
char *map;
time_t *tp;
{
*tp = 0;
return strcmp(map, PASSWD_MAP) == 0 ? 0 : ENOENT;
}
/*
* Grab the entry via the getpwname routine
* Modify time is ignored by passwd - XXX
*/
int passwd_search P((mnt_map *m, char *map, char *key, char **pval, time_t *tp));
int passwd_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
char *dir = 0;
struct passwd *pw;
if (strcmp(key, "/defaults") == 0) {
*pval = strdup("type:=nfs");
return 0;
}
pw = getpwnam(key);
if (pw) {
/*
* We chop the home directory up as follows:
* /anydir/dom1/dom2/dom3/user
*
* and return
* rfs:=/anydir/dom3;rhost:=dom3.dom2.dom1;sublink:=user
*
* This allows cross-domain entries in your passwd file.
* ... but forget about security!
*/
char *user;
char *p, *q;
char val[MAXPATHLEN];
char rhost[MAXHOSTNAMELEN];
dir = strdup(pw->pw_dir);
/*
* Find user name. If no / then Invalid...
*/
user = strrchr(dir, '/');
if (!user)
goto enoent;
*user++ = '\0';
/*
* Find start of host "path". If no / then Invalid...
*/
p = strchr(dir+1, '/');
if (!p)
goto enoent;
*p++ = '\0';
/*
* At this point, p is dom1/dom2/dom3
* Copy, backwards, into rhost replacing
* / with .
*/
rhost[0] = '\0';
do {
q = strrchr(p, '/');
if (q) {
strcat(rhost, q + 1);
strcat(rhost, ".");
*q = '\0';
} else {
strcat(rhost, p);
}
} while (q);
/*
* Sanity check
*/
if (*rhost == '\0' || *user == '\0' || *dir == '\0')
goto enoent;
/*
* Make up return string
*/
q = strchr(rhost, '.');
if (q)
*q = '\0';
sprintf(val, "rfs:=%s/%s;rhost:=%s;sublink:=%s;fs:=${autodir}%s",
dir, rhost, rhost, user, pw->pw_dir);
if (q)
*q = '.';
*pval = strdup(val);
return 0;
}
enoent:
if (dir)
free(dir);
return ENOENT;
}
#endif /* HAS_PASSWD_MAPS */

View file

@ -0,0 +1,153 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)info_union.c 8.1 (Berkeley) 6/6/93
*
* $Id: info_union.c,v 5.2.2.1 1992/02/09 15:08:34 jsp beta $
*
*/
/*
* Get info from the system namespace
*
* NOTE: Cannot handle reads back through the automounter.
* THIS WILL CAUSE A DEADLOCK!
*/
#include "am.h"
#ifdef HAS_UNION_MAPS
#ifdef _POSIX_SOURCE
#include <dirent.h>
#define DIRENT struct dirent
#else
#include <sys/dir.h>
#define DIRENT struct direct
#endif
#define UNION_PREFIX "union:"
#define UNION_PREFLEN 6
/*
* No way to probe - check the map name begins with "union:"
*/
int union_init P((char *map, time_t *tp));
int union_init(map, tp)
char *map;
time_t *tp;
{
*tp = 0;
return strncmp(map, UNION_PREFIX, UNION_PREFLEN) == 0 ? 0 : ENOENT;
}
int union_search P((mnt_map *m, char *map, char *key, char **pval, time_t *tp));
int union_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
char *mapd = strdup(map + UNION_PREFLEN);
char **v = strsplit(mapd, ':', '\"');
char **p;
for (p = v; p[1]; p++)
;
*pval = xmalloc(strlen(*p) + 5);
sprintf(*pval, "fs:=%s", *p);
free(mapd);
free(v);
return 0;
}
int union_reload P((mnt_map *m, char *map, void (*fn)()));
int union_reload(m, map, fn)
mnt_map *m;
char *map;
void (*fn)();
{
char *mapd = strdup(map + UNION_PREFLEN);
char **v = strsplit(mapd, ':', '\"');
char **dir;
/*
* Add fake /defaults entry
*/
(*fn)(m, strdup("/defaults"), strdup("type:=link;opts:=nounmount;sublink:=${key}"));
for (dir = v; *dir; dir++) {
int dlen;
DIRENT *dp;
DIR *dirp = opendir(*dir);
if (!dirp) {
plog(XLOG_USER, "Cannot read directory %s: %m", *dir);
continue;
}
dlen = strlen(*dir);
#ifdef DEBUG
dlog("Reading directory %s...", *dir);
#endif
while (dp = readdir(dirp)) {
char *val;
if (dp->d_name[0] == '.' &&
(dp->d_name[1] == '\0' ||
(dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
continue;
#ifdef DEBUG
dlog("... gives %s", dp->d_name);
#endif
val = xmalloc(dlen + 5);
sprintf(val, "fs:=%s", *dir);
(*fn)(m, strdup(dp->d_name), val);
}
closedir(dirp);
}
/*
* Add wildcard entry
*/
{ char *val = xmalloc(strlen(dir[-1]) + 5);
sprintf(val, "fs:=%s", dir[-1]);
(*fn)(m, strdup("*"), val);
}
free(mapd);
free(v);
return 0;
}
#endif /* HAS_UNION_MAPS */

1140
usr.sbin/amd/amd/map.c Normal file

File diff suppressed because it is too large Load diff

914
usr.sbin/amd/amd/mapc.c Normal file
View file

@ -0,0 +1,914 @@
/*-
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mapc.c,v 5.2.2.1 1992/02/09 15:08:38 jsp beta $
*/
#ifndef lint
static char sccsid[] = "@(#)mapc.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
/*
* Mount map cache
*/
#include "am.h"
#ifdef HAS_REGEXP
#include RE_HDR
#endif
/*
* Hash table size
*/
#define NKVHASH (1 << 2) /* Power of two */
/*
* Wildcard key
*/
static char wildcard[] = "*";
/*
* Map cache types
* default, none, incremental, all, regexp
* MAPC_RE implies MAPC_ALL and must be numerically
* greater.
*/
#define MAPC_DFLT 0x000
#define MAPC_NONE 0x001
#define MAPC_INC 0x002
#define MAPC_ROOT 0x004
#define MAPC_ALL 0x010
#ifdef HAS_REGEXP
#define MAPC_RE 0x020
#define MAPC_ISRE(m) ((m)->alloc == MAPC_RE)
#else
#define MAPC_ISRE(m) FALSE
#endif
#define MAPC_CACHE_MASK 0x0ff
#define MAPC_SYNC 0x100
static struct opt_tab mapc_opt[] = {
{ "all", MAPC_ALL },
{ "default", MAPC_DFLT },
{ "inc", MAPC_INC },
{ "mapdefault", MAPC_DFLT },
{ "none", MAPC_NONE },
#ifdef HAS_REGEXP
{ "re", MAPC_RE },
{ "regexp", MAPC_RE },
#endif
{ "sync", MAPC_SYNC },
{ 0, 0 }
};
/*
* Lookup recursion
*/
#define MREC_FULL 2
#define MREC_PART 1
#define MREC_NONE 0
/*
* Cache map operations
*/
typedef void add_fn P((mnt_map*, char*, char*));
typedef int init_fn P((char*, time_t*));
typedef int search_fn P((mnt_map*, char*, char*, char**, time_t*));
typedef int reload_fn P((mnt_map*, char*, add_fn*));
typedef int mtime_fn P((char*, time_t*));
static void mapc_sync P((mnt_map*));
/*
* Map type
*/
typedef struct map_type map_type;
struct map_type {
char *name; /* Name of this map type */
init_fn *init; /* Initialisation */
reload_fn *reload; /* Reload or fill */
search_fn *search; /* Search for new entry */
mtime_fn *mtime; /* Find modify time */
int def_alloc; /* Default allocation mode */
};
/*
* Key-value pair
*/
typedef struct kv kv;
struct kv {
kv *next;
char *key;
char *val;
};
struct mnt_map {
qelem hdr;
int refc; /* Reference count */
short flags; /* Allocation flags */
short alloc; /* Allocation mode */
time_t modify; /* Modify time of map */
char *map_name; /* Name of this map */
char *wildcard; /* Wildcard value */
reload_fn *reload; /* Function to be used for reloads */
search_fn *search; /* Function to be used for searching */
mtime_fn *mtime; /* Modify time function */
kv *kvhash[NKVHASH]; /* Cached data */
};
/*
* Map for root node
*/
static mnt_map *root_map;
/*
* List of known maps
*/
extern qelem map_list_head;
qelem map_list_head = { &map_list_head, &map_list_head };
/*
* Configuration
*/
/* ROOT MAP */
static int root_init P((char*, time_t*));
/* FILE MAPS */
#ifdef HAS_FILE_MAPS
extern int file_init P((char*, time_t*));
extern int file_reload P((mnt_map*, char*, add_fn*));
extern int file_search P((mnt_map*, char*, char*, char**, time_t*));
extern int file_mtime P((char*, time_t*));
#endif /* HAS_FILE_MAPS */
/* Network Information Service (NIS) MAPS */
#ifdef HAS_NIS_MAPS
extern int nis_init P((char*, time_t*));
#ifdef HAS_NIS_RELOAD
extern int nis_reload P((mnt_map*, char*, add_fn*));
#else
#define nis_reload error_reload
#endif
extern int nis_search P((mnt_map*, char*, char*, char**, time_t*));
#define nis_mtime nis_init
#endif /* HAS_NIS_MAPS */
/* NDBM MAPS */
#ifdef HAS_NDBM_MAPS
#ifdef OS_HAS_NDBM
extern int ndbm_init P((char*, time_t*));
extern int ndbm_search P((mnt_map*, char*, char*, char**, time_t*));
#define ndbm_mtime ndbm_init
#endif /* OS_HAS_NDBM */
#endif /* HAS_NDBM_MAPS */
/* PASSWD MAPS */
#ifdef HAS_PASSWD_MAPS
extern int passwd_init P((char*, time_t*));
extern int passwd_search P((mnt_map*, char*, char*, char**, time_t*));
#endif /* HAS_PASSWD_MAPS */
/* HESIOD MAPS */
#ifdef HAS_HESIOD_MAPS
extern int hesiod_init P((char*, time_t*));
#ifdef HAS_HESIOD_RELOAD
extern int hesiod_reload P((mnt_map*, char*, add_fn*));
#else
#define hesiod_reload error_reload
#endif
extern int hesiod_search P((mnt_map*, char*, char*, char**, time_t*));
#endif /* HAS_HESIOD_MAPS */
/* UNION MAPS */
#ifdef HAS_UNION_MAPS
extern int union_init P((char*, time_t*));
extern int union_search P((mnt_map*, char*, char*, char**, time_t*));
extern int union_reload P((mnt_map*, char*, add_fn*));
#endif /* HAS_UNION_MAPS */
/* ERROR MAP */
static int error_init P((char*, time_t*));
static int error_reload P((mnt_map*, char*, add_fn*));
static int error_search P((mnt_map*, char*, char*, char**, time_t*));
static int error_mtime P((char*, time_t*));
static map_type maptypes[] = {
{ "root", root_init, error_reload, error_search, error_mtime, MAPC_ROOT },
#ifdef HAS_PASSWD_MAPS
{ "passwd", passwd_init, error_reload, passwd_search, error_mtime, MAPC_INC },
#endif
#ifdef HAS_HESIOD_MAPS
{ "hesiod", hesiod_init, hesiod_reload, hesiod_search, error_mtime, MAPC_ALL },
#endif
#ifdef HAS_UNION_MAPS
{ "union", union_init, union_reload, union_search, error_mtime, MAPC_ALL },
#endif
#ifdef HAS_NIS_MAPS
{ "nis", nis_init, nis_reload, nis_search, nis_mtime, MAPC_INC },
#endif
#ifdef HAS_NDBM_MAPS
{ "ndbm", ndbm_init, error_reload, ndbm_search, ndbm_mtime, MAPC_INC },
#endif
#ifdef HAS_FILE_MAPS
{ "file", file_init, file_reload, file_search, file_mtime, MAPC_ALL },
#endif
{ "error", error_init, error_reload, error_search, error_mtime, MAPC_NONE },
};
/*
* Hash function
*/
static unsigned int kvhash_of P((char *key));
static unsigned int kvhash_of(key)
char *key;
{
unsigned int i, j;
for (i = 0; j = *key++; i += j)
;
return i % NKVHASH;
}
void mapc_showtypes P((FILE *fp));
void mapc_showtypes(fp)
FILE *fp;
{
map_type *mt;
char *sep = "";
for (mt = maptypes; mt < maptypes+sizeof(maptypes)/sizeof(maptypes[0]); mt++) {
fprintf(fp, "%s%s", sep, mt->name);
sep = ", ";
}
}
static Const char *reg_error = "?";
void regerror P((Const char *m));
void regerror(m)
Const char *m;
{
reg_error = m;
}
/*
* Add key and val to the map m.
* key and val are assumed to be safe copies
*/
void mapc_add_kv P((mnt_map *m, char *key, char *val));
void mapc_add_kv(m, key, val)
mnt_map *m;
char *key;
char *val;
{
kv **h;
kv *n;
int hash = kvhash_of(key);
#ifdef DEBUG
dlog("add_kv: %s -> %s", key, val);
#endif
#ifdef HAS_REGEXP
if (MAPC_ISRE(m)) {
char keyb[MAXPATHLEN];
regexp *re;
/*
* Make sure the string is bound to the start and end
*/
sprintf(keyb, "^%s$", key);
re = regcomp(keyb);
if (re == 0) {
plog(XLOG_USER, "error compiling RE \"%s\": %s", keyb, reg_error);
return;
} else {
free(key);
key = (char *) re;
}
}
#endif
h = &m->kvhash[hash];
n = ALLOC(kv);
n->key = key;
n->val = val;
n->next = *h;
*h = n;
}
void mapc_repl_kv P((mnt_map *m, char *key, char *val));
void mapc_repl_kv(m, key, val)
mnt_map *m;
char *key;
char *val;
{
kv *k;
/*
* Compute the hash table offset
*/
k = m->kvhash[kvhash_of(key)];
/*
* Scan the linked list for the key
*/
while (k && !FSTREQ(k->key, key))
k = k->next;
if (k) {
free(k->val);
k->val = val;
} else {
mapc_add_kv(m, key, val);
}
}
/*
* Search a map for a key.
* Calls map specific search routine.
* While map is out of date, keep re-syncing.
*/
static int search_map P((mnt_map *m, char *key, char **valp));
static int search_map(m, key, valp)
mnt_map *m;
char *key;
char **valp;
{
int rc;
do {
rc = (*m->search)(m, m->map_name, key, valp, &m->modify);
if (rc < 0) {
plog(XLOG_MAP, "Re-synchronizing cache for map %s", m->map_name);
mapc_sync(m);
}
} while (rc < 0);
return rc;
}
/*
* Do a wildcard lookup in the map and
* save the result.
*/
static void mapc_find_wildcard P((mnt_map *m));
static void mapc_find_wildcard(m)
mnt_map *m;
{
/*
* Attempt to find the wildcard entry
*/
int rc = search_map(m, wildcard, &m->wildcard);
if (rc != 0)
m->wildcard = 0;
}
/*
* Make a duplicate reference to an existing map
*/
#define mapc_dup(m) ((m)->refc++, (m))
/*
* Do a map reload
*/
static int mapc_reload_map(m)
mnt_map *m;
{
int error;
#ifdef DEBUG
dlog("calling map reload on %s", m->map_name);
#endif
error = (*m->reload)(m, m->map_name, mapc_add_kv);
if (error)
return error;
m->wildcard = 0;
#ifdef DEBUG
dlog("calling mapc_search for wildcard");
#endif
error = mapc_search(m, wildcard, &m->wildcard);
if (error)
m->wildcard = 0;
return 0;
}
/*
* Create a new map
*/
static mnt_map *mapc_create P((char *map, char *opt));
static mnt_map *mapc_create(map, opt)
char *map;
char *opt;
{
mnt_map *m = ALLOC(mnt_map);
map_type *mt;
time_t modify;
int alloc = 0;
(void) cmdoption(opt, mapc_opt, &alloc);
for (mt = maptypes; mt < maptypes+sizeof(maptypes)/sizeof(maptypes[0]); mt++)
if ((*mt->init)(map, &modify) == 0)
break;
/* assert: mt in maptypes */
m->flags = alloc & ~MAPC_CACHE_MASK;
alloc &= MAPC_CACHE_MASK;
if (alloc == MAPC_DFLT)
alloc = mt->def_alloc;
switch (alloc) {
default:
plog(XLOG_USER, "Ambiguous map cache type \"%s\"; using \"inc\"", opt);
alloc = MAPC_INC;
/* fallthrough... */
case MAPC_NONE:
case MAPC_INC:
case MAPC_ROOT:
break;
case MAPC_ALL:
/*
* If there is no support for reload and it was requested
* then back off to incremental instead.
*/
if (mt->reload == error_reload) {
plog(XLOG_WARNING, "Map type \"%s\" does not support cache type \"all\"; using \"inc\"", mt->name);
alloc = MAPC_INC;
}
break;
#ifdef HAS_REGEXP
case MAPC_RE:
if (mt->reload == error_reload) {
plog(XLOG_WARNING, "Map type \"%s\" does not support cache type \"re\"", mt->name);
mt = &maptypes[sizeof(maptypes)/sizeof(maptypes[0]) - 1];
/* assert: mt->name == "error" */
}
break;
#endif
}
#ifdef DEBUG
dlog("Map for %s coming from maptype %s", map, mt->name);
#endif
m->alloc = alloc;
m->reload = mt->reload;
m->modify = modify;
m->search = alloc >= MAPC_ALL ? error_search : mt->search;
m->mtime = mt->mtime;
bzero((voidp) m->kvhash, sizeof(m->kvhash));
m->map_name = strdup(map);
m->refc = 1;
m->wildcard = 0;
/*
* synchronize cache with reality
*/
mapc_sync(m);
return m;
}
/*
* Free the cached data in a map
*/
static void mapc_clear P((mnt_map *m));
static void mapc_clear(m)
mnt_map *m;
{
int i;
/*
* For each of the hash slots, chain
* along free'ing the data.
*/
for (i = 0; i < NKVHASH; i++) {
kv *k = m->kvhash[i];
while (k) {
kv *n = k->next;
free((voidp) k->key);
if (k->val)
free((voidp) k->val);
free((voidp) k);
k = n;
}
}
/*
* Zero the hash slots
*/
bzero((voidp) m->kvhash, sizeof(m->kvhash));
/*
* Free the wildcard if it exists
*/
if (m->wildcard) {
free(m->wildcard);
m->wildcard = 0;
}
}
/*
* Find a map, or create one if it does not exist
*/
mnt_map *mapc_find P((char *map, char *opt));
mnt_map *mapc_find(map, opt)
char *map;
char *opt;
{
mnt_map *m;
/*
* Search the list of known maps to see if
* it has already been loaded. If it is found
* then return a duplicate reference to it.
* Otherwise make a new map as required and
* add it to the list of maps
*/
ITER(m, mnt_map, &map_list_head)
if (STREQ(m->map_name, map))
return mapc_dup(m);
m = mapc_create(map, opt);
ins_que(&m->hdr, &map_list_head);
return m;
}
/*
* Free a map.
*/
void mapc_free P((mnt_map *m));
void mapc_free(m)
mnt_map *m;
{
/*
* Decrement the reference count.
* If the reference count hits zero
* then throw the map away.
*/
if (m && --m->refc == 0) {
mapc_clear(m);
free((voidp) m->map_name);
rem_que(&m->hdr);
free((voidp) m);
}
}
/*
* Search the map for the key.
* Put a safe copy in *pval or return
* an error code
*/
int mapc_meta_search P((mnt_map *m, char *key, char **pval, int recurse));
int mapc_meta_search(m, key, pval, recurse)
mnt_map *m;
char *key;
char **pval;
int recurse;
{
int error = 0;
kv *k = 0;
/*
* Firewall
*/
if (!m) {
plog(XLOG_ERROR, "Null map request for %s", key);
return ENOENT;
}
if (m->flags & MAPC_SYNC) {
/*
* Get modify time...
*/
time_t t;
error = (*m->mtime)(m->map_name, &t);
if (error || t > m->modify) {
m->modify = t;
plog(XLOG_INFO, "Map %s is out of date", m->map_name);
mapc_sync(m);
}
}
if (!MAPC_ISRE(m)) {
/*
* Compute the hash table offset
*/
k = m->kvhash[kvhash_of(key)];
/*
* Scan the linked list for the key
*/
while (k && !FSTREQ(k->key, key)) k = k->next;
}
#ifdef HAS_REGEXP
else if (recurse == MREC_FULL) {
/*
* Try for an RE match against the entire map.
* Note that this will be done in a "random"
* order.
*/
int i;
for (i = 0; i < NKVHASH; i++) {
k = m->kvhash[i];
while (k) {
if (regexec((regexp *) k->key, key))
break;
k = k->next;
}
if (k)
break;
}
}
#endif
/*
* If found then take a copy
*/
if (k) {
if (k->val)
*pval = strdup(k->val);
else
error = ENOENT;
} else if (m->alloc >= MAPC_ALL) {
/*
* If the entire map is cached then this
* key does not exist.
*/
error = ENOENT;
} else {
/*
* Otherwise search the map. If we are
* in incremental mode then add the key
* to the cache.
*/
error = search_map(m, key, pval);
if (!error && m->alloc == MAPC_INC)
mapc_add_kv(m, strdup(key), strdup(*pval));
}
/*
* If an error, and a wildcard exists,
* and the key is not internal then
* return a copy of the wildcard.
*/
if (error > 0) {
if (recurse == MREC_FULL && !MAPC_ISRE(m)) {
char wildname[MAXPATHLEN];
char *subp;
if (*key == '/')
return error;
/*
* Keep chopping sub-directories from the RHS
* and replacing with "/ *" and repeat the lookup.
* For example:
* "src/gnu/gcc" -> "src / gnu / *" -> "src / *"
*/
strcpy(wildname, key);
while (error && (subp = strrchr(wildname, '/'))) {
strcpy(subp, "/*");
#ifdef DEBUG
dlog("mapc recurses on %s", wildname);
#endif
error = mapc_meta_search(m, wildname, pval, MREC_PART);
if (error)
*subp = 0;
}
if (error > 0 && m->wildcard) {
*pval = strdup(m->wildcard);
error = 0;
}
}
}
return error;
}
int mapc_search P((mnt_map *m, char *key, char **pval));
int mapc_search(m, key, pval)
mnt_map *m;
char *key;
char **pval;
{
return mapc_meta_search(m, key, pval, MREC_FULL);
}
/*
* Get map cache in sync with physical representation
*/
static void mapc_sync P((mnt_map *m));
static void mapc_sync(m)
mnt_map *m;
{
if (m->alloc != MAPC_ROOT) {
mapc_clear(m);
if (m->alloc >= MAPC_ALL)
if (mapc_reload_map(m))
m->alloc = MAPC_INC;
/*
* Attempt to find the wildcard entry
*/
if (m->alloc < MAPC_ALL)
mapc_find_wildcard(m);
}
}
/*
* Reload all the maps
* Called when Amd gets hit by a SIGHUP.
*/
void mapc_reload(P_void);
void mapc_reload()
{
mnt_map *m;
/*
* For all the maps,
* Throw away the existing information.
* Do a reload
* Find the wildcard
*/
ITER(m, mnt_map, &map_list_head)
mapc_sync(m);
}
/*
* Root map.
* The root map is used to bootstrap amd.
* All the require top-level mounts are added
* into the root map and then the map is iterated
* and a lookup is done on all the mount points.
* This causes the top level mounts to be automounted.
*/
static int root_init P((char *map, time_t *tp));
static int root_init(map, tp)
char *map;
time_t *tp;
{
*tp = clocktime();
return strcmp(map, ROOT_MAP) == 0 ? 0 : ENOENT;
}
/*
* Add a new entry to the root map
*
* dir - directory (key)
* opts - mount options
* map - map name
*/
void root_newmap P((char *dir, char *opts, char *map));
void root_newmap(dir, opts, map)
char *dir;
char *opts;
char *map;
{
char str[MAXPATHLEN];
/*
* First make sure we have a root map to talk about...
*/
if (!root_map)
root_map = mapc_find(ROOT_MAP, "mapdefault");
/*
* Then add the entry...
*/
dir = strdup(dir);
if (map)
sprintf(str, "cache:=mapdefault;type:=toplvl;fs:=\"%s\";%s",
map, opts ? opts : "");
else
strcpy(str, opts);
mapc_repl_kv(root_map, dir, strdup(str));
}
int mapc_keyiter P((mnt_map *m, void (*fn)(char*,voidp), voidp arg));
int mapc_keyiter(m, fn, arg)
mnt_map *m;
void (*fn)P((char*, voidp));
voidp arg;
{
int i;
int c = 0;
for (i = 0; i < NKVHASH; i++) {
kv *k = m->kvhash[i];
while (k) {
(*fn)(k->key, arg);
k = k->next;
c++;
}
}
return c;
}
/*
* Iterate of the the root map
* and call (*fn)() on the key
* of all the nodes.
* Finally throw away the root map.
*/
int root_keyiter P((void (*fn)(char*,voidp), voidp arg));
int root_keyiter(fn, arg)
void (*fn)P((char*,voidp));
voidp arg;
{
if (root_map) {
int c = mapc_keyiter(root_map, fn, arg);
#ifdef notdef
mapc_free(root_map);
root_map = 0;
#endif
return c;
}
return 0;
}
/*
* Error map
*/
static int error_init P((char *map, time_t *tp));
static int error_init(map, tp)
char *map;
time_t *tp;
{
plog(XLOG_USER, "No source data for map %s", map);
*tp = 0;
return 0;
}
/*ARGSUSED*/
static int error_search P((mnt_map *m, char *map, char *key, char **pval, time_t *tp));
static int error_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
return ENOENT;
}
/*ARGSUSED*/
static int error_reload P((mnt_map *m, char *map, add_fn *fn));
static int error_reload(m, map, fn)
mnt_map *m;
char *map;
add_fn *fn;
{
return ENOENT;
}
static int error_mtime P((char *map, time_t *tp));
static int error_mtime(map, tp)
char *map;
time_t *tp;
{
*tp = 0;
return 0;
}

333
usr.sbin/amd/amd/misc_rpc.c Normal file
View file

@ -0,0 +1,333 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc_rpc.c 8.1 (Berkeley) 6/6/93
*
* $Id: misc_rpc.c,v 5.2.2.1 1992/02/09 15:08:40 jsp beta $
*
*/
/*
* Additions to Sun RPC.
*/
#include "am.h"
void rpc_msg_init P((struct rpc_msg *mp, u_long prog, u_long vers, u_long proc));
void rpc_msg_init(mp, prog, vers, proc)
struct rpc_msg *mp;
unsigned long prog, vers, proc;
{
/*
* Initialise the message
*/
bzero((voidp) mp, sizeof(*mp));
mp->rm_xid = 0;
mp->rm_direction = CALL;
mp->rm_call.cb_rpcvers = RPC_MSG_VERSION;
mp->rm_call.cb_prog = prog;
mp->rm_call.cb_vers = vers;
mp->rm_call.cb_proc = proc;
}
/*
* Field reply to call to mountd
*/
int pickup_rpc_reply P((voidp pkt, int len, voidp where, xdrproc_t where_xdr));
int pickup_rpc_reply(pkt, len, where, where_xdr)
voidp pkt;
int len;
voidp where;
xdrproc_t where_xdr;
{
XDR reply_xdr;
int ok;
struct rpc_err err;
struct rpc_msg reply_msg;
int error = 0;
/*bzero((voidp) &err, sizeof(err));*/
bzero((voidp) &reply_msg, sizeof(reply_msg));
reply_msg.acpted_rply.ar_results.where = (caddr_t) where;
reply_msg.acpted_rply.ar_results.proc = where_xdr;
xdrmem_create(&reply_xdr, pkt, len, XDR_DECODE);
ok = xdr_replymsg(&reply_xdr, &reply_msg);
if (!ok) {
error = EIO;
goto drop;
}
_seterr_reply(&reply_msg, &err);
if (err.re_status != RPC_SUCCESS) {
error = EIO;
goto drop;
}
drop:
if (reply_msg.rm_reply.rp_stat == MSG_ACCEPTED &&
reply_msg.acpted_rply.ar_verf.oa_base) {
reply_xdr.x_op = XDR_FREE;
(void)xdr_opaque_auth(&reply_xdr,
&reply_msg.acpted_rply.ar_verf);
}
xdr_destroy(&reply_xdr);
return error;
}
int make_rpc_packet P((char *buf, int buflen, unsigned long proc,
struct rpc_msg *mp, voidp arg, xdrproc_t arg_xdr, AUTH *auth));
int make_rpc_packet(buf, buflen, proc, mp, arg, arg_xdr, auth)
char *buf;
int buflen;
unsigned long proc;
struct rpc_msg *mp;
voidp arg;
xdrproc_t arg_xdr;
AUTH *auth;
{
XDR msg_xdr;
int len;
xdrmem_create(&msg_xdr, buf, buflen, XDR_ENCODE);
/*
* Basic protocol header
*/
if (!xdr_callhdr(&msg_xdr, mp))
return -EIO;
/*
* Called procedure number
*/
if (!xdr_enum(&msg_xdr, &proc))
return -EIO;
/*
* Authorization
*/
if (!AUTH_MARSHALL(auth, &msg_xdr))
return -EIO;
/*
* Arguments
*/
if (!(*arg_xdr)(&msg_xdr, arg))
return -EIO;
/*
* Determine length
*/
len = xdr_getpos(&msg_xdr);
/*
* Throw away xdr
*/
xdr_destroy(&msg_xdr);
return len;
}
/*
* Early RPC seems to be missing these..
* Extracted from the RPC 3.9 sources as indicated
*/
#ifdef NEED_XDR_POINTER
/* @(#)xdr_reference.c 1.1 87/11/04 3.9 RPCSRC */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* xdr_pointer():
*
* XDR a pointer to a possibly recursive data structure. This
* differs with xdr_reference in that it can serialize/deserialiaze
* trees correctly.
*
* What's sent is actually a union:
*
* union object_pointer switch (boolean b) {
* case TRUE: object_data data;
* case FALSE: void nothing;
* }
*
* > objpp: Pointer to the pointer to the object.
* > obj_size: size of the object.
* > xdr_obj: routine to XDR an object.
*
*/
bool_t
xdr_pointer(xdrs,objpp,obj_size,xdr_obj)
register XDR *xdrs;
char **objpp;
u_int obj_size;
xdrproc_t xdr_obj;
{
bool_t more_data;
more_data = (*objpp != NULL);
if (! xdr_bool(xdrs,&more_data)) {
return (FALSE);
}
if (! more_data) {
*objpp = NULL;
return (TRUE);
}
return (xdr_reference(xdrs,objpp,obj_size,xdr_obj));
}
#endif /* NEED_XDR_POINTER */
#ifdef NEED_CLNT_SPERRNO
/* @(#)clnt_perror.c 1.1 87/11/04 3.9 RPCSRC */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
struct rpc_errtab {
enum clnt_stat status;
char *message;
};
static struct rpc_errtab rpc_errlist[] = {
{ RPC_SUCCESS,
"RPC: Success" },
{ RPC_CANTENCODEARGS,
"RPC: Can't encode arguments" },
{ RPC_CANTDECODERES,
"RPC: Can't decode result" },
{ RPC_CANTSEND,
"RPC: Unable to send" },
{ RPC_CANTRECV,
"RPC: Unable to receive" },
{ RPC_TIMEDOUT,
"RPC: Timed out" },
{ RPC_VERSMISMATCH,
"RPC: Incompatible versions of RPC" },
{ RPC_AUTHERROR,
"RPC: Authentication error" },
{ RPC_PROGUNAVAIL,
"RPC: Program unavailable" },
{ RPC_PROGVERSMISMATCH,
"RPC: Program/version mismatch" },
{ RPC_PROCUNAVAIL,
"RPC: Procedure unavailable" },
{ RPC_CANTDECODEARGS,
"RPC: Server can't decode arguments" },
{ RPC_SYSTEMERROR,
"RPC: Remote system error" },
{ RPC_UNKNOWNHOST,
"RPC: Unknown host" },
/* { RPC_UNKNOWNPROTO,
"RPC: Unknown protocol" },*/
{ RPC_PMAPFAILURE,
"RPC: Port mapper failure" },
{ RPC_PROGNOTREGISTERED,
"RPC: Program not registered"},
{ RPC_FAILED,
"RPC: Failed (unspecified error)"}
};
/*
* This interface for use by clntrpc
*/
char *
clnt_sperrno(stat)
enum clnt_stat stat;
{
int i;
for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
if (rpc_errlist[i].status == stat) {
return (rpc_errlist[i].message);
}
}
return ("RPC: (unknown error code)");
}
#endif /* NEED_CLNT_SPERRNO */

367
usr.sbin/amd/amd/mntfs.c Normal file
View file

@ -0,0 +1,367 @@
/*-
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mntfs.c,v 5.2.2.1 1992/02/09 15:08:42 jsp beta $
*/
#ifndef lint
static char sccsid[] = "@(#)mntfs.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "am.h"
extern qelem mfhead;
qelem mfhead = { &mfhead, &mfhead };
int mntfs_allocated;
#ifdef notdef
/*
* This is the default attributes field which
* is copied into every new node to be created.
* The individual filesystem fs_init() routines
* patch the copy to represent the particular
* details for the relevant filesystem type
*/
static struct fattr gen_fattr = {
NFDIR, /* type */
NFSMODE_DIR | 0555, /* mode */
2, /* nlink */
0, /* uid */
0, /* gid */
512, /* size */
4096, /* blocksize */
0, /* rdev */
1, /* blocks */
0, /* fsid */
0, /* fileid */
{ 0, 0 }, /* atime */
{ 0, 0 }, /* mtime */
{ 0, 0 }, /* ctime */
};
#endif /* notdef */
mntfs *dup_mntfs(mf)
mntfs *mf;
{
if (mf->mf_refc == 0) {
if (mf->mf_cid)
untimeout(mf->mf_cid);
mf->mf_cid = 0;
#ifdef notdef
mf->mf_error = -1;
mf->mf_flags &= ~MFF_ERROR;
#endif
}
mf->mf_refc++;
return mf;
}
static void init_mntfs P((mntfs *mf, am_ops *ops, am_opts *mo, char *mp, char *info, char *auto_opts, char *mopts, char *remopts));
static void init_mntfs(mf, ops, mo, mp, info, auto_opts, mopts, remopts)
mntfs *mf;
am_ops *ops;
am_opts *mo;
char *mp;
char *info;
char *auto_opts;
char *mopts;
char *remopts;
{
mf->mf_ops = ops;
mf->mf_fo = mo;
mf->mf_mount = strdup(mp);
mf->mf_info = strdup(info);
mf->mf_auto = strdup(auto_opts);
mf->mf_mopts = strdup(mopts);
mf->mf_remopts = strdup(remopts);
mf->mf_refc = 1;
mf->mf_flags = 0;
mf->mf_error = -1;
mf->mf_cid = 0;
mf->mf_private = 0;
mf->mf_prfree = 0;
#ifdef notdef
mf->mf_attr.status = NFS_OK;
mf->mf_fattr = gen_fattr;
mf->mf_fattr.fsid = 42;
mf->mf_fattr.fileid = 0;
mf->mf_fattr.atime.seconds = clocktime();
mf->mf_fattr.atime.useconds = 0;
mf->mf_fattr.mtime = mf->mf_fattr.ctime = mf->mf_fattr.atime;
#endif
if (ops->ffserver)
mf->mf_server = (*ops->ffserver)(mf);
else
mf->mf_server = 0;
}
static mntfs *alloc_mntfs P((am_ops *ops, am_opts *mo, char *mp, char *info, char *auto_opts, char *mopts, char *remopts));
static mntfs *alloc_mntfs(ops, mo, mp, info, auto_opts, mopts, remopts)
am_ops *ops;
am_opts *mo;
char *mp;
char *info;
char *auto_opts;
char *mopts;
char *remopts;
{
mntfs *mf = ALLOC(mntfs);
init_mntfs(mf, ops, mo, mp, info, auto_opts, mopts, remopts);
ins_que(&mf->mf_q, &mfhead);
mntfs_allocated++;
return mf;
}
mntfs *find_mntfs P((am_ops *ops, am_opts *mo, char *mp, char *info, char *auto_opts, char *mopts, char *remopts));
mntfs *find_mntfs(ops, mo, mp, info, auto_opts, mopts, remopts)
am_ops *ops;
am_opts *mo;
char *mp;
char *info;
char *auto_opts;
char *mopts;
char *remopts;
{
mntfs *mf;
#ifdef DEBUG
dlog("Locating mntfs reference to %s", mp);
#endif /* DEBUG */
ITER(mf, mntfs, &mfhead) {
if (STREQ(mf->mf_mount, mp)) {
/*
* Handle cases where error ops are involved
*/
if (ops == &efs_ops) {
/*
* If the existing ops are not efs_ops
* then continue...
*/
if (mf->mf_ops != &efs_ops)
continue;
} else /* ops != &efs_ops */ {
/*
* If the existing ops are efs_ops
* then continue...
*/
if (mf->mf_ops == &efs_ops)
continue;
}
if ((mf->mf_flags & MFF_RESTART) && amd_state == Run) {
/*
* Restart a previously mounted filesystem.
*/
mntfs *mf2 = alloc_mntfs(&ifs_ops, mo, mp, info, auto_opts, mopts, remopts);
#ifdef DEBUG
dlog("Restarting filesystem %s", mf->mf_mount);
#endif /* DEBUG */
/*
* Remember who we are restarting
*/
mf2->mf_private = (voidp) dup_mntfs(mf);
mf2->mf_prfree = free_mntfs;
return mf2;
}
mf->mf_fo = mo;
if (!(mf->mf_flags & (MFF_MOUNTED|MFF_MOUNTING|MFF_UNMOUNTING))) {
fserver *fs;
mf->mf_flags &= ~MFF_ERROR;
mf->mf_error = -1;
mf->mf_auto = strealloc(mf->mf_auto, auto_opts);
mf->mf_mopts = strealloc(mf->mf_mopts, mopts);
mf->mf_remopts = strealloc(mf->mf_remopts, remopts);
mf->mf_info = strealloc(mf->mf_info, info);
if (mf->mf_private && mf->mf_prfree) {
(*mf->mf_prfree)(mf->mf_private);
mf->mf_private = 0;
}
fs = ops->ffserver ? (*ops->ffserver)(mf) : (fserver *) 0;
if (mf->mf_server)
free_srvr(mf->mf_server);
mf->mf_server = fs;
}
return dup_mntfs(mf);
}
}
return alloc_mntfs(ops, mo, mp, info, auto_opts, mopts, remopts);
}
mntfs *new_mntfs()
{
return alloc_mntfs(&efs_ops, (am_opts *) 0, "//nil//", ".", "", "", "");
}
static void uninit_mntfs(mf, rmd)
mntfs *mf;
int rmd;
{
if (mf->mf_mount) free((voidp) mf->mf_mount);
if (mf->mf_auto) free((voidp) mf->mf_auto);
if (mf->mf_mopts) free((voidp) mf->mf_mopts);
if (mf->mf_remopts) free((voidp) mf->mf_remopts);
if (mf->mf_info) free((voidp) mf->mf_info);
if (mf->mf_private && mf->mf_prfree)
(*mf->mf_prfree)(mf->mf_private);
/*
* Clean up any directories that were made
*/
if (rmd && (mf->mf_flags & MFF_MKMNT))
rmdirs(mf->mf_mount);
/*
* Clean up the file server
*/
if (mf->mf_server)
free_srvr(mf->mf_server);
/*
* Don't do a callback on this mount
*/
if (mf->mf_cid) {
untimeout(mf->mf_cid);
mf->mf_cid = 0;
}
}
static void discard_mntfs(mf)
mntfs *mf;
{
rem_que(&mf->mf_q);
/*
* Free memory
*/
uninit_mntfs(mf, TRUE);
free((voidp) mf);
--mntfs_allocated;
}
void flush_mntfs()
{
mntfs *mf;
mf = FIRST(mntfs, &mfhead);
while (mf != HEAD(mntfs, &mfhead)) {
mntfs *mf2 = mf;
mf = NEXT(mntfs, mf);
if (mf2->mf_refc == 0 && mf2->mf_cid)
discard_mntfs(mf2);
}
}
void free_mntfs(mf)
mntfs *mf;
{
if (--mf->mf_refc == 0) {
if (mf->mf_flags & MFF_MOUNTED) {
int quoted;
mf->mf_flags &= ~MFF_MOUNTED;
/*
* Record for posterity
*/
quoted = strchr(mf->mf_info, ' ') != 0; /* cheap */
plog(XLOG_INFO, "%s%s%s %sed fstype %s from %s",
quoted ? "\"" : "",
mf->mf_info,
quoted ? "\"" : "",
mf->mf_error ? "discard" : "unmount",
mf->mf_ops->fs_type, mf->mf_mount);
}
if (mf->mf_ops->fs_flags & FS_DISCARD) {
#ifdef DEBUG
dlog("Immediately discarding mntfs for %s", mf->mf_mount);
#endif /* DEBUG */
discard_mntfs(mf);
} else {
#ifdef DEBUG
if (mf->mf_flags & MFF_RESTART) {
dlog("Discarding remount hook for %s", mf->mf_mount);
} else {
dlog("Discarding last mntfs reference to %s fstype %s",
mf->mf_mount, mf->mf_ops->fs_type);
}
if (mf->mf_flags & (MFF_MOUNTED|MFF_MOUNTING|MFF_UNMOUNTING))
dlog("mntfs reference for %s still active", mf->mf_mount);
#endif /* DEBUG */
mf->mf_cid = timeout(ALLOWED_MOUNT_TIME, discard_mntfs, (voidp) mf);
}
}
}
mntfs *realloc_mntfs P((mntfs *mf, am_ops *ops, am_opts *mo, char *mp, char *info, char *auto_opts, char *mopts, char *remopts));
mntfs *realloc_mntfs(mf, ops, mo, mp, info, auto_opts, mopts, remopts)
mntfs *mf;
am_ops *ops;
am_opts *mo;
char *mp;
char *info;
char *auto_opts;
char *mopts;
char *remopts;
{
mntfs *mf2;
if (mf->mf_refc == 1 && mf->mf_ops == &ifs_ops && STREQ(mf->mf_mount, mp)) {
/*
* If we are inheriting then just return
* the same node...
*/
return mf;
}
/*
* Re-use the existing mntfs if it is mounted.
* This traps a race in nfsx.
*/
if (mf->mf_ops != &efs_ops &&
(mf->mf_flags & MFF_MOUNTED) &&
!FSRV_ISDOWN(mf->mf_server)) {
mf->mf_fo = mo;
return mf;
}
mf2 = find_mntfs(ops, mo, mp, info, auto_opts, mopts, remopts);
free_mntfs(mf);
return mf2;
}

273
usr.sbin/amd/amd/mount_fs.c Normal file
View file

@ -0,0 +1,273 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mount_fs.c 8.1 (Berkeley) 6/6/93
*
* $Id: mount_fs.c,v 5.2.2.2 1992/05/31 16:35:45 jsp Exp $
*
*/
#include "am.h"
#ifdef NFS_3
typedef nfs_fh fhandle_t;
#endif /* NFS_3 */
#include <sys/mount.h>
#include <sys/stat.h>
/*
* Standard mount flags
*/
#ifdef hpux
/*
* HP-UX has an annoying feature of printing
* error msgs on /dev/console
*/
#undef M_NOSUID
#endif /* hpux */
struct opt_tab mnt_flags[] = {
{ "ro", M_RDONLY },
#ifdef M_CACHE
{ "nocache", M_NOCACHE },
#endif /* M_CACHE */
#ifdef M_GRPID
{ "grpid", M_GRPID },
#endif /* M_GRPID */
#ifdef M_MULTI
{ "multi", M_MULTI },
#endif /* M_MULTI */
#ifdef M_NODEV
{ "nodev", M_NODEV },
#endif /* M_NODEV */
#ifdef M_NOEXEC
{ "noexec", M_NOEXEC },
#endif /* M_NOEXEC */
#ifdef M_NOSUB
{ "nosub", M_NOSUB },
#endif /* M_NOSUB */
#ifdef M_NOSUID
{ "nosuid", M_NOSUID },
#endif /* M_NOSUID */
#ifdef M_SYNC
{ "sync", M_SYNC },
#endif /* M_SYNC */
{ 0, 0 }
};
int compute_mount_flags(mnt)
struct mntent *mnt;
{
struct opt_tab *opt;
int flags;
#ifdef NFS_4
flags = M_NEWTYPE;
#else
flags = 0;
#endif /* NFS_4 */
/*
* Crack basic mount options
*/
for (opt = mnt_flags; opt->opt; opt++)
flags |= hasmntopt(mnt, opt->opt) ? opt->flag : 0;
return flags;
}
int mount_fs P((struct mntent *mnt, int flags, caddr_t mnt_data, int retry, MTYPE_TYPE type));
int mount_fs(mnt, flags, mnt_data, retry, type)
struct mntent *mnt;
int flags;
caddr_t mnt_data;
int retry;
MTYPE_TYPE type;
{
int error = 0;
#ifdef MNTINFO_DEV
struct stat stb;
char *xopts = 0;
#endif /* MNTINFO_DEV */
#ifdef DEBUG
#ifdef NFS_4
dlog("%s fstype %s (%s) flags %#x (%s)",
mnt->mnt_dir, type, mnt->mnt_type, flags, mnt->mnt_opts);
#else
dlog("%s fstype %d (%s) flags %#x (%s)",
mnt->mnt_dir, type, mnt->mnt_type, flags, mnt->mnt_opts);
#endif /* NFS_4 */
#endif /* DEBUG */
/*
* Fake some mount table entries for the automounter
*/
#ifdef FASCIST_DF_COMMAND
/*
* Some systems have a df command which blows up when
* presented with an unknown mount type.
*/
if (STREQ(mnt->mnt_type, MNTTYPE_AUTO)) {
/*
* Try it with the normal name
*/
mnt->mnt_type = FASCIST_DF_COMMAND;
}
#endif /* FASCIST_DF_COMMAND */
again:
clock_valid = 0;
error = MOUNT_TRAP(type, mnt, flags, mnt_data);
if (error < 0)
plog(XLOG_ERROR, "%s: mount: %m", mnt->mnt_dir);
if (error < 0 && --retry > 0) {
sleep(1);
goto again;
}
if (error < 0) {
#ifdef notdef
if (automount)
going_down(errno);
#endif
return errno;
}
#ifdef UPDATE_MTAB
#ifdef MNTINFO_DEV
/*
* Add the extra dev= field to the mount table.
*/
if (lstat(mnt->mnt_dir, &stb) == 0) {
char *zopts = (char *) xmalloc(strlen(mnt->mnt_opts) + 32);
xopts = mnt->mnt_opts;
if (sizeof(stb.st_dev) == 2) {
/* e.g. SunOS 4.1 */
sprintf(zopts, "%s,%s=%s%04lx", xopts, MNTINFO_DEV,
MNTINFO_PREF, (u_long) stb.st_dev & 0xffff);
} else {
/* e.g. System Vr4 */
sprintf(zopts, "%s,%s=%s%08lx", xopts, MNTINFO_DEV,
MNTINFO_PREF, (u_long) stb.st_dev);
}
mnt->mnt_opts = zopts;
}
#endif /* MNTINFO_DEV */
#ifdef FIXUP_MNTENT
/*
* Additional fields in struct mntent
* are fixed up here
*/
FIXUP_MNTENT(mnt);
#endif
write_mntent(mnt);
#ifdef MNTINFO_DEV
if (xopts) {
free(mnt->mnt_opts);
mnt->mnt_opts = xopts;
}
#endif /* MNTINFO_DEV */
#endif /* UPDATE_MTAB */
return 0;
}
#ifdef NEED_MNTOPT_PARSER
/*
* Some systems don't provide these to the user,
* but amd needs them, so...
*
* From: Piete Brooks <pb@cl.cam.ac.uk>
*/
#include <ctype.h>
static char *nextmntopt(p)
char **p;
{
char *cp = *p;
char *rp;
/*
* Skip past white space
*/
while (*cp && isspace(*cp))
cp++;
/*
* Word starts here
*/
rp = cp;
/*
* Scan to send of string or separator
*/
while (*cp && *cp != ',')
cp++;
/*
* If separator found the overwrite with nul char.
*/
if (*cp) {
*cp = '\0';
cp++;
}
/*
* Return value for next call
*/
*p = cp;
return rp;
}
char *hasmntopt(mnt, opt)
struct mntent *mnt;
char *opt;
{
char t[MNTMAXSTR];
char *f;
char *o = t;
int l = strlen(opt);
strcpy(t, mnt->mnt_opts);
while (*(f = nextmntopt(&o)))
if (strncmp(opt, f, l) == 0)
return f - t + mnt->mnt_opts;
return 0;
}
#endif /* NEED_MNTOPT_PARSER */
#ifdef MOUNT_HELPER_SOURCE
#include MOUNT_HELPER_SOURCE
#endif /* MOUNT_HELPER_SOURCE */

108
usr.sbin/amd/amd/mtab.c Normal file
View file

@ -0,0 +1,108 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mtab.c 8.1 (Berkeley) 6/6/93
*
* $Id: mtab.c,v 5.2.2.1 1992/02/09 15:08:45 jsp beta $
*
*/
#include "am.h"
/*
* Firewall /etc/mtab entries
*/
void mnt_free P((struct mntent *mp));
void mnt_free(mp)
struct mntent *mp;
{
free(mp->mnt_fsname);
free(mp->mnt_dir);
free(mp->mnt_type);
free(mp->mnt_opts);
free((voidp) mp);
}
/*
* Discard memory allocated for mount list
*/
void discard_mntlist P((mntlist *mp));
void discard_mntlist(mp)
mntlist *mp;
{
mntlist *mp2;
while (mp2 = mp) {
mp = mp->mnext;
if (mp2->mnt)
mnt_free(mp2->mnt);
free((voidp) mp2);
}
}
/*
* Throw away a mount list
*/
void free_mntlist P((mntlist *mp));
void free_mntlist(mp)
mntlist *mp;
{
discard_mntlist(mp);
unlock_mntlist();
}
/*
* Utility routine which determines the value of a
* numeric option in the mount options (such as port=%d).
* Returns 0 if the option is not specified.
*/
int hasmntval P((struct mntent *mnt, char *opt));
int hasmntval(mnt, opt)
struct mntent *mnt;
char *opt;
{
char *str = hasmntopt(mnt, opt);
if (str) {
char *eq = strchr(str, '=');
if (eq)
return atoi(eq+1);
else
plog(XLOG_USER, "bad numeric option \"%s\" in \"%s\"", opt, str);
}
return 0;
}

809
usr.sbin/amd/amd/nfs_ops.c Normal file
View file

@ -0,0 +1,809 @@
/*-
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: nfs_ops.c,v 5.2.2.2 1992/05/31 16:35:05 jsp Exp $
*/
#ifndef lint
static char sccsid[] = "@(#)nfs_ops.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "am.h"
#include <sys/stat.h>
#ifdef HAS_NFS
#define NFS
#define NFSCLIENT
#ifdef NFS_3
typedef nfs_fh fhandle_t;
#endif /* NFS_3 */
#ifdef NFS_HDR
#include NFS_HDR
#endif /* NFS_HDR */
#include <sys/mount.h>
#include "mount.h"
/*
* Network file system
*/
/*
* Convert from nfsstat to UN*X error code
*/
#define unx_error(e) ((int)(e))
/*
* The NFS layer maintains a cache of file handles.
* This is *fundamental* to the implementation and
* also allows quick remounting when a filesystem
* is accessed soon after timing out.
*
* The NFS server layer knows to flush this cache
* when a server goes down so avoiding stale handles.
*
* Each cache entry keeps a hard reference to
* the corresponding server. This ensures that
* the server keepalive information is maintained.
*
* The copy of the sockaddr_in here is taken so
* that the port can be twiddled to talk to mountd
* instead of portmap or the NFS server as used
* elsewhere.
* The port# is flushed if a server goes down.
* The IP address is never flushed - we assume
* that the address of a mounted machine never
* changes. If it does, then you have other
* problems...
*/
typedef struct fh_cache fh_cache;
struct fh_cache {
qelem fh_q; /* List header */
voidp fh_wchan; /* Wait channel */
int fh_error; /* Valid data? */
int fh_id; /* Unique id */
int fh_cid; /* Callout id */
struct fhstatus fh_handle; /* Handle on filesystem */
struct sockaddr_in fh_sin; /* Address of mountd */
fserver *fh_fs; /* Server holding filesystem */
char *fh_path; /* Filesystem on host */
};
/*
* FH_TTL is the time a file handle will remain in the cache since
* last being used. If the file handle becomes invalid, then it
* will be flushed anyway.
*/
#define FH_TTL (5 * 60) /* five minutes */
#define FH_TTL_ERROR (30) /* 30 seconds */
static int fh_id = 0;
#define FHID_ALLOC() (++fh_id)
extern qelem fh_head;
qelem fh_head = { &fh_head, &fh_head };
static int call_mountd P((fh_cache*, unsigned long, fwd_fun, voidp));
AUTH *nfs_auth;
static fh_cache *find_nfs_fhandle_cache P((voidp idv, int done));
static fh_cache *find_nfs_fhandle_cache(idv, done)
voidp idv;
int done;
{
fh_cache *fp, *fp2 = 0;
int id = (int) idv;
ITER(fp, fh_cache, &fh_head) {
if (fp->fh_id == id) {
fp2 = fp;
break;
}
}
#ifdef DEBUG
if (fp2) {
dlog("fh cache gives fp %#x, fs %s", fp2, fp2->fh_path);
} else {
dlog("fh cache search failed");
}
#endif /* DEBUG */
if (fp2 && !done) {
fp2->fh_error = ETIMEDOUT;
return 0;
}
return fp2;
}
/*
* Called when a filehandle appears
*/
static void got_nfs_fh P((voidp pkt, int len, struct sockaddr_in *sa,
struct sockaddr_in *ia, voidp idv, int done));
static void got_nfs_fh(pkt, len, sa, ia, idv, done)
voidp pkt;
int len;
struct sockaddr_in *sa, *ia;
voidp idv;
int done;
{
fh_cache *fp = find_nfs_fhandle_cache(idv, done);
if (fp) {
fp->fh_error = pickup_rpc_reply(pkt, len, (voidp) &fp->fh_handle, xdr_fhstatus);
if (!fp->fh_error) {
#ifdef DEBUG
dlog("got filehandle for %s:%s", fp->fh_fs->fs_host, fp->fh_path);
#endif /* DEBUG */
/*
* Wakeup anything sleeping on this filehandle
*/
if (fp->fh_wchan) {
#ifdef DEBUG
dlog("Calling wakeup on %#x", fp->fh_wchan);
#endif /* DEBUG */
wakeup(fp->fh_wchan);
}
}
}
}
void flush_nfs_fhandle_cache P((fserver *fs));
void flush_nfs_fhandle_cache(fs)
fserver *fs;
{
fh_cache *fp;
ITER(fp, fh_cache, &fh_head) {
if (fp->fh_fs == fs || fs == 0) {
fp->fh_sin.sin_port = (u_short) 0;
fp->fh_error = -1;
}
}
}
static void discard_fh P((fh_cache *fp));
static void discard_fh(fp)
fh_cache *fp;
{
rem_que(&fp->fh_q);
#ifdef DEBUG
dlog("Discarding filehandle for %s:%s", fp->fh_fs->fs_host, fp->fh_path);
#endif /* DEBUG */
free_srvr(fp->fh_fs);
free((voidp) fp->fh_path);
free((voidp) fp);
}
/*
* Determine the file handle for a node
*/
static int prime_nfs_fhandle_cache P((char *path, fserver *fs, struct fhstatus *fhbuf, voidp wchan));
static int prime_nfs_fhandle_cache(path, fs, fhbuf, wchan)
char *path;
fserver *fs;
struct fhstatus *fhbuf;
voidp wchan;
{
fh_cache *fp, *fp_save = 0;
int error;
int reuse_id = FALSE;
#ifdef DEBUG
dlog("Searching cache for %s:%s", fs->fs_host, path);
#endif /* DEBUG */
/*
* First search the cache
*/
ITER(fp, fh_cache, &fh_head) {
if (fs == fp->fh_fs && strcmp(path, fp->fh_path) == 0) {
switch (fp->fh_error) {
case 0:
error = fp->fh_error = unx_error(fp->fh_handle.fhs_status);
if (error == 0) {
if (fhbuf)
bcopy((voidp) &fp->fh_handle, (voidp) fhbuf,
sizeof(fp->fh_handle));
if (fp->fh_cid)
untimeout(fp->fh_cid);
fp->fh_cid = timeout(FH_TTL, discard_fh, (voidp) fp);
} else if (error == EACCES) {
/*
* Now decode the file handle return code.
*/
plog(XLOG_INFO, "Filehandle denied for \"%s:%s\"",
fs->fs_host, path);
} else {
errno = error; /* XXX */
plog(XLOG_INFO, "Filehandle error for \"%s:%s\": %m",
fs->fs_host, path);
}
/*
* The error was returned from the remote mount daemon.
* Policy: this error will be cached for now...
*/
return error;
case -1:
/*
* Still thinking about it, but we can re-use.
*/
fp_save = fp;
reuse_id = TRUE;
break;
default:
/*
* Return the error.
* Policy: make sure we recompute if required again
* in case this was caused by a network failure.
* This can thrash mountd's though... If you find
* your mountd going slowly then:
* 1. Add a fork() loop to main.
* 2. Remove the call to innetgr() and don't use
* netgroups, especially if you don't use YP.
*/
error = fp->fh_error;
fp->fh_error = -1;
return error;
}
break;
}
}
/*
* Not in cache
*/
if (fp_save) {
fp = fp_save;
/*
* Re-use existing slot
*/
untimeout(fp->fh_cid);
free_srvr(fp->fh_fs);
free(fp->fh_path);
} else {
fp = ALLOC(fh_cache);
bzero((voidp) fp, sizeof(*fp));
ins_que(&fp->fh_q, &fh_head);
}
if (!reuse_id)
fp->fh_id = FHID_ALLOC();
fp->fh_wchan = wchan;
fp->fh_error = -1;
fp->fh_cid = timeout(FH_TTL, discard_fh, (voidp) fp);
/*
* If the address has changed then don't try to re-use the
* port information
*/
if (fp->fh_sin.sin_addr.s_addr != fs->fs_ip->sin_addr.s_addr) {
fp->fh_sin = *fs->fs_ip;
fp->fh_sin.sin_port = 0;
}
fp->fh_fs = dup_srvr(fs);
fp->fh_path = strdup(path);
error = call_mountd(fp, MOUNTPROC_MNT, got_nfs_fh, wchan);
if (error) {
/*
* Local error - cache for a short period
* just to prevent thrashing.
*/
untimeout(fp->fh_cid);
fp->fh_cid = timeout(error < 0 ? 2 * ALLOWED_MOUNT_TIME : FH_TTL_ERROR,
discard_fh, (voidp) fp);
fp->fh_error = error;
} else {
error = fp->fh_error;
}
return error;
}
int make_nfs_auth P((void))
{
#ifdef HAS_NFS_QUALIFIED_NAMES
/*
* From: Chris Metcalf <metcalf@masala.lcs.mit.edu>
* Use hostd, not just hostname. Note that uids
* and gids and the gidlist are type *int* and not the
* system uid_t and gid_t types.
*/
static int group_wheel = 0;
nfs_auth = authunix_create(hostd, 0, 0, 1, &group_wheel);
#else
nfs_auth = authunix_create_default();
#endif
if (!nfs_auth)
return ENOBUFS;
return 0;
}
static int call_mountd P((fh_cache *fp, u_long proc, fwd_fun f, voidp wchan));
static int call_mountd(fp, proc, f, wchan)
fh_cache *fp;
u_long proc;
fwd_fun f;
voidp wchan;
{
struct rpc_msg mnt_msg;
int len;
char iobuf[8192];
int error;
if (!nfs_auth) {
error = make_nfs_auth();
if (error)
return error;
}
if (fp->fh_sin.sin_port == 0) {
u_short port;
error = nfs_srvr_port(fp->fh_fs, &port, wchan);
if (error)
return error;
fp->fh_sin.sin_port = port;
}
rpc_msg_init(&mnt_msg, MOUNTPROG, MOUNTVERS, (unsigned long) 0);
len = make_rpc_packet(iobuf, sizeof(iobuf), proc,
&mnt_msg, (voidp) &fp->fh_path, xdr_nfspath, nfs_auth);
if (len > 0) {
error = fwd_packet(MK_RPC_XID(RPC_XID_MOUNTD, fp->fh_id),
(voidp) iobuf, len, &fp->fh_sin, &fp->fh_sin, (voidp) fp->fh_id, f);
} else {
error = -len;
}
/*
* It may be the case that we're sending to the wrong MOUNTD port. This
* occurs if mountd is restarted on the server after the port has been
* looked up and stored in the filehandle cache somewhere. The correct
* solution, if we're going to cache port numbers is to catch the ICMP
* port unreachable reply from the server and cause the portmap request
* to be redone. The quick solution here is to invalidate the MOUNTD
* port.
*/
fp->fh_sin.sin_port = 0;
return error;
}
/*-------------------------------------------------------------------------*/
/*
* NFS needs the local filesystem, remote filesystem
* remote hostname.
* Local filesystem defaults to remote and vice-versa.
*/
static char *nfs_match(fo)
am_opts *fo;
{
char *xmtab;
if (fo->opt_fs && !fo->opt_rfs)
fo->opt_rfs = fo->opt_fs;
if (!fo->opt_rfs) {
plog(XLOG_USER, "nfs: no remote filesystem specified");
return FALSE;
}
if (!fo->opt_rhost) {
plog(XLOG_USER, "nfs: no remote host specified");
return FALSE;
}
/*
* Determine magic cookie to put in mtab
*/
xmtab = (char *) xmalloc(strlen(fo->opt_rhost) + strlen(fo->opt_rfs) + 2);
sprintf(xmtab, "%s:%s", fo->opt_rhost, fo->opt_rfs);
#ifdef DEBUG
dlog("NFS: mounting remote server \"%s\", remote fs \"%s\" on \"%s\"",
fo->opt_rhost, fo->opt_rfs, fo->opt_fs);
#endif /* DEBUG */
return xmtab;
}
/*
* Initialise am structure for nfs
*/
static int nfs_init(mf)
mntfs *mf;
{
if (!mf->mf_private) {
int error;
struct fhstatus fhs;
char *colon = strchr(mf->mf_info, ':');
if (colon == 0)
return ENOENT;
error = prime_nfs_fhandle_cache(colon+1, mf->mf_server, &fhs, (voidp) mf);
if (!error) {
mf->mf_private = (voidp) ALLOC(fhstatus);
mf->mf_prfree = (void (*)()) free;
bcopy((voidp) &fhs, mf->mf_private, sizeof(fhs));
}
return error;
}
return 0;
}
int mount_nfs_fh P((struct fhstatus *fhp, char *dir, char *fs_name, char *opts, mntfs *mf));
int mount_nfs_fh(fhp, dir, fs_name, opts, mf)
struct fhstatus *fhp;
char *dir;
char *fs_name;
char *opts;
mntfs *mf;
{
struct nfs_args nfs_args;
struct mntent mnt;
int retry;
char *colon;
/*char *path;*/
char host[MAXHOSTNAMELEN + MAXPATHLEN + 2];
fserver *fs = mf->mf_server;
int flags;
char *xopts;
int error;
#ifdef notdef
unsigned short port;
#endif /* notdef */
MTYPE_TYPE type = MOUNT_TYPE_NFS;
bzero((voidp) &nfs_args, sizeof(nfs_args)); /* Paranoid */
/*
* Extract host name to give to kernel
*/
if (!(colon = strchr(fs_name, ':')))
return ENOENT;
#ifndef NFS_ARGS_NEEDS_PATH
*colon = '\0';
#endif
strncpy(host, fs_name, sizeof(host));
#ifndef NFS_ARGS_NEEDS_PATH
*colon = ':';
#endif /* NFS_ARGS_NEEDS_PATH */
/*path = colon + 1;*/
if (mf->mf_remopts && *mf->mf_remopts && !islocalnet(fs->fs_ip->sin_addr.s_addr))
xopts = strdup(mf->mf_remopts);
else
xopts = strdup(opts);
bzero((voidp) &nfs_args, sizeof(nfs_args));
mnt.mnt_dir = dir;
mnt.mnt_fsname = fs_name;
mnt.mnt_type = MTAB_TYPE_NFS;
mnt.mnt_opts = xopts;
mnt.mnt_freq = 0;
mnt.mnt_passno = 0;
retry = hasmntval(&mnt, "retry");
if (retry <= 0)
retry = 1; /* XXX */
/*again:*/
/*
* set mount args
*/
NFS_FH_DREF(nfs_args.fh, (NFS_FH_TYPE) fhp->fhstatus_u.fhs_fhandle);
#ifdef ULTRIX_HACK
nfs_args.optstr = mnt.mnt_opts;
#endif /* ULTRIX_HACK */
nfs_args.hostname = host;
nfs_args.flags |= NFSMNT_HOSTNAME;
#ifdef HOSTNAMESZ
/*
* Most kernels have a name length restriction.
*/
if (strlen(host) >= HOSTNAMESZ)
strcpy(host + HOSTNAMESZ - 3, "..");
#endif /* HOSTNAMESZ */
if (nfs_args.rsize = hasmntval(&mnt, "rsize"))
nfs_args.flags |= NFSMNT_RSIZE;
if (nfs_args.wsize = hasmntval(&mnt, "wsize"))
nfs_args.flags |= NFSMNT_WSIZE;
if (nfs_args.timeo = hasmntval(&mnt, "timeo"))
nfs_args.flags |= NFSMNT_TIMEO;
if (nfs_args.retrans = hasmntval(&mnt, "retrans"))
nfs_args.flags |= NFSMNT_RETRANS;
#ifdef NFSMNT_BIODS
if (nfs_args.biods = hasmntval(&mnt, "biods"))
nfs_args.flags |= NFSMNT_BIODS;
#endif /* NFSMNT_BIODS */
#ifdef NFSMNT_MAXGRPS
if (nfs_args.maxgrouplist = hasmntval(&mnt, "maxgroups"))
nfs_args.flags |= NFSMNT_MAXGRPS;
#endif /* NFSMNT_MAXGRPS */
#ifdef notdef
/*
* This isn't supported by the ping algorithm yet.
* In any case, it is all done in nfs_init().
*/
if (port = hasmntval(&mnt, "port"))
sin.sin_port = htons(port);
else
sin.sin_port = htons(NFS_PORT); /* XXX should use portmapper */
#endif /* notdef */
if (hasmntopt(&mnt, MNTOPT_SOFT) != NULL)
nfs_args.flags |= NFSMNT_SOFT;
#ifdef NFSMNT_SPONGY
if (hasmntopt(&mnt, "spongy") != NULL) {
nfs_args.flags |= NFSMNT_SPONGY;
if (nfs_args.flags & NFSMNT_SOFT) {
plog(XLOG_USER, "Mount opts soft and spongy are incompatible - soft ignored");
nfs_args.flags &= ~NFSMNT_SOFT;
}
}
#endif /* MNTOPT_SPONGY */
#ifdef MNTOPT_INTR
if (hasmntopt(&mnt, MNTOPT_INTR) != NULL)
nfs_args.flags |= NFSMNT_INT;
#endif /* MNTOPT_INTR */
#ifdef MNTOPT_NODEVS
if (hasmntopt(&mnt, MNTOPT_NODEVS) != NULL)
nfs_args.flags |= NFSMNT_NODEVS;
#endif /* MNTOPT_NODEVS */
#ifdef MNTOPT_COMPRESS
if (hasmntopt(&mnt, "compress") != NULL)
nfs_args.flags |= NFSMNT_COMPRESS;
#endif /* MNTOPT_COMPRESS */
#ifdef MNTOPT_NOCONN
if (hasmntopt(&mnt, "noconn") != NULL)
nfs_args.flags |= NFSMNT_NOCONN;
#endif /* MNTOPT_NOCONN */
#ifdef NFSMNT_PGTHRESH
if (nfs_args.pg_thresh = hasmntval(&mnt, "pgthresh"))
nfs_args.flags |= NFSMNT_PGTHRESH;
#endif /* NFSMNT_PGTHRESH */
NFS_SA_DREF(nfs_args, fs->fs_ip);
flags = compute_mount_flags(&mnt);
#ifdef NFSMNT_NOCTO
if (hasmntopt(&mnt, "nocto") != NULL)
nfs_args.flags |= NFSMNT_NOCTO;
#endif /* NFSMNT_NOCTO */
#ifdef HAS_TCP_NFS
if (hasmntopt(&mnt, "tcp") != NULL)
nfs_args.sotype = SOCK_STREAM;
#endif /* HAS_TCP_NFS */
#ifdef ULTRIX_HACK
/*
* Ultrix passes the flags argument as part of the
* mount data structure, rather than using the
* flags argument to the system call. This is
* confusing...
*/
if (!(nfs_args.flags & NFSMNT_PGTHRESH)) {
nfs_args.pg_thresh = 64; /* 64k - XXX */
nfs_args.flags |= NFSMNT_PGTHRESH;
}
nfs_args.gfs_flags = flags;
flags &= M_RDONLY;
if (flags & M_RDONLY)
nfs_args.flags |= NFSMNT_RONLY;
#endif /* ULTRIX_HACK */
error = mount_fs(&mnt, flags, (caddr_t) &nfs_args, retry, type);
free(xopts);
return error;
}
static int mount_nfs(dir, fs_name, opts, mf)
char *dir;
char *fs_name;
char *opts;
mntfs *mf;
{
#ifdef notdef
int error;
struct fhstatus fhs;
char *colon;
if (!(colon = strchr(fs_name, ':')))
return ENOENT;
#ifdef DEBUG
dlog("locating fhandle for %s", fs_name);
#endif /* DEBUG */
error = prime_nfs_fhandle_cache(colon+1, mf->mf_server, &fhs, (voidp) 0);
if (error)
return error;
return mount_nfs_fh(&fhs, dir, fs_name, opts, mf);
#endif
if (!mf->mf_private) {
plog(XLOG_ERROR, "Missing filehandle for %s", fs_name);
return EINVAL;
}
return mount_nfs_fh((struct fhstatus *) mf->mf_private, dir, fs_name, opts, mf);
}
static int nfs_fmount(mf)
mntfs *mf;
{
int error;
error = mount_nfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, mf);
#ifdef DEBUG
if (error) {
errno = error;
dlog("mount_nfs: %m");
}
#endif /* DEBUG */
return error;
}
static int nfs_fumount(mf)
mntfs *mf;
{
int error = UMOUNT_FS(mf->mf_mount);
if (error)
return error;
return 0;
}
static void nfs_umounted(mp)
am_node *mp;
{
#ifdef INFORM_MOUNTD
/*
* Don't bother to inform remote mountd
* that we are finished. Until a full
* track of filehandles is maintained
* the mountd unmount callback cannot
* be done correctly anyway...
*/
mntfs *mf = mp->am_mnt;
fserver *fs;
char *colon, *path;
if (mf->mf_error || mf->mf_refc > 1)
return;
fs = mf->mf_server;
/*
* Call the mount daemon on the server to
* announce that we are not using the fs any more.
*
* This is *wrong*. The mountd should be called
* when the fhandle is flushed from the cache, and
* a reference held to the cached entry while the
* fs is mounted...
*/
colon = path = strchr(mf->mf_info, ':');
if (fs && colon) {
fh_cache f;
#ifdef DEBUG
dlog("calling mountd for %s", mf->mf_info);
#endif /* DEBUG */
*path++ = '\0';
f.fh_path = path;
f.fh_sin = *fs->fs_ip;
f.fh_sin.sin_port = (u_short) 0;
f.fh_fs = fs;
f.fh_id = 0;
f.fh_error = 0;
(void) prime_nfs_fhandle_cache(colon+1, mf->mf_server, (struct fhstatus *) 0, (voidp) mf);
(void) call_mountd(&f, MOUNTPROC_UMNT, (fwd_fun) 0, (voidp) 0);
*colon = ':';
}
#endif /* INFORM_MOUNTD */
#ifdef KICK_KERNEL
/* This should go into the mainline code, not in nfs_ops... */
/*
* Run lstat over the underlying directory in
* case this was a direct mount. This will
* get the kernel back in sync with reality.
*/
if (mp->am_parent && mp->am_parent->am_path &&
STREQ(mp->am_parent->am_mnt->mf_ops->fs_type, "direct")) {
struct stat stb;
int pid;
if ((pid = background()) == 0) {
if (lstat(mp->am_parent->am_path, &stb) < 0) {
plog(XLOG_ERROR, "lstat(%s) after unmount: %m", mp->am_parent->am_path);
#ifdef DEBUG
} else {
dlog("hack lstat(%s): ok", mp->am_parent->am_path);
#endif /* DEBUG */
}
_exit(0);
}
}
#endif /* KICK_KERNEL */
}
/*
* Network file system
*/
am_ops nfs_ops = {
"nfs",
nfs_match,
nfs_init,
auto_fmount,
nfs_fmount,
auto_fumount,
nfs_fumount,
efs_lookuppn,
efs_readdir,
0, /* nfs_readlink */
0, /* nfs_mounted */
nfs_umounted,
find_nfs_srvr,
FS_MKMNT|FS_BACKGROUND|FS_AMQINFO
};
#endif /* HAS_NFS */

View file

@ -0,0 +1,435 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfs_start.c 8.1 (Berkeley) 6/6/93
*
* $Id: nfs_start.c,v 5.2.2.1 1992/02/09 15:08:51 jsp beta $
*
*/
#include "am.h"
#include "amq.h"
#include <sys/signal.h>
#include <setjmp.h>
extern jmp_buf select_intr;
extern int select_intr_valid;
#ifdef HAS_TFS
/*
* Use replacement for RPC/UDP transport
* so that we do NFS gatewaying.
*/
#define svcudp_create svcudp2_create
extern SVCXPRT *svcudp2_create P((int));
#endif /* HAS_TFS */
extern void nfs_program_2();
extern void amq_program_1();
unsigned short nfs_port;
SVCXPRT *nfsxprt;
extern int fwd_sock;
int max_fds = -1;
#define MASKED_SIGS (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGCHLD)|sigmask(SIGHUP))
#ifdef DEBUG
/*
* Check that we are not burning resources
*/
static void checkup(P_void)
{
static int max_fd = 0;
static char *max_mem = 0;
int next_fd = dup(0);
extern caddr_t sbrk P((int));
caddr_t next_mem = sbrk(0);
close(next_fd);
/*if (max_fd < 0) {
max_fd = next_fd;
} else*/ if (max_fd < next_fd) {
dlog("%d new fds allocated; total is %d",
next_fd - max_fd, next_fd);
max_fd = next_fd;
}
/*if (max_mem == 0) {
max_mem = next_mem;
} else*/ if (max_mem < next_mem) {
dlog("%#x bytes of memory allocated; total is %#x (%d pages)",
next_mem - max_mem,
next_mem,
((int)next_mem+getpagesize()-1)/getpagesize());
max_mem = next_mem;
}
}
#endif /* DEBUG */
static int do_select(smask, fds, fdp, tvp)
int smask;
int fds;
int *fdp;
struct timeval *tvp;
{
int sig;
int nsel;
if (sig = setjmp(select_intr)) {
select_intr_valid = 0;
/* Got a signal */
switch (sig) {
case SIGINT:
case SIGTERM:
amd_state = Finishing;
reschedule_timeout_mp();
break;
}
nsel = -1;
errno = EINTR;
} else {
select_intr_valid = 1;
/*
* Invalidate the current clock value
*/
clock_valid = 0;
/*
* Allow interrupts. If a signal
* occurs, then it will cause a longjmp
* up above.
*/
(void) sigsetmask(smask);
/*
* Wait for input
*/
nsel = select(fds, fdp, (int *) 0, (int *) 0,
tvp->tv_sec ? tvp : (struct timeval *) 0);
}
(void) sigblock(MASKED_SIGS);
/*
* Perhaps reload the cache?
*/
if (do_mapc_reload < clocktime()) {
mapc_reload();
do_mapc_reload = clocktime() + ONE_HOUR;
}
return nsel;
}
/*
* Determine whether anything is left in
* the RPC input queue.
*/
static int rpc_pending_now()
{
struct timeval tvv;
int nsel;
#ifdef FD_SET
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fwd_sock, &readfds);
#else
int readfds = (1 << fwd_sock);
#endif /* FD_SET */
tvv.tv_sec = tvv.tv_usec = 0;
nsel = select(max_fds+1, &readfds, (int *) 0, (int *) 0, &tvv);
if (nsel < 1)
return(0);
#ifdef FD_SET
if (FD_ISSET(fwd_sock, &readfds))
return(1);
#else
if (readfds & (1 << fwd_sock))
return(1);
#endif
return(0);
}
static serv_state run_rpc(P_void)
{
int dtbsz = max_fds + 1;
int smask = sigblock(MASKED_SIGS);
next_softclock = clocktime();
amd_state = Run;
/*
* Keep on trucking while we are in Run mode. This state
* is switched to Quit after all the file systems have
* been unmounted.
*/
while ((int)amd_state <= (int)Finishing) {
struct timeval tvv;
int nsel;
time_t now;
#ifdef RPC_4
fd_set readfds;
readfds = svc_fdset;
FD_SET(fwd_sock, &readfds);
#else
#ifdef FD_SET
fd_set readfds;
FD_ZERO(&readfds);
readfds.fds_bits[0] = svc_fds;
FD_SET(fwd_sock, &readfds);
#else
int readfds = svc_fds | (1 << fwd_sock);
#endif /* FD_SET */
#endif /* RPC_4 */
#ifdef DEBUG
checkup();
#endif /* DEBUG */
/*
* If the full timeout code is not called,
* then recompute the time delta manually.
*/
now = clocktime();
if (next_softclock <= now) {
if (amd_state == Finishing)
umount_exported();
tvv.tv_sec = softclock();
} else {
tvv.tv_sec = next_softclock - now;
}
tvv.tv_usec = 0;
if (amd_state == Finishing && last_used_map < 0) {
flush_mntfs();
amd_state = Quit;
break;
}
#ifdef DEBUG
if (tvv.tv_sec)
dlog("Select waits for %ds", tvv.tv_sec);
else
dlog("Select waits for Godot");
#endif /* DEBUG */
nsel = do_select(smask, dtbsz, &readfds, &tvv);
switch (nsel) {
case -1:
if (errno == EINTR) {
#ifdef DEBUG
dlog("select interrupted");
#endif /* DEBUG */
continue;
}
perror("select");
break;
case 0:
#ifdef DEBUG
/*dlog("select returned 0");*/
#endif /* DEBUG */
break;
default:
/* Read all pending NFS responses at once to avoid
having responses queue up as a consequence of
retransmissions. */
#ifdef FD_SET
if (FD_ISSET(fwd_sock, &readfds)) {
FD_CLR(fwd_sock, &readfds);
#else
if (readfds & (1 << fwd_sock)) {
readfds &= ~(1 << fwd_sock);
#endif
--nsel;
do {
fwd_reply();
} while (rpc_pending_now() > 0);
}
if (nsel) {
/*
* Anything left must be a normal
* RPC request.
*/
#ifdef RPC_4
svc_getreqset(&readfds);
#else
#ifdef FD_SET
svc_getreq(readfds.fds_bits[0]);
#else
svc_getreq(readfds);
#endif /* FD_SET */
#endif /* RPC_4 */
}
break;
}
}
(void) sigsetmask(smask);
if (amd_state == Quit)
amd_state = Done;
return amd_state;
}
static int bindnfs_port(so)
int so;
{
unsigned short port;
int error = bind_resv_port(so, &port);
if (error == 0)
nfs_port = port;
return error;
}
void unregister_amq(P_void)
{
#ifdef DEBUG
Debug(D_AMQ)
#endif /* DEBUG */
(void) pmap_unset(AMQ_PROGRAM, AMQ_VERSION);
}
int mount_automounter(ppid)
int ppid;
{
int so = socket(AF_INET, SOCK_DGRAM, 0);
SVCXPRT *amqp;
int nmount;
if (so < 0 || bindnfs_port(so) < 0) {
perror("Can't create privileged nfs port");
return 1;
}
if ((nfsxprt = svcudp_create(so)) == NULL ||
(amqp = svcudp_create(so)) == NULL) {
plog(XLOG_FATAL, "cannot create rpc/udp service");
return 2;
}
if (!svc_register(nfsxprt, NFS_PROGRAM, NFS_VERSION, nfs_program_2, 0)) {
plog(XLOG_FATAL, "unable to register (NFS_PROGRAM, NFS_VERSION, 0)");
return 3;
}
/*
* Start RPC forwarding
*/
if (fwd_init() != 0)
return 3;
/*
* One or other of so, fwd_sock
* must be the highest fd on
* which to select.
*/
if (so > max_fds)
max_fds = so;
if (fwd_sock > max_fds)
max_fds = fwd_sock;
/*
* Construct the root automount node
*/
make_root_node();
/*
* Pick up the pieces from a previous run
* This is likely to (indirectly) need the rpc_fwd package
* so it *must* come after the call to fwd_init().
*/
if (restart_existing_mounts)
restart();
/*
* Mount the top-level auto-mountpoints
*/
nmount = mount_exported();
/*
* Now safe to tell parent that we are up and running
*/
if (ppid)
kill(ppid, SIGQUIT);
if (nmount == 0) {
plog(XLOG_FATAL, "No work to do - quitting");
amd_state = Done;
return 0;
}
#ifdef DEBUG
Debug(D_AMQ) {
#endif /* DEBUG */
/*
* Register with amq
*/
unregister_amq();
if (!svc_register(amqp, AMQ_PROGRAM, AMQ_VERSION, amq_program_1, IPPROTO_UDP)) {
plog(XLOG_FATAL, "unable to register (AMQ_PROGRAM, AMQ_VERSION, udp)");
return 3;
}
#ifdef DEBUG
}
#endif /* DEBUG */
/*
* Start timeout_mp rolling
*/
reschedule_timeout_mp();
/*
* Start the server
*/
if (run_rpc() != Done) {
plog(XLOG_FATAL, "run_rpc failed");
amd_state = Done;
}
return 0;
}

552
usr.sbin/amd/amd/nfs_subr.c Normal file
View file

@ -0,0 +1,552 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfs_subr.c 8.1 (Berkeley) 6/6/93
*
* $Id: nfs_subr.c,v 5.2.2.1 1992/02/09 15:08:53 jsp beta $
*
*/
#include "am.h"
/*
* Convert from UN*X to NFS error code
*/
#ifdef NFS_ERROR_MAPPING
NFS_ERROR_MAPPING
#define nfs_error(e) \
((nfsstat)((e) > NFS_LOMAP && (e) < NFS_HIMAP ? \
nfs_errormap[(e) - NFS_LOMAP] : (e)))
#else
#define nfs_error(e) ((nfsstat)(e))
#endif /* NFS_ERROR_MAPPING */
static char *do_readlink P((am_node *mp, int *error_return, struct attrstat **attrpp));
static char *do_readlink(mp, error_return, attrpp)
am_node *mp;
int *error_return;
struct attrstat **attrpp;
{
char *ln;
/*
* If there is a readlink method, then use
* that, otherwise if a link exists use
* that, otherwise use the mount point.
*/
if (mp->am_mnt->mf_ops->readlink) {
int retry = 0;
mp = (*mp->am_mnt->mf_ops->readlink)(mp, &retry);
if (mp == 0) {
*error_return = retry;
return 0;
}
/*reschedule_timeout_mp();*/
}
if (mp->am_link) {
ln = mp->am_link;
} else {
ln = mp->am_mnt->mf_mount;
}
if (attrpp)
*attrpp = &mp->am_attr;
return ln;
}
/*ARGSUSED*/
voidp
nfsproc_null_2(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static char res;
return (voidp) &res;
}
/*ARGSUSED*/
struct attrstat *
nfsproc_getattr_2(argp, rqstp)
struct nfs_fh *argp;
struct svc_req *rqstp;
{
static struct attrstat res;
am_node *mp;
int retry;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "gettattr:");
#endif /* DEBUG */
mp = fh_to_mp2(argp, &retry);
if (mp == 0) {
#ifdef PRECISE_SYMLINKS
getattr_retry:
#endif /* PRECISE_SYMLINKS */
if (retry < 0)
return 0;
res.status = nfs_error(retry);
} else {
struct attrstat *attrp = &mp->am_attr;
#ifdef PRECISE_SYMLINKS
if (mp->am_fattr.type == NFLNK) {
/*
* Make sure we can read the link,
* and then determine the length.
*/
char *ln = do_readlink(mp, &retry, &attrp);
if (ln == 0)
goto getattr_retry;
}
#endif /* PRECISE_SYMLINKS */
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "\tstat(%s), size = %d", mp->am_path, attrp->attrstat_u.attributes.size);
#endif /* DEBUG */
mp->am_stats.s_getattr++;
return attrp;
}
return &res;
}
/*ARGSUSED*/
struct attrstat *
nfsproc_setattr_2(argp, rqstp)
struct sattrargs *argp;
struct svc_req *rqstp;
{
static struct attrstat res;
if (!fh_to_mp(&argp->file))
res.status = nfs_error(ESTALE);
else
res.status = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
voidp
nfsproc_root_2(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static char res;
return (voidp)&res;
}
/*ARGSUSED*/
struct diropres *
nfsproc_lookup_2(argp, rqstp)
struct diropargs *argp;
struct svc_req *rqstp;
{
static struct diropres res;
am_node *mp;
int retry;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "lookup:");
#endif /* DEBUG */
mp = fh_to_mp2(&argp->dir, &retry);
if (mp == 0) {
if (retry < 0)
return 0;
res.status = nfs_error(retry);
} else {
int error;
am_node *ap;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "\tlookuppn(%s, %s)", mp->am_path, argp->name);
#endif /* DEBUG */
ap = (*mp->am_mnt->mf_ops->lookuppn)(mp, argp->name, &error, VLOOK_CREATE);
if (ap == 0) {
if (error < 0) {
#ifdef DEBUG
dlog("Not sending RPC reply");
#endif /* DEBUG */
amd_stats.d_drops++;
return 0;
}
res.status = nfs_error(error);
} else {
mp_to_fh(ap, &res.diropres_u.diropres.file);
res.diropres_u.diropres.attributes = ap->am_fattr;
res.status = NFS_OK;
}
mp->am_stats.s_lookup++;
/*reschedule_timeout_mp();*/
}
return &res;
}
/*ARGSUSED*/
struct readlinkres *
nfsproc_readlink_2(argp, rqstp)
struct nfs_fh *argp;
struct svc_req *rqstp;
{
static struct readlinkres res;
am_node *mp;
int retry;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "readlink:");
#endif /* DEBUG */
mp = fh_to_mp2(argp, &retry);
if (mp == 0) {
readlink_retry:
if (retry < 0)
return 0;
res.status = nfs_error(retry);
} else {
char *ln = do_readlink(mp, &retry, (struct attrstat **) 0);
if (ln == 0)
goto readlink_retry;
res.status = NFS_OK;
#ifdef DEBUG
Debug(D_TRACE)
if (ln)
plog(XLOG_DEBUG, "\treadlink(%s) = %s", mp->am_path, ln);
#endif /* DEBUG */
res.readlinkres_u.data = ln;
mp->am_stats.s_readlink++;
}
return &res;
}
/*ARGSUSED*/
struct readres *
nfsproc_read_2(argp, rqstp)
struct readargs *argp;
struct svc_req *rqstp;
{
static struct readres res;
bzero((char *)&res, sizeof(res));
res.status = nfs_error(EACCES);
return &res;
}
/*ARGSUSED*/
voidp
nfsproc_writecache_2(argp, rqstp)
voidp argp;
struct svc_req *rqstp;
{
static char res;
return (voidp) &res;
}
/*ARGSUSED*/
struct attrstat *
nfsproc_write_2(argp, rqstp)
writeargs *argp;
struct svc_req *rqstp;
{
static struct attrstat res;
if (!fh_to_mp(&argp->file))
res.status = nfs_error(ESTALE);
else
res.status = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
struct diropres *
nfsproc_create_2(argp, rqstp)
createargs *argp;
struct svc_req *rqstp;
{
static struct diropres res;
if (!fh_to_mp(&argp->where.dir))
res.status = nfs_error(ESTALE);
else
res.status = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
static nfsstat *
unlink_or_rmdir(argp, rqstp, unlinkp)
struct diropargs *argp;
struct svc_req *rqstp;
int unlinkp;
{
static nfsstat res;
int retry;
/*mntfs *mf;*/
am_node *mp = fh_to_mp3(&argp->dir, &retry, VLOOK_DELETE);
if (mp == 0) {
if (retry < 0)
return 0;
res = nfs_error(retry);
goto out;
}
/*mf = mp->am_mnt;*/
if (mp->am_fattr.type != NFDIR) {
res = nfs_error(ENOTDIR);
goto out;
}
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "\tremove(%s, %s)", mp->am_path, argp->name);
#endif /* DEBUG */
mp = (*mp->am_mnt->mf_ops->lookuppn)(mp, argp->name, &retry, VLOOK_DELETE);
if (mp == 0) {
/*
* Ignore retries...
*/
if (retry < 0)
retry = 0;
/*
* Usual NFS workaround...
*/
else if (retry == ENOENT)
retry = 0;
res = nfs_error(retry);
} else {
forcibly_timeout_mp(mp);
res = NFS_OK;
}
out:
return &res;
}
/*ARGSUSED*/
nfsstat *
nfsproc_remove_2(argp, rqstp)
struct diropargs *argp;
struct svc_req *rqstp;
{
return unlink_or_rmdir(argp, rqstp, TRUE);
}
/*ARGSUSED*/
nfsstat *
nfsproc_rename_2(argp, rqstp)
renameargs *argp;
struct svc_req *rqstp;
{
static nfsstat res;
if (!fh_to_mp(&argp->from.dir) || !fh_to_mp(&argp->to.dir))
res = nfs_error(ESTALE);
/*
* If the kernel is doing clever things with referenced files
* then let it pretend...
*/
else if (strncmp(argp->to.name, ".nfs", 4) == 0)
res = NFS_OK;
/*
* otherwise a failure
*/
else
res = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
nfsstat *
nfsproc_link_2(argp, rqstp)
linkargs *argp;
struct svc_req *rqstp;
{
static nfsstat res;
if (!fh_to_mp(&argp->from) || !fh_to_mp(&argp->to.dir))
res = nfs_error(ESTALE);
else
res = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
nfsstat *
nfsproc_symlink_2(argp, rqstp)
symlinkargs *argp;
struct svc_req *rqstp;
{
static nfsstat res;
if (!fh_to_mp(&argp->from.dir))
res = nfs_error(ESTALE);
else
res = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
struct diropres *
nfsproc_mkdir_2(argp, rqstp)
createargs *argp;
struct svc_req *rqstp;
{
static struct diropres res;
if (!fh_to_mp(&argp->where.dir))
res.status = nfs_error(ESTALE);
else
res.status = nfs_error(EROFS);
return &res;
}
/*ARGSUSED*/
nfsstat *
nfsproc_rmdir_2(argp, rqstp)
struct diropargs *argp;
struct svc_req *rqstp;
{
return unlink_or_rmdir(argp, rqstp, FALSE);
}
/*ARGSUSED*/
struct readdirres *
nfsproc_readdir_2(argp, rqstp)
readdirargs *argp;
struct svc_req *rqstp;
{
static readdirres res;
static entry e_res[MAX_READDIR_ENTRIES];
am_node *mp;
int retry;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "readdir:");
#endif /* DEBUG */
mp = fh_to_mp2(&argp->dir, &retry);
if (mp == 0) {
if (retry < 0)
return 0;
res.status = nfs_error(retry);
} else {
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "\treaddir(%s)", mp->am_path);
#endif /* DEBUG */
res.status = nfs_error((*mp->am_mnt->mf_ops->readdir)(mp, argp->cookie,
&res.readdirres_u.reply, e_res, argp->count));
mp->am_stats.s_readdir++;
}
return &res;
}
/*ARGSUSED*/
struct statfsres *
nfsproc_statfs_2(argp, rqstp)
struct nfs_fh *argp;
struct svc_req *rqstp;
{
static statfsres res;
am_node *mp;
int retry;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "statfs:");
#endif /* DEBUG */
mp = fh_to_mp2(argp, &retry);
if (mp == 0) {
if (retry < 0)
return 0;
res.status = nfs_error(retry);
} else {
statfsokres *fp;
#ifdef DEBUG
Debug(D_TRACE)
plog(XLOG_DEBUG, "\tstat_fs(%s)", mp->am_path);
#endif /* DEBUG */
/*
* just return faked up file system information
*/
fp = &res.statfsres_u.reply;
fp->tsize = 1024;
fp->bsize = 4096;
#ifdef HAS_EMPTY_AUTOMOUNTS
fp->blocks = 0;
#else
fp->blocks = 1;
#endif
fp->bfree = 0;
fp->bavail = 0;
res.status = NFS_OK;
mp->am_stats.s_statfs++;
}
return &res;
}

516
usr.sbin/amd/amd/nfsx_ops.c Normal file
View file

@ -0,0 +1,516 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfsx_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: nfsx_ops.c,v 5.2.2.3 1992/05/31 16:13:07 jsp Exp $
*
*/
#include "am.h"
#ifdef HAS_NFSX
/*
* NFS hierarchical mounts
*
* TODO: Re-implement.
*/
/*
* The rfs field contains a list of mounts to be done from
* the remote host.
*/
typedef struct nfsx_mnt {
mntfs *n_mnt;
int n_error;
} nfsx_mnt;
struct nfsx {
int nx_c; /* Number of elements in nx_v */
nfsx_mnt *nx_v; /* Underlying mounts */
nfsx_mnt *nx_try;
};
static int nfsx_fmount P((mntfs*));
static char *nfsx_match(fo)
am_opts *fo;
{
char *xmtab;
char *ptr;
int len;
if (!fo->opt_rfs) {
plog(XLOG_USER, "nfsx: no remote filesystem specified");
return FALSE;
}
if (!fo->opt_rhost) {
plog(XLOG_USER, "nfsx: no remote host specified");
return FALSE;
}
#ifdef notdef
/* fiddle sublink, must be last... */
if (fo->opt_sublink) {
plog(XLOG_WARNING, "nfsx: sublink %s ignored", fo->opt_sublink);
free((voidp) fo->opt_sublink);
fo->opt_sublink = 0;
}
#endif
/* set default sublink */
if (fo->opt_sublink == 0) {
ptr = strchr(fo->opt_rfs, ',');
if (ptr && ptr != (fo->opt_rfs + 1))
fo->opt_sublink = strnsave(fo->opt_rfs + 1, ptr - fo->opt_rfs - 1);
}
/*
* Remove trailing ",..." from ${fs}
* After deslashifying, overwrite the end of ${fs} with "/"
* to make sure it is unique.
*/
if (ptr = strchr(fo->opt_fs, ','))
*ptr = '\0';
deslashify(fo->opt_fs);
/*
* Bump string length to allow trailing /
*/
len = strlen(fo->opt_fs);
fo->opt_fs = xrealloc(fo->opt_fs, len + 1 + 1);
ptr = fo->opt_fs + len;
/*
* Make unique...
*/
*ptr++ = '/';
*ptr = '\0';
/*
* Determine magic cookie to put in mtab
*/
xmtab = str3cat((char *) 0, fo->opt_rhost, ":", fo->opt_rfs);
#ifdef DEBUG
dlog("NFS: mounting remote server \"%s\", remote fs \"%s\" on \"%s\"",
fo->opt_rhost, fo->opt_rfs, fo->opt_fs);
#endif /* DEBUG */
return xmtab;
}
static void nfsx_prfree P((voidp vp));
static void nfsx_prfree(vp)
voidp vp;
{
struct nfsx *nx = (struct nfsx *) vp;
int i;
for (i = 0; i < nx->nx_c; i++) {
mntfs *m = nx->nx_v[i].n_mnt;
if (m)
free_mntfs(m);
}
free((voidp) nx->nx_v);
free((voidp) nx);
}
static int nfsx_init(mf)
mntfs *mf;
{
/*
* mf_info has the form:
* host:/prefix/path,sub,sub,sub
*/
int i;
int glob_error;
struct nfsx *nx;
int asked_for_wakeup = 0;
nx = (struct nfsx *) mf->mf_private;
if (nx == 0) {
char **ivec;
char *info = 0;
char *host;
char *pref;
int error = 0;
info = strdup(mf->mf_info);
host = strchr(info, ':');
if (!host) {
error = EINVAL;
goto errexit;
}
pref = host+1;
host = info;
/*
* Split the prefix off from the suffices
*/
ivec = strsplit(pref, ',', '\'');
/*
* Count array size
*/
for (i = 0; ivec[i]; i++)
;
nx = ALLOC(nfsx);
mf->mf_private = (voidp) nx;
mf->mf_prfree = nfsx_prfree;
nx->nx_c = i - 1; /* i-1 because we don't want the prefix */
nx->nx_v = (nfsx_mnt *) xmalloc(nx->nx_c * sizeof(nfsx_mnt));
{ char *mp = 0;
char *xinfo = 0;
char *fs = mf->mf_fo->opt_fs;
char *rfs = 0;
for (i = 0; i < nx->nx_c; i++) {
char *path = ivec[i+1];
rfs = str3cat(rfs, pref, "/", path);
/*
* Determine the mount point.
* If this is the root, then don't remove
* the trailing slash to avoid mntfs name clashes.
*/
mp = str3cat(mp, fs, "/", rfs);
normalize_slash(mp);
deslashify(mp);
/*
* Determine the mount info
*/
xinfo = str3cat(xinfo, host, *path == '/' ? "" : "/", path);
normalize_slash(xinfo);
if (pref[1] != '\0')
deslashify(xinfo);
#ifdef DEBUG
dlog("nfsx: init mount for %s on %s", xinfo, mp);
#endif
nx->nx_v[i].n_error = -1;
nx->nx_v[i].n_mnt = find_mntfs(&nfs_ops, mf->mf_fo, mp, xinfo, "", mf->mf_mopts, mf->mf_remopts);
}
if (rfs) free(rfs);
if (mp) free(mp);
if (xinfo) free(xinfo);
}
free((voidp) ivec);
errexit:
if (info)
free(info);
if (error)
return error;
}
/*
* Iterate through the mntfs's and call
* the underlying init routine on each
*/
glob_error = 0;
for (i = 0; i < nx->nx_c; i++) {
nfsx_mnt *n = &nx->nx_v[i];
mntfs *m = n->n_mnt;
int error = (*m->mf_ops->fs_init)(m);
/*
* If HARD_NFSX_ERRORS is defined, make any
* initialisation failure a hard error and
* fail the entire group. Otherwise only fail
* if none of the group is mountable (see nfsx_fmount).
*/
#ifdef HARD_NFSX_ERRORS
if (error > 0)
return error;
#else
if (error > 0)
n->n_error = error;
#endif
else if (error < 0) {
glob_error = -1;
if (!asked_for_wakeup) {
asked_for_wakeup = 1;
sched_task(wakeup_task, (voidp) mf, (voidp) m);
}
}
}
return glob_error;
}
static void nfsx_cont P((int rc, int term, voidp closure));
static void nfsx_cont(rc, term, closure)
int rc;
int term;
voidp closure;
{
mntfs *mf = (mntfs *) closure;
struct nfsx *nx = (struct nfsx *) mf->mf_private;
nfsx_mnt *n = nx->nx_try;
n->n_mnt->mf_flags &= ~(MFF_ERROR|MFF_MOUNTING);
mf->mf_flags &= ~MFF_ERROR;
/*
* Wakeup anything waiting for this mount
*/
wakeup((voidp) n->n_mnt);
if (rc || term) {
if (term) {
/*
* Not sure what to do for an error code.
*/
plog(XLOG_ERROR, "mount for %s got signal %d", n->n_mnt->mf_mount, term);
n->n_error = EIO;
} else {
/*
* Check for exit status
*/
errno = rc; /* XXX */
plog(XLOG_ERROR, "%s: mount (nfsx_cont): %m", n->n_mnt->mf_mount);
n->n_error = rc;
}
free_mntfs(n->n_mnt);
n->n_mnt = new_mntfs();
n->n_mnt->mf_error = n->n_error;
n->n_mnt->mf_flags |= MFF_ERROR;
} else {
/*
* The mount worked.
*/
mf_mounted(n->n_mnt);
n->n_error = 0;
}
/*
* Do the remaining bits
*/
if (nfsx_fmount(mf) >= 0) {
wakeup((voidp) mf);
mf->mf_flags &= ~MFF_MOUNTING;
mf_mounted(mf);
}
}
static int try_nfsx_mount P((voidp mv));
static int try_nfsx_mount(mv)
voidp mv;
{
mntfs *mf = (mntfs *) mv;
int error;
mf->mf_flags |= MFF_MOUNTING;
error = (*mf->mf_ops->fmount_fs)(mf);
mf->mf_flags &= ~MFF_MOUNTING;
return error;
}
static int nfsx_remount P((mntfs *mf, int fg));
static int nfsx_remount(mf, fg)
mntfs *mf;
int fg;
{
struct nfsx *nx = (struct nfsx *) mf->mf_private;
nfsx_mnt *n;
int glob_error = -1;
for (n = nx->nx_v; n < nx->nx_v + nx->nx_c; n++) {
mntfs *m = n->n_mnt;
if (n->n_error < 0) {
if (!(m->mf_flags & MFF_MKMNT) && m->mf_ops->fs_flags & FS_MKMNT) {
int error = mkdirs(m->mf_mount, 0555);
if (!error)
m->mf_flags |= MFF_MKMNT;
}
}
}
/*
* Iterate through the mntfs's and mount each filesystem
* which is not yet mounted.
*/
for (n = nx->nx_v; n < nx->nx_v + nx->nx_c; n++) {
mntfs *m = n->n_mnt;
if (n->n_error < 0) {
/*
* Check fmount entry pt. exists
* and then mount...
*/
if (!m->mf_ops->fmount_fs) {
n->n_error = EINVAL;
} else {
#ifdef DEBUG
dlog("calling underlying fmount on %s", m->mf_mount);
#endif
if (!fg && foreground && (m->mf_ops->fs_flags & FS_MBACKGROUND)) {
m->mf_flags |= MFF_MOUNTING; /* XXX */
#ifdef DEBUG
dlog("backgrounding mount of \"%s\"", m->mf_info);
#endif
nx->nx_try = n;
run_task(try_nfsx_mount, (voidp) m, nfsx_cont, (voidp) mf);
n->n_error = -1;
return -1;
} else {
#ifdef DEBUG
dlog("foreground mount of \"%s\" ...", mf->mf_info);
#endif
n->n_error = (*m->mf_ops->fmount_fs)(m);
}
}
#ifdef DEBUG
if (n->n_error > 0) {
errno = n->n_error; /* XXX */
dlog("underlying fmount of %s failed: %m", m->mf_mount);
}
#endif
if (n->n_error == 0) {
glob_error = 0;
} else if (glob_error < 0) {
glob_error = n->n_error;
}
}
}
return glob_error < 0 ? 0 : glob_error;
}
static int nfsx_fmount P((mntfs *mf));
static int nfsx_fmount(mf)
mntfs *mf;
{
return nfsx_remount(mf, FALSE);
}
/*
* Unmount an NFS hierarchy.
* Note that this is called in the foreground
* and so may hang under extremely rare conditions.
*/
static int nfsx_fumount(mf)
mntfs *mf;
{
struct nfsx *nx = (struct nfsx *) mf->mf_private;
nfsx_mnt *n;
int glob_error = 0;
/*
* Iterate in reverse through the mntfs's and unmount each filesystem
* which is mounted.
*/
for (n = nx->nx_v + nx->nx_c - 1; n >= nx->nx_v; --n) {
mntfs *m = n->n_mnt;
/*
* If this node has not been messed with
* and there has been no error so far
* then try and unmount.
* If an error had occured then zero
* the error code so that the remount
* only tries to unmount those nodes
* which had been successfully unmounted.
*/
if (n->n_error == 0) {
#ifdef DEBUG
dlog("calling underlying fumount on %s", m->mf_mount);
#endif
n->n_error = (*m->mf_ops->fumount_fs)(m);
if (n->n_error) {
glob_error = n->n_error;
n->n_error = 0;
} else {
/*
* Make sure remount gets this node
*/
n->n_error = -1;
}
}
}
/*
* If any unmounts failed then remount the
* whole lot...
*/
if (glob_error) {
glob_error = nfsx_remount(mf, TRUE);
if (glob_error) {
errno = glob_error; /* XXX */
plog(XLOG_USER, "nfsx: remount of %s failed: %m", mf->mf_mount);
}
glob_error = EBUSY;
} else {
/*
* Remove all the mount points
*/
for (n = nx->nx_v; n < nx->nx_v + nx->nx_c; n++) {
mntfs *m = n->n_mnt;
if (n->n_error < 0) {
if (m->mf_ops->fs_flags & FS_MKMNT) {
(void) rmdirs(m->mf_mount);
m->mf_flags &= ~MFF_MKMNT;
}
}
free_mntfs(m);
n->n_mnt = 0;
n->n_error = -1;
}
}
return glob_error;
}
/*
* Ops structure
*/
am_ops nfsx_ops = {
"nfsx",
nfsx_match,
nfsx_init,
auto_fmount,
nfsx_fmount,
auto_fumount,
nfsx_fumount,
efs_lookuppn,
efs_readdir,
0, /* nfsx_readlink */
0, /* nfsx_mounted */
0, /* nfsx_umounted */
find_nfs_srvr, /* XXX */
/*FS_UBACKGROUND|*/FS_AMQINFO
};
#endif /* HAS_NFSX */

835
usr.sbin/amd/amd/opts.c Normal file
View file

@ -0,0 +1,835 @@
/*-
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: opts.c,v 5.2.2.3 1992/05/31 16:34:13 jsp Exp $
*/
#ifndef lint
static char sccsid[] = "@(#)opts.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "am.h"
extern char *getenv P((const char *));
/*
* static copy of the options with
* which to play
*/
static struct am_opts fs_static;
static char *opt_host = hostname;
static char *opt_hostd = hostd;
static char nullstr[] = "";
static char *opt_key = nullstr;
static char *opt_map = nullstr;
static char *opt_path = nullstr;
static char *vars[8];
/*
* Length of longest option name
*/
#define NLEN 16 /* conservative */
#define S(x) (x) , (sizeof(x)-1)
static struct opt {
char *name; /* Name of the option */
int nlen; /* Length of option name */
char **optp; /* Pointer to option value string */
char **sel_p; /* Pointer to selector value string */
} opt_fields[] = {
/* Options in something corresponding to frequency of use */
{ S("opts"), &fs_static.opt_opts, 0 },
{ S("host"), 0, &opt_host },
{ S("hostd"), 0, &opt_hostd },
{ S("type"), &fs_static.opt_type, 0 },
{ S("rhost"), &fs_static.opt_rhost, 0 },
{ S("rfs"), &fs_static.opt_rfs, 0 },
{ S("fs"), &fs_static.opt_fs, 0 },
{ S("key"), 0, &opt_key },
{ S("map"), 0, &opt_map },
{ S("sublink"), &fs_static.opt_sublink, 0 },
{ S("arch"), 0, &arch },
{ S("dev"), &fs_static.opt_dev, 0 },
{ S("pref"), &fs_static.opt_pref, 0 },
{ S("path"), 0, &opt_path },
{ S("autodir"), 0, &auto_dir },
{ S("delay"), &fs_static.opt_delay, 0 },
{ S("domain"), 0, &hostdomain },
{ S("karch"), 0, &karch },
{ S("cluster"), 0, &cluster },
{ S("wire"), 0, &wire },
{ S("byte"), 0, &endian },
{ S("os"), 0, &op_sys },
{ S("remopts"), &fs_static.opt_remopts, 0 },
{ S("mount"), &fs_static.opt_mount, 0 },
{ S("unmount"), &fs_static.opt_unmount, 0 },
{ S("cache"), &fs_static.opt_cache, 0 },
{ S("user"), &fs_static.opt_user, 0 },
{ S("group"), &fs_static.opt_group, 0 },
{ S("var0"), &vars[0], 0 },
{ S("var1"), &vars[1], 0 },
{ S("var2"), &vars[2], 0 },
{ S("var3"), &vars[3], 0 },
{ S("var4"), &vars[4], 0 },
{ S("var5"), &vars[5], 0 },
{ S("var6"), &vars[6], 0 },
{ S("var7"), &vars[7], 0 },
{ 0, 0, 0, 0 },
};
typedef struct opt_apply opt_apply;
struct opt_apply {
char **opt;
char *val;
};
/*
* Specially expand the remote host name first
*/
static opt_apply rhost_expansion[] = {
{ &fs_static.opt_rhost, "${host}" },
{ 0, 0 },
};
/*
* List of options which need to be expanded
* Note that this the order here _may_ be important.
*/
static opt_apply expansions[] = {
/* { &fs_static.opt_dir, 0 }, */
{ &fs_static.opt_sublink, 0 },
{ &fs_static.opt_rfs, "${path}" },
{ &fs_static.opt_fs, "${autodir}/${rhost}${rfs}" },
{ &fs_static.opt_opts, "rw" },
{ &fs_static.opt_remopts, "${opts}" },
{ &fs_static.opt_mount, 0 },
{ &fs_static.opt_unmount, 0 },
{ 0, 0 },
};
/*
* List of options which need to be free'ed before re-use
*/
static opt_apply to_free[] = {
{ &fs_static.fs_glob, 0 },
{ &fs_static.fs_local, 0 },
{ &fs_static.fs_mtab, 0 },
/* { &fs_static.opt_dir, 0 }, */
{ &fs_static.opt_sublink, 0 },
{ &fs_static.opt_rfs, 0 },
{ &fs_static.opt_fs, 0 },
{ &fs_static.opt_rhost, 0 },
{ &fs_static.opt_opts, 0 },
{ &fs_static.opt_remopts, 0 },
{ &fs_static.opt_mount, 0 },
{ &fs_static.opt_unmount, 0 },
{ &vars[0], 0 },
{ &vars[1], 0 },
{ &vars[2], 0 },
{ &vars[3], 0 },
{ &vars[4], 0 },
{ &vars[5], 0 },
{ &vars[6], 0 },
{ &vars[7], 0 },
{ 0, 0 },
};
/*
* Skip to next option in the string
*/
static char *opt P((char**));
static char *opt(p)
char **p;
{
char *cp = *p;
char *dp = cp;
char *s = cp;
top:
while (*cp && *cp != ';') {
if (*cp == '\"') {
/*
* Skip past string
*/
cp++;
while (*cp && *cp != '\"')
*dp++ = *cp++;
if (*cp)
cp++;
} else {
*dp++ = *cp++;
}
}
/*
* Skip past any remaining ';'s
*/
while (*cp == ';')
cp++;
/*
* If we have a zero length string
* and there are more fields, then
* parse the next one. This allows
* sequences of empty fields.
*/
if (*cp && dp == s)
goto top;
*dp = '\0';
*p = cp;
return s;
}
static int eval_opts P((char*, char*));
static int eval_opts(opts, mapkey)
char *opts;
char *mapkey;
{
/*
* Fill in the global structure fs_static by
* cracking the string opts. opts may be
* scribbled on at will.
*/
char *o = opts;
char *f;
/*
* For each user-specified option
*/
while (*(f = opt(&o))) {
struct opt *op;
enum vs_opt { OldSyn, SelEQ, SelNE, VarAss } vs_opt;
char *eq = strchr(f, '=');
char *opt;
if (!eq || eq[1] == '\0' || eq == f) {
/*
* No value, just continue
*/
plog(XLOG_USER, "key %s: No value component in \"%s\"", mapkey, f);
continue;
}
/*
* Check what type of operation is happening
* !=, =! is SelNE
* == is SelEQ
* := is VarAss
* = is OldSyn (either SelEQ or VarAss)
*/
if (eq[-1] == '!') { /* != */
vs_opt = SelNE;
eq[-1] = '\0';
opt = eq + 1;
} else if (eq[-1] == ':') { /* := */
vs_opt = VarAss;
eq[-1] = '\0';
opt = eq + 1;
} else if (eq[1] == '=') { /* == */
vs_opt = SelEQ;
eq[0] = '\0';
opt = eq + 2;
} else if (eq[1] == '!') { /* =! */
vs_opt = SelNE;
eq[0] = '\0';
opt = eq + 2;
} else { /* = */
vs_opt = OldSyn;
eq[0] = '\0';
opt = eq + 1;
}
/*
* For each recognised option
*/
for (op = opt_fields; op->name; op++) {
/*
* Check whether they match
*/
if (FSTREQ(op->name, f)) {
switch (vs_opt) {
#if AMD_COMPAT <= 5000108
case OldSyn:
plog(XLOG_WARNING, "key %s: Old syntax selector found: %s=%s", mapkey, f, opt);
if (!op->sel_p) {
*op->optp = opt;
break;
}
/* fall through ... */
#endif /* 5000108 */
case SelEQ:
case SelNE:
if (op->sel_p && (STREQ(*op->sel_p, opt) == (vs_opt == SelNE))) {
plog(XLOG_MAP, "key %s: map selector %s (=%s) did not %smatch %s",
mapkey,
op->name,
*op->sel_p,
vs_opt == SelNE ? "not " : "",
opt);
return 0;
}
break;
case VarAss:
if (op->sel_p) {
plog(XLOG_USER, "key %s: Can't assign to a selector (%s)", mapkey, op->name);
return 0;
}
*op->optp = opt;
break;
}
break;
}
}
if (!op->name)
plog(XLOG_USER, "key %s: Unrecognised key/option \"%s\"", mapkey, f);
}
return 1;
}
/*
* Free an option
*/
static void free_op P((opt_apply*, int));
/*ARGSUSED*/
static void free_op(p, b)
opt_apply *p;
int b;
{
if (*p->opt) {
free(*p->opt);
*p->opt = 0;
}
}
/*
* Normalize slashes in the string.
*/
void normalize_slash P((char *p));
void normalize_slash(p)
char *p;
{
char *f = strchr(p, '/');
char *f0 = f;
if (f) {
char *t = f;
do {
/* assert(*f == '/'); */
if (f == f0 && f[0] == '/' && f[1] == '/') {
/* copy double slash iff first */
*t++ = *f++;
*t++ = *f++;
} else {
/* copy a single / across */
*t++ = *f++;
}
/* assert(f[-1] == '/'); */
/* skip past more /'s */
while (*f == '/')
f++;
/* assert(*f != '/'); */
/* keep copying up to next / */
while (*f && *f != '/') {
*t++ = *f++;
}
/* assert(*f == 0 || *f == '/'); */
} while (*f);
*t = 0; /* derived from fix by Steven Glassman */
}
}
/*
* Macro-expand an option. Note that this does not
* handle recursive expansions. They will go badly wrong.
* If sel is true then old expand selectors, otherwise
* don't expand selectors.
*/
static void expand_op P((opt_apply*, int));
static void expand_op(p, sel_p)
opt_apply *p;
int sel_p;
{
/*
* The BUFSPACE macros checks that there is enough space
* left in the expansion buffer. If there isn't then we
* give up completely. This is done to avoid crashing the
* automounter itself (which would be a bad thing to do).
*/
#define BUFSPACE(ep, len) (((ep) + (len)) < expbuf+MAXPATHLEN)
static char expand_error[] = "No space to expand \"%s\"";
char expbuf[MAXPATHLEN+1];
char nbuf[NLEN+1];
char *ep = expbuf;
char *cp = *p->opt;
char *dp;
#ifdef DEBUG
char *cp_orig = *p->opt;
#endif /* DEBUG */
struct opt *op;
while (dp = strchr(cp, '$')) {
char ch;
/*
* First copy up to the $
*/
{ int len = dp - cp;
if (BUFSPACE(ep, len)) {
strncpy(ep, cp, len);
ep += len;
} else {
plog(XLOG_ERROR, expand_error, *p->opt);
goto out;
}
}
cp = dp + 1;
ch = *cp++;
if (ch == '$') {
if (BUFSPACE(ep, 1)) {
*ep++ = '$';
} else {
plog(XLOG_ERROR, expand_error, *p->opt);
goto out;
}
} else if (ch == '{') {
/* Expansion... */
enum { E_All, E_Dir, E_File, E_Domain, E_Host } todo;
/*
* Find closing brace
*/
char *br_p = strchr(cp, '}');
int len;
/*
* Check we found it
*/
if (!br_p) {
/*
* Just give up
*/
plog(XLOG_USER, "No closing '}' in \"%s\"", *p->opt);
goto out;
}
len = br_p - cp;
/*
* Figure out which part of the variable to grab.
*/
if (*cp == '/') {
/*
* Just take the last component
*/
todo = E_File;
cp++;
--len;
} else if (br_p[-1] == '/') {
/*
* Take all but the last component
*/
todo = E_Dir;
--len;
} else if (*cp == '.') {
/*
* Take domain name
*/
todo = E_Domain;
cp++;
--len;
} else if (br_p[-1] == '.') {
/*
* Take host name
*/
todo = E_Host;
--len;
} else {
/*
* Take the whole lot
*/
todo = E_All;
}
/*
* Truncate if too long. Since it won't
* match anyway it doesn't matter that
* it has been cut short.
*/
if (len > NLEN)
len = NLEN;
/*
* Put the string into another buffer so
* we can do comparisons.
*/
strncpy(nbuf, cp, len);
nbuf[len] = '\0';
/*
* Advance cp
*/
cp = br_p + 1;
/*
* Search the option array
*/
for (op = opt_fields; op->name; op++) {
/*
* Check for match
*/
if (len == op->nlen && STREQ(op->name, nbuf)) {
char xbuf[NLEN+3];
char *val;
/*
* Found expansion. Copy
* the correct value field.
*/
if (!(!op->sel_p == !sel_p)) {
/*
* Copy the string across unexpanded
*/
sprintf(xbuf, "${%s%s%s}",
todo == E_File ? "/" :
todo == E_Domain ? "." : "",
nbuf,
todo == E_Dir ? "/" :
todo == E_Host ? "." : "");
val = xbuf;
/*
* Make sure expansion doesn't
* munge the value!
*/
todo = E_All;
} else if (op->sel_p) {
val = *op->sel_p;
} else {
val = *op->optp;
}
if (val) {
/*
* Do expansion:
* ${/var} means take just the last part
* ${var/} means take all but the last part
* ${.var} means take all but first part
* ${var.} means take just the first part
* ${var} means take the whole lot
*/
int vlen = strlen(val);
char *vptr = val;
switch (todo) {
case E_Dir:
vptr = strrchr(val, '/');
if (vptr)
vlen = vptr - val;
vptr = val;
break;
case E_File:
vptr = strrchr(val, '/');
if (vptr) {
vptr++;
vlen = strlen(vptr);
} else
vptr = val;
break;
case E_Domain:
vptr = strchr(val, '.');
if (vptr) {
vptr++;
vlen = strlen(vptr);
} else {
vptr = "";
vlen = 0;
}
break;
case E_Host:
vptr = strchr(val, '.');
if (vptr)
vlen = vptr - val;
vptr = val;
break;
case E_All:
break;
}
#ifdef DEBUG
/*dlog("Expanding \"%s\" to \"%s\"", nbuf, val);*/
#endif /* DEBUG */
if (BUFSPACE(ep, vlen)) {
strcpy(ep, vptr);
ep += vlen;
} else {
plog(XLOG_ERROR, expand_error, *p->opt);
goto out;
}
}
/*
* Done with this variable
*/
break;
}
}
/*
* Check that the search was succesful
*/
if (!op->name) {
/*
* If it wasn't then scan the
* environment for that name
* and use any value found
*/
char *env = getenv(nbuf);
if (env) {
int vlen = strlen(env);
if (BUFSPACE(ep, vlen)) {
strcpy(ep, env);
ep += vlen;
} else {
plog(XLOG_ERROR, expand_error, *p->opt);
goto out;
}
#ifdef DEBUG
Debug(D_STR)
plog(XLOG_DEBUG, "Environment gave \"%s\" -> \"%s\"", nbuf, env);
#endif /* DEBUG */
} else {
plog(XLOG_USER, "Unknown sequence \"${%s}\"", nbuf);
}
}
} else {
/*
* Error, error
*/
plog(XLOG_USER, "Unknown $ sequence in \"%s\"", *p->opt);
}
}
out:
/*
* Handle common case - no expansion
*/
if (cp == *p->opt) {
*p->opt = strdup(cp);
} else {
/*
* Finish off the expansion
*/
if (BUFSPACE(ep, strlen(cp))) {
strcpy(ep, cp);
/*ep += strlen(ep);*/
} else {
plog(XLOG_ERROR, expand_error, *p->opt);
}
/*
* Save the exansion
*/
*p->opt = strdup(expbuf);
}
normalize_slash(*p->opt);
#ifdef DEBUG
Debug(D_STR) {
plog(XLOG_DEBUG, "Expansion of \"%s\"...", cp_orig);
plog(XLOG_DEBUG, "... is \"%s\"", *p->opt);
}
#endif /* DEBUG */
}
/*
* Wrapper for expand_op
*/
static void expand_opts P((opt_apply*, int));
static void expand_opts(p, sel_p)
opt_apply *p;
int sel_p;
{
if (*p->opt) {
expand_op(p, sel_p);
} else if (p->val) {
/*
* Do double expansion, remembering
* to free the string from the first
* expansion...
*/
char *s = *p->opt = expand_key(p->val);
expand_op(p, sel_p);
free(s);
}
}
/*
* Apply a function to a list of options
*/
static void apply_opts(op, ppp, b)
void (*op)();
opt_apply ppp[];
int b;
{
opt_apply *pp;
for (pp = ppp; pp->opt; pp++)
(*op)(pp, b);
}
/*
* Free the option table
*/
void free_opts(fo)
am_opts *fo;
{
/*
* Copy in the structure we are playing with
*/
fs_static = *fo;
/*
* Free previously allocated memory
*/
apply_opts(free_op, to_free, FALSE);
}
/*
* Expand lookup key
*/
char *expand_key(key)
char *key;
{
opt_apply oa;
oa.opt = &key; oa.val = 0;
expand_opts(&oa, TRUE);
return key;
}
/*
* Remove trailing /'s from a string
* unless the string is a single / (Steven Glassman)
*/
void deslashify P((char *s));
void deslashify(s)
char *s;
{
if (s && *s) {
char *sl = s + strlen(s);
while (*--sl == '/' && sl > s)
*sl = '\0';
}
}
int eval_fs_opts(fo, opts, g_opts, path, key, map)
am_opts *fo;
char *opts, *g_opts, *path, *key, *map;
{
int ok = TRUE;
free_opts(fo);
/*
* Clear out the option table
*/
bzero((voidp) &fs_static, sizeof(fs_static));
bzero((voidp) vars, sizeof(vars));
bzero((voidp) fo, sizeof(*fo));
/*
* Set key, map & path before expansion
*/
opt_key = key;
opt_map = map;
opt_path = path;
/*
* Expand global options
*/
fs_static.fs_glob = expand_key(g_opts);
/*
* Expand local options
*/
fs_static.fs_local = expand_key(opts);
/*
* Expand default (global) options
*/
if (!eval_opts(fs_static.fs_glob, key))
ok = FALSE;
/*
* Expand local options
*/
if (ok && !eval_opts(fs_static.fs_local, key))
ok = FALSE;
/*
* Normalise remote host name.
* 1. Expand variables
* 2. Normalize relative to host tables
* 3. Strip local domains from the remote host
* name before using it in other expansions.
* This makes mount point names and other things
* much shorter, while allowing cross domain
* sharing of mount maps.
*/
apply_opts(expand_opts, rhost_expansion, FALSE);
if (ok && fs_static.opt_rhost && *fs_static.opt_rhost)
host_normalize(&fs_static.opt_rhost);
/*
* Macro expand the options.
* Do this regardless of whether we are accepting
* this mount - otherwise nasty things happen
* with memory allocation.
*/
apply_opts(expand_opts, expansions, FALSE);
/*
* Strip trailing slashes from local pathname...
*/
deslashify(fs_static.opt_fs);
/*
* ok... copy the data back out.
*/
*fo = fs_static;
/*
* Clear defined options
*/
opt_key = opt_map = opt_path = nullstr;
return ok;
}

169
usr.sbin/amd/amd/pfs_ops.c Normal file
View file

@ -0,0 +1,169 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pfs_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: pfs_ops.c,v 5.2.2.1 1992/02/09 15:08:56 jsp beta $
*
*/
#include "am.h"
#ifdef HAS_PFS
/*
* Program file system
*/
/*
* Execute needs a mount and unmount command.
*/
static char *pfs_match(fo)
am_opts *fo;
{
char *prog;
if (!fo->opt_mount || !fo->opt_unmount) {
plog(XLOG_USER, "program: no mount/unmount specified");
return 0;
}
prog = strchr(fo->opt_mount, ' ');
return strdup(prog ? prog+1 : fo->opt_mount);
}
static int pfs_init(mf)
mntfs *mf;
{
/*
* Save unmount command
*/
if (mf->mf_refc == 1) {
mf->mf_private = (voidp) strdup(mf->mf_fo->opt_unmount);
mf->mf_prfree = (void (*) ()) free;
}
return 0;
}
static int pfs_exec(info)
char *info;
{
char **xivec;
int error;
/*
* Split copy of command info string
*/
info = strdup(info);
if (info == 0)
return ENOBUFS;
xivec = strsplit(info, ' ', '\'');
/*
* Put stdout to stderr
*/
(void) fclose(stdout);
(void) dup(fileno(logfp));
if (fileno(logfp) != fileno(stderr)) {
(void) fclose(stderr);
(void) dup(fileno(logfp));
}
/*
* Try the exec
*/
#ifdef DEBUG
Debug(D_FULL) {
char **cp = xivec;
plog(XLOG_DEBUG, "executing (un)mount command...");
while (*cp) {
plog(XLOG_DEBUG, "arg[%d] = '%s'", cp-xivec, *cp);
cp++;
}
}
#endif /* DEBUG */
if (xivec[0] == 0 || xivec[1] == 0) {
errno = EINVAL;
plog(XLOG_USER, "1st/2nd args missing to (un)mount program");
} else {
(void) execv(xivec[0], xivec+1);
}
/*
* Save error number
*/
error = errno;
plog(XLOG_ERROR, "exec failed: %m");
/*
* Free allocate memory
*/
free((voidp) info);
free((voidp) xivec);
/*
* Return error
*/
return error;
}
static int pfs_fmount(mf)
mntfs *mf;
{
return pfs_exec(mf->mf_fo->opt_mount);
}
static int pfs_fumount(mf)
mntfs *mf;
{
return pfs_exec((char *) mf->mf_private);
}
/*
* Ops structure
*/
am_ops pfs_ops = {
"program",
pfs_match,
pfs_init,
auto_fmount,
pfs_fmount,
auto_fumount,
pfs_fumount,
efs_lookuppn,
efs_readdir,
0, /* pfs_readlink */
0, /* pfs_mounted */
0, /* pfs_umounted */
find_afs_srvr,
FS_BACKGROUND|FS_AMQINFO
};
#endif /* HAS_PFS */

181
usr.sbin/amd/amd/restart.c Normal file
View file

@ -0,0 +1,181 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: restart.c,v 5.2.2.1 1992/02/09 15:08:59 jsp beta $
*
*/
#ifndef lint
static char sccsid[] = "@(#)restart.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "am.h"
/*
* Handle an amd restart.
*
* Scan through the mount list finding all "interesting" mount points.
* Next hack up partial data structures and add the mounted file
* system to the list of known filesystems. This will leave a
* dangling reference to that filesystems, so when the filesystem is
* finally inherited, an extra "free" must be done on it.
*
* This module relies on internal details of other components. If
* you change something else make *sure* restart() still works.
*/
void restart()
{
/*
* Read the existing mount table
*/
mntlist *ml, *mlp;
/*
* For each entry, find nfs, ufs or auto mounts
* and create a partial am_node to represent it.
*/
for (mlp = ml = read_mtab("restart"); mlp; mlp = mlp->mnext) {
struct mntent *me = mlp->mnt;
am_ops *fs_ops = 0;
if (STREQ(me->mnt_type, MTAB_TYPE_UFS)) {
/*
* UFS entry
*/
fs_ops = &ufs_ops;
} else if (STREQ(me->mnt_type, MTAB_TYPE_NFS)) {
/*
* NFS entry, or possibly an Amd entry...
*/
int au_pid;
char *colon = strchr(me->mnt_fsname, ':');
if (colon && sscanf(colon, ":(pid%d)", &au_pid) == 1) {
plog(XLOG_WARNING, "%s is an existing automount point", me->mnt_dir);
fs_ops = &sfs_ops;
} else {
fs_ops = &nfs_ops;
}
#ifdef MTAB_TYPE_MFS
} else if (STREQ(me->mnt_type, MTAB_TYPE_MFS)) {
/*
* MFS entry. Fake with a symlink.
*/
fs_ops = &sfs_ops;
#endif /* MTAB_TYPE_MFS */
} else {
/*
* Catch everything else with symlinks to
* avoid recursive mounts. This is debatable...
*/
fs_ops = &sfs_ops;
}
/*
* If we found something to do
*/
if (fs_ops) {
mntfs *mf;
am_opts mo;
char *cp;
cp = strchr(me->mnt_fsname, ':');
/*
* Partially fake up an opts structure
*/
mo.opt_rhost = 0;
mo.opt_rfs = 0;
if (cp) {
*cp = '\0';
mo.opt_rhost = strdup(me->mnt_fsname);
mo.opt_rfs = strdup(cp+1);
*cp = ':';
} else if (fs_ops->ffserver == find_nfs_srvr) {
/*
* Prototype 4.4 BSD used to end up here -
* might as well keep the workaround for now
*/
plog(XLOG_WARNING, "NFS server entry assumed to be %s:/", me->mnt_fsname);
mo.opt_rhost = strdup(me->mnt_fsname);
mo.opt_rfs = strdup("/");
me->mnt_fsname = str3cat(me->mnt_fsname, mo.opt_rhost, ":", "/");
}
mo.opt_fs = me->mnt_dir;
mo.opt_opts = me->mnt_opts;
/*
* Make a new mounted filesystem
*/
mf = find_mntfs(fs_ops, &mo, me->mnt_dir,
me->mnt_fsname, "", me->mnt_opts, "");
if (mf->mf_refc == 1) {
mf->mf_flags |= MFF_RESTART|MFF_MOUNTED;
mf->mf_error = 0; /* Already mounted correctly */
mf->mf_fo = 0;
/*
* If the restarted type is a link then
* don't time out.
*/
if (fs_ops == &sfs_ops || fs_ops == &ufs_ops)
mf->mf_flags |= MFF_RSTKEEP;
if (fs_ops->fs_init) {
/*
* Don't care whether this worked since
* it is checked again when the fs is
* inherited.
*/
(void) (*fs_ops->fs_init)(mf);
}
plog(XLOG_INFO, "%s restarted fstype %s on %s",
me->mnt_fsname, fs_ops->fs_type, me->mnt_dir);
} else {
/* Something strange happened - two mounts at the same place! */
free_mntfs(mf);
}
/*
* Clean up mo
*/
if (mo.opt_rhost)
free(mo.opt_rhost);
if (mo.opt_rfs)
free(mo.opt_rfs);
}
}
/*
* Free the mount list
*/
free_mntlist(ml);
}

430
usr.sbin/amd/amd/rpc_fwd.c Normal file
View file

@ -0,0 +1,430 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)rpc_fwd.c 8.1 (Berkeley) 6/6/93
*
* $Id: rpc_fwd.c,v 5.2.2.1 1992/02/09 15:09:01 jsp beta $
*
*/
/*
* RPC packet forwarding
*/
#include "am.h"
#include <sys/ioctl.h>
#ifndef F_SETFL
#include <fcntl.h>
#endif /* F_SETFL */
#ifndef FNDELAY
#include <sys/file.h>
#endif /* FNDELAY */
/*
* Note that the ID field in the external packet is only
* ever treated as a 32 bit opaque data object, so there
* is no need to convert to and from network byte ordering.
*/
/*
* Each pending reply has an rpc_forward structure
* associated with it. These have a 15 second lifespan.
* If a new structure is required, then an expired
* one will be re-allocated if available, otherwise a fresh
* one is allocated. Whenever a reply is received the
* structure is discarded.
*/
typedef struct rpc_forward rpc_forward;
struct rpc_forward {
qelem rf_q; /* Linked list */
time_t rf_ttl; /* Time to live */
u_int rf_xid; /* Packet id */
u_int rf_oldid; /* Original packet id */
fwd_fun rf_fwd; /* Forwarding function */
voidp rf_ptr;
struct sockaddr_in rf_sin;
};
/*
* Head of list of pending replies
*/
extern qelem rpc_head;
qelem rpc_head = { &rpc_head, &rpc_head };
static u_int xid;
#define XID_ALLOC() (xid++)
#define MAX_PACKET_SIZE 8192 /* Maximum UDP packet size */
int fwd_sock;
/*
* Allocate a rely structure
*/
static rpc_forward *fwd_alloc()
{
time_t now = clocktime();
rpc_forward *p = 0, *p2;
#ifdef DEBUG
/*dlog("fwd_alloca: rpc_head = %#x", rpc_head.q_forw);*/
#endif /* DEBUG */
/*
* First search for an existing expired one.
*/
ITER(p2, rpc_forward, &rpc_head) {
if (p2->rf_ttl <= now) {
p = p2;
break;
}
}
/*
* If one couldn't be found then allocate
* a new structure and link it at the
* head of the list.
*/
if (p) {
/*
* Call forwarding function to say that
* this message was junked.
*/
#ifdef DEBUG
dlog("Re-using packet forwarding slot - id %#x", p->rf_xid);
#endif /* DEBUG */
if (p->rf_fwd)
(*p->rf_fwd)(0, 0, 0, &p->rf_sin, p->rf_ptr, FALSE);
rem_que(&p->rf_q);
} else {
p = ALLOC(rpc_forward);
}
ins_que(&p->rf_q, &rpc_head);
/*
* Set the time to live field
* Timeout in 43 seconds
*/
p->rf_ttl = now + 43;
#ifdef DEBUG
/*dlog("fwd_alloca: rpc_head = %#x", rpc_head.q_forw);*/
#endif /* DEBUG */
return p;
}
/*
* Free an allocated reply structure.
* First unlink it from the list, then
* discard it.
*/
static void fwd_free(p)
rpc_forward *p;
{
#ifdef DEBUG
/*dlog("fwd_free: rpc_head = %#x", rpc_head.q_forw);*/
#endif /* DEBUG */
rem_que(&p->rf_q);
#ifdef DEBUG
/*dlog("fwd_free: rpc_head = %#x", rpc_head.q_forw);*/
#endif /* DEBUG */
free((voidp) p);
}
/*
* Initialise the RPC forwarder
*/
int fwd_init()
{
int on = 1;
/*
* Create ping socket
*/
fwd_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (fwd_sock < 0) {
plog(XLOG_ERROR, "Unable to create RPC forwarding socket: %m");
return errno;
}
/*
* Some things we talk to require a priv port - so make one here
*/
if (bind_resv_port(fwd_sock, (unsigned short *) 0) < 0)
plog(XLOG_ERROR, "can't bind privileged port");
if (fcntl(fwd_sock, F_SETFL, FNDELAY) < 0 &&
ioctl(fwd_sock, FIONBIO, &on) < 0) {
plog(XLOG_ERROR, "Can't set non-block on forwarding socket: %m");
return errno;
}
return 0;
}
/*
* Locate a packet in the forwarding list
*/
static rpc_forward *fwd_locate(id)
u_int id;
{
rpc_forward *p;
ITER(p, rpc_forward, &rpc_head) {
if (p->rf_xid == id)
return p;
}
return 0;
}
/*
* This is called to forward a packet to another
* RPC server. The message id is changed and noted
* so that when a reply appears we can tie it up
* correctly. Just matching the reply's source address
* would not work because it might come from a
* different address.
*/
int fwd_packet(type_id, pkt, len, fwdto, replyto, i, cb)
int type_id;
voidp pkt;
int len;
struct sockaddr_in *fwdto, *replyto;
voidp i;
fwd_fun cb;
{
rpc_forward *p;
u_int *pkt_int;
int error;
if ((int)amd_state >= (int)Finishing)
return ENOENT;
/*
* See if the type_id is fully specified.
* If so, then discard any old entries
* for this id.
* Otherwise make sure the type_id is
* fully qualified by allocating an id here.
*/
#ifdef DEBUG
switch (type_id & RPC_XID_MASK) {
case RPC_XID_PORTMAP: dlog("Sending PORTMAP request"); break;
case RPC_XID_MOUNTD: dlog("Sending MOUNTD request %#x", type_id); break;
case RPC_XID_NFSPING: dlog("Sending NFS ping"); break;
default: dlog("UNKNOWN RPC XID"); break;
}
#endif /* DEBUG */
if (type_id & ~RPC_XID_MASK) {
#ifdef DEBUG
/*dlog("Fully qualified rpc type provided");*/
#endif /* DEBUG */
p = fwd_locate(type_id);
if (p) {
#ifdef DEBUG
dlog("Discarding earlier rpc fwd handle");
#endif /* DEBUG */
fwd_free(p);
}
} else {
#ifdef DEBUG
dlog("Allocating a new xid...");
#endif /* DEBUG */
type_id = MK_RPC_XID(type_id, XID_ALLOC());
}
p = fwd_alloc();
if (!p)
return ENOBUFS;
error = 0;
pkt_int = (u_int *) pkt;
/*
* Get the original packet id
*/
p->rf_oldid = *pkt_int;
/*
* Replace with newly allocated id
*/
p->rf_xid = *pkt_int = type_id;
/*
* The sendto may fail if, for example, the route
* to a remote host is lost because an intermediate
* gateway has gone down. Important to fill in the
* rest of "p" otherwise nasty things happen later...
*/
#ifdef DEBUG
{ char dq[20];
dlog("Sending packet id %#x to %s.%d", p->rf_xid, inet_dquad(dq, fwdto->sin_addr.s_addr), ntohs(fwdto->sin_port));
}
#endif /* DEBUG */
if (sendto(fwd_sock, (char *) pkt, len, 0,
(struct sockaddr *) fwdto, sizeof(*fwdto)) < 0)
error = errno;
/*
* Save callback function and return address
*/
p->rf_fwd = cb;
if (replyto)
p->rf_sin = *replyto;
else
bzero((voidp) &p->rf_sin, sizeof(p->rf_sin));
p->rf_ptr = i;
return error;
}
/*
* Called when some data arrives on the forwarding socket
*/
void fwd_reply()
{
int len;
#ifdef DYNAMIC_BUFFERS
voidp pkt;
#else
u_int pkt[MAX_PACKET_SIZE/sizeof(u_int)+1];
#endif /* DYNAMIC_BUFFERS */
u_int *pkt_int;
int rc;
rpc_forward *p;
struct sockaddr_in src_addr;
int src_addr_len;
/*
* Determine the length of the packet
*/
#ifdef DYNAMIC_BUFFERS
if (ioctl(fwd_sock, FIONREAD, &len) < 0) {
plog(XLOG_ERROR, "Error reading packet size: %m");
return;
}
/*
* Allocate a buffer
*/
pkt = (voidp) malloc((unsigned) len);
if (!pkt) {
plog(XLOG_ERROR, "Out of buffers in fwd_reply");
return;
}
#else
len = MAX_PACKET_SIZE;
#endif /* DYNAMIC_BUFFERS */
/*
* Read the packet and check for validity
*/
again:
src_addr_len = sizeof(src_addr);
rc = recvfrom(fwd_sock, (char *) pkt, len, 0,
(struct sockaddr *) &src_addr, &src_addr_len);
if (rc < 0 || src_addr_len != sizeof(src_addr) ||
src_addr.sin_family != AF_INET) {
if (rc < 0 && errno == EINTR)
goto again;
plog(XLOG_ERROR, "Error reading RPC reply: %m");
goto out;
}
#ifdef DYNAMIC_BUFFERS
if (rc != len) {
plog(XLOG_ERROR, "Short read in fwd_reply");
goto out;
}
#endif /* DYNAMIC_BUFFERS */
/*
* Do no more work if finishing soon
*/
if ((int)amd_state >= (int)Finishing)
goto out;
/*
* Find packet reference
*/
pkt_int = (u_int *) pkt;
#ifdef DEBUG
switch (*pkt_int & RPC_XID_MASK) {
case RPC_XID_PORTMAP: dlog("Receiving PORTMAP reply"); break;
case RPC_XID_MOUNTD: dlog("Receiving MOUNTD reply %#x", *pkt_int); break;
case RPC_XID_NFSPING: dlog("Receiving NFS ping %#x", *pkt_int); break;
default: dlog("UNKNOWN RPC XID"); break;
}
#endif /* DEBUG */
p = fwd_locate(*pkt_int);
if (!p) {
#ifdef DEBUG
dlog("Can't forward reply id %#x", *pkt_int);
#endif /* DEBUG */
goto out;
}
if (p->rf_fwd) {
/*
* Put the original message id back
* into the packet.
*/
*pkt_int = p->rf_oldid;
/*
* Call forwarding function
*/
(*p->rf_fwd)((voidp) pkt, rc, &src_addr, &p->rf_sin, p->rf_ptr, TRUE);
}
/*
* Free forwarding info
*/
fwd_free(p);
out:;
#ifdef DYNAMIC_BUFFERS
/*
* Free the packet
*/
free((voidp) pkt);
#endif /* DYNAMIC_BUFFERS */
}

325
usr.sbin/amd/amd/sched.c Normal file
View file

@ -0,0 +1,325 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)sched.c 8.1 (Berkeley) 6/6/93
*
* $Id: sched.c,v 5.2.2.1 1992/02/09 15:09:02 jsp beta $
*
*/
/*
* Process scheduler
*/
#include "am.h"
#include <sys/signal.h>
#include WAIT
#include <setjmp.h>
extern jmp_buf select_intr;
extern int select_intr_valid;
typedef struct pjob pjob;
struct pjob {
qelem hdr; /* Linked list */
int pid; /* Process ID of job */
cb_fun cb_fun; /* Callback function */
voidp cb_closure; /* Closure for callback */
union wait w; /* Status filled in by sigchld */
voidp wchan; /* Wait channel */
};
extern qelem proc_list_head;
qelem proc_list_head = { &proc_list_head, &proc_list_head };
extern qelem proc_wait_list;
qelem proc_wait_list = { &proc_wait_list, &proc_wait_list };
int task_notify_todo;
void ins_que(elem, pred)
qelem *elem, *pred;
{
qelem *p = pred->q_forw;
elem->q_back = pred;
elem->q_forw = p;
pred->q_forw = elem;
p->q_back = elem;
}
void rem_que(elem)
qelem *elem;
{
qelem *p = elem->q_forw;
qelem *p2 = elem->q_back;
p2->q_forw = p;
p->q_back = p2;
}
static pjob *sched_job(cf, ca)
cb_fun cf;
voidp ca;
{
pjob *p = ALLOC(pjob);
p->cb_fun = cf;
p->cb_closure = ca;
/*
* Now place on wait queue
*/
ins_que(&p->hdr, &proc_wait_list);
return p;
}
void run_task(tf, ta, cf, ca)
task_fun tf;
voidp ta;
cb_fun cf;
voidp ca;
{
pjob *p = sched_job(cf, ca);
int mask;
p->wchan = (voidp) p;
mask = sigblock(sigmask(SIGCHLD));
if (p->pid = background()) {
sigsetmask(mask);
return;
}
exit((*tf)(ta));
/* firewall... */
abort();
}
/*
* Schedule a task to be run when woken up
*/
void sched_task(cf, ca, wchan)
cb_fun cf;
voidp ca;
voidp wchan;
{
/*
* Allocate a new task
*/
pjob *p = sched_job(cf, ca);
#ifdef DEBUG_SLEEP
dlog("SLEEP on %#x", wchan);
#endif
p->wchan = wchan;
p->pid = 0;
bzero((voidp) &p->w, sizeof(p->w));
}
static void wakeupjob(p)
pjob *p;
{
rem_que(&p->hdr);
ins_que(&p->hdr, &proc_list_head);
task_notify_todo++;
}
void wakeup(wchan)
voidp wchan;
{
pjob *p, *p2;
#ifdef DEBUG_SLEEP
int done = 0;
#endif
if (!foreground)
return;
#ifdef DEBUG_SLEEP
/*dlog("wakeup(%#x)", wchan);*/
#endif
/*
* Can't user ITER() here because
* wakeupjob() juggles the list.
*/
for (p = FIRST(pjob, &proc_wait_list);
p2 = NEXT(pjob, p), p != HEAD(pjob, &proc_wait_list);
p = p2) {
if (p->wchan == wchan) {
#ifdef DEBUG_SLEEP
done = 1;
#endif
wakeupjob(p);
}
}
#ifdef DEBUG_SLEEP
if (!done)
dlog("Nothing SLEEPing on %#x", wchan);
#endif
}
void wakeup_task(rc, term, cl)
int rc;
int term;
voidp cl;
{
wakeup(cl);
}
/*ARGSUSED*/
void sigchld(sig)
int sig;
{
union wait w;
int pid;
#ifdef SYS5_SIGNALS
if ((pid = wait(&w)) > 0) {
#else
while ((pid = wait3((int *) &w, WNOHANG, (struct rusage *) 0)) > 0) {
#endif /* SYS5_SIGNALS */
pjob *p, *p2;
if (WIFSIGNALED(w))
plog(XLOG_ERROR, "Process %d exited with signal %d",
pid, w.w_termsig);
#ifdef DEBUG
else
dlog("Process %d exited with status %d",
pid, w.w_retcode);
#endif /* DEBUG */
for (p = FIRST(pjob, &proc_wait_list);
p2 = NEXT(pjob, p), p != HEAD(pjob, &proc_wait_list);
p = p2) {
if (p->pid == pid) {
p->w = w;
wakeupjob(p);
break;
}
}
#ifdef DEBUG
if (p) ; else dlog("can't locate task block for pid %d", pid);
#endif /* DEBUG */
}
#ifdef SYS5_SIGNALS
signal(sig, sigchld);
#endif /* SYS5_SIGNALS */
if (select_intr_valid)
longjmp(select_intr, sig);
}
/*
* Run any pending tasks.
* This must be called with SIGCHLD disabled
*/
void do_task_notify(P_void)
{
/*
* Keep taking the first item off the list and processing it.
*
* Done this way because the the callback can, quite reasonably,
* queue a new task, so no local reference into the list can be
* held here.
*/
while (FIRST(pjob, &proc_list_head) != HEAD(pjob, &proc_list_head)) {
pjob *p = FIRST(pjob, &proc_list_head);
rem_que(&p->hdr);
/*
* This job has completed
*/
--task_notify_todo;
/*
* Do callback if it exists
*/
if (p->cb_fun)
(*p->cb_fun)(p->w.w_retcode,
p->w.w_termsig, p->cb_closure);
free((voidp) p);
}
}
#ifdef HAS_SVR3_SIGNALS
/*
* 4.2 signal library based on svr3 (4.1+ bsd) interface
* From Stephen C. Pope <scp@acl.lanl.gov).
*/
static int current_mask = 0;
int sigblock(mask)
int mask;
{
int sig;
int m;
int oldmask;
oldmask = current_mask;
for ( sig = 1, m = 1; sig <= MAXSIG; sig++, m <<= 1 ) {
if (mask & m) {
sighold(sig);
current_mask |= m;
}
}
return oldmask;
}
int sigsetmask(mask)
int mask;
{
int sig;
int m;
int oldmask;
oldmask = current_mask;
for ( sig = 1, m = 1; sig <= MAXSIG; sig++, m <<= 1 ) {
if (mask & m) {
sighold(sig);
current_mask |= m;
}
else {
sigrelse(sig);
current_mask &= ~m;
}
}
return oldmask;
}
#endif /* HAS_SVR3_SIGNALS */

208
usr.sbin/amd/amd/sfs_ops.c Normal file
View file

@ -0,0 +1,208 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)sfs_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: sfs_ops.c,v 5.2.2.1 1992/02/09 15:09:04 jsp beta $
*
*/
#include "am.h"
#if defined(HAS_SFS) || defined(HAS_SFSX)
#define NEED_SFS_MATCH
#define NEED_SFS_UMOUNT
#endif
/*
* Symbol-link file system
*/
#ifdef HAS_SFSX
#include <sys/stat.h>
#endif
#ifdef NEED_SFS_MATCH
/*
* SFS needs a link.
*/
static char *sfs_match(fo)
am_opts *fo;
{
if (!fo->opt_fs) {
plog(XLOG_USER, "link: no fs specified");
return 0;
}
/*
* Bug report (14/12/89) from Jay Plett <jay@princeton.edu>
* If an automount point has the same name as an existing
* link type mount Amd hits a race condition and either hangs
* or causes a symlink loop.
*
* If fs begins with a '/' change the opt_fs & opt_sublink
* fields so that the fs option doesn't end up pointing at
* an existing symlink.
*
* If sublink is nil then set sublink to fs
* else set sublink to fs / sublink
*
* Finally set fs to ".".
*/
if (*fo->opt_fs == '/') {
char *fullpath;
char *link = fo->opt_sublink;
if (link) {
if (*link == '/')
fullpath = strdup(link);
else
fullpath = str3cat((char *)0, fo->opt_fs, "/", link);
} else {
fullpath = strdup(fo->opt_fs);
}
if (fo->opt_sublink)
free(fo->opt_sublink);
fo->opt_sublink = fullpath;
fo->opt_fs = str3cat(fo->opt_fs, ".", fullpath, "");
}
return strdup(fo->opt_fs);
}
#endif
#ifdef HAS_SFSX
/*ARGUSED*/
static int sfsx_mount P((am_node *mp));
static int sfsx_mount(mp)
am_node *mp;
{
/*
* Check for existence of target.
*/
struct stat stb;
char *ln;
if (mp->am_link)
ln = mp->am_link;
else /* should never occur */
ln = mp->am_mnt->mf_mount;
/*
* Use lstat, not stat, since we don't
* want to know if the ultimate target of
* a symlink chain exists, just the first.
*/
if (lstat(ln, &stb) < 0)
return errno;
return 0;
}
#endif
#ifdef HAS_SFS
/*ARGUSED*/
static int sfs_fmount(mf)
mntfs *mf;
{
/*
* Wow - this is hard to implement!
*/
return 0;
}
#endif
#ifdef NEED_SFS_UMOUNT
/*ARGUSED*/
static int sfs_fumount(mf)
mntfs *mf;
{
return 0;
}
#endif
/*
* Ops structures
*/
#ifdef HAS_SFS
am_ops sfs_ops = {
"link",
sfs_match,
0, /* sfs_init */
auto_fmount,
sfs_fmount,
auto_fumount,
sfs_fumount,
efs_lookuppn,
efs_readdir,
0, /* sfs_readlink */
0, /* sfs_mounted */
0, /* sfs_umounted */
find_afs_srvr,
#ifdef FLUSH_KERNEL_NAME_CACHE
FS_UBACKGROUND
#else /* FLUSH_KERNEL_NAME_CACHE */
0
#endif /* FLUSH_KERNEL_NAME_CACHE */
};
#endif /* HAS_SFS */
#ifdef HAS_SFSX
struct am_ops sfsx_ops = {
"linkx",
sfs_match,
0, /* sfsx_init */
sfsx_mount,
0,
auto_fumount,
sfs_fumount,
efs_lookuppn,
efs_readdir,
0, /* sfsx_readlink */
0, /* sfsx_mounted */
0, /* sfsx_umounted */
find_afs_srvr,
#ifdef FLUSH_KERNEL_NAME_CACHE
FS_BACKGROUND
#else /* FLUSH_KERNEL_NAME_CACHE */
FS_MBACKGROUND
#endif /* FLUSH_KERNEL_NAME_CACHE */
};
#endif /* HAS_SFSX */

205
usr.sbin/amd/amd/srvr_afs.c Normal file
View file

@ -0,0 +1,205 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)srvr_afs.c 8.1 (Berkeley) 6/6/93
*
* $Id: srvr_afs.c,v 5.2.2.1 1992/02/09 15:09:05 jsp beta $
*
*/
/*
* Automount FS server ("localhost") modeling
*/
#include "am.h"
extern qelem afs_srvr_list;
qelem afs_srvr_list = { &afs_srvr_list, &afs_srvr_list };
static fserver *localhost;
/*
* Find an nfs server for the local host
*/
fserver *find_afs_srvr P((mntfs *));
fserver *find_afs_srvr(mf)
mntfs *mf;
{
fserver *fs = localhost;
if (!fs) {
fs = ALLOC(fserver);
fs->fs_refc = 0;
fs->fs_host = strdup("localhost");
fs->fs_ip = 0;
fs->fs_cid = 0;
fs->fs_pinger = 0;
fs->fs_flags = FSF_VALID;
fs->fs_type = "local";
fs->fs_private = 0;
fs->fs_prfree = 0;
ins_que(&fs->fs_q, &afs_srvr_list);
srvrlog(fs, "starts up");
localhost = fs;
}
fs->fs_refc++;
return fs;
}
/*------------------------------------------------------------------*/
/* Generic routines follow */
/*
* Wakeup anything waiting for this server
*/
void wakeup_srvr P((fserver *fs));
void wakeup_srvr(fs)
fserver *fs;
{
fs->fs_flags &= ~FSF_WANT;
wakeup((voidp) fs);
}
/*
* Called when final ttl of server has expired
*/
static void timeout_srvr P((fserver *fs));
static void timeout_srvr(fs)
fserver *fs;
{
/*
* If the reference count is still zero then
* we are free to remove this node
*/
if (fs->fs_refc == 0) {
#ifdef DEBUG
dlog("Deleting file server %s", fs->fs_host);
#endif /* DEBUG */
if (fs->fs_flags & FSF_WANT)
wakeup_srvr(fs);
/*
* Remove from queue.
*/
rem_que(&fs->fs_q);
/*
* (Possibly) call the private free routine.
*/
if (fs->fs_private && fs->fs_prfree)
(*fs->fs_prfree)(fs->fs_private);
/*
* Free the net address
*/
if (fs->fs_ip)
free((voidp) fs->fs_ip);
/*
* Free the host name.
*/
free((voidp) fs->fs_host);
/*
* Discard the fserver object.
*/
free((voidp) fs);
}
}
/*
* Free a file server
*/
void free_srvr P((fserver *fs));
void free_srvr(fs)
fserver *fs;
{
if (--fs->fs_refc == 0) {
/*
* The reference count is now zero,
* so arrange for this node to be
* removed in AM_TTL seconds if no
* other mntfs is referencing it.
*/
int ttl = (fs->fs_flags & (FSF_DOWN|FSF_ERROR)) ? 19 : AM_TTL;
#ifdef DEBUG
dlog("Last hard reference to file server %s - will timeout in %ds", fs->fs_host, ttl);
#endif /* DEBUG */
if (fs->fs_cid) {
untimeout(fs->fs_cid);
/*
* Turn off pinging - XXX
*/
fs->fs_flags &= ~FSF_PINGING;
}
/*
* Keep structure lying around for a while
*/
fs->fs_cid = timeout(ttl, timeout_srvr, (voidp) fs);
/*
* Mark the fileserver down and invalid again
*/
fs->fs_flags &= ~FSF_VALID;
fs->fs_flags |= FSF_DOWN;
}
}
/*
* Make a duplicate fserver reference
*/
fserver *dup_srvr P((fserver *fs));
fserver *dup_srvr(fs)
fserver *fs;
{
fs->fs_refc++;
return fs;
}
/*
* Log state change
*/
void srvrlog P((fserver *fs, char *state));
void srvrlog(fs, state)
fserver *fs;
char *state;
{
plog(XLOG_INFO, "file server %s type %s %s", fs->fs_host, fs->fs_type, state);
}

719
usr.sbin/amd/amd/srvr_nfs.c Normal file
View file

@ -0,0 +1,719 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)srvr_nfs.c 8.1 (Berkeley) 6/6/93
*
* $Id: srvr_nfs.c,v 5.2.2.1 1992/02/09 15:09:06 jsp beta $
*
*/
/*
* NFS server modeling
*/
#include "am.h"
#include <netdb.h>
#include <rpc/pmap_prot.h>
#include "mount.h"
extern qelem nfs_srvr_list;
qelem nfs_srvr_list = { &nfs_srvr_list, &nfs_srvr_list };
typedef struct nfs_private {
u_short np_mountd; /* Mount daemon port number */
char np_mountd_inval; /* Port *may* be invalid */
int np_ping; /* Number of failed ping attempts */
time_t np_ttl; /* Time when server is thought dead */
int np_xid; /* RPC transaction id for pings */
int np_error; /* Error during portmap request */
} nfs_private;
static int np_xid; /* For NFS pings */
#define NPXID_ALLOC() (++np_xid)
/*#define NPXID_ALLOC() ((++np_xid&0x0fffffff) == 0 ? npxid_gc() : np_xid)*/
/*
* Number of pings allowed to fail before host is declared down
* - three-fifths of the allowed mount time...
#define MAX_ALLOWED_PINGS ((((ALLOWED_MOUNT_TIME + 5 * AM_PINGER - 1) * 3) / 5) / AM_PINGER)
*/
#define MAX_ALLOWED_PINGS (3 + /* for luck ... */ 1)
/*
* How often to ping when starting a new server
*/
#define FAST_NFS_PING 3
#if (FAST_NFS_PING * MAX_ALLOWED_PINGS) >= ALLOWED_MOUNT_TIME
#error: sanity check failed
/*
you cannot do things this way...
sufficient fast pings must be given the chance to fail
within the allowed mount time
*/
#endif /* (FAST_NFS_PING * MAX_ALLOWED_PINGS) >= ALLOWED_MOUNT_TIME */
static int ping_len;
static char ping_buf[sizeof(struct rpc_msg) + 32];
/*
* Flush any cached data
*/
void flush_srvr_nfs_cache P((void));
void flush_srvr_nfs_cache()
{
fserver *fs = 0;
ITER(fs, fserver, &nfs_srvr_list) {
nfs_private *np = (nfs_private *) fs->fs_private;
if (np) {
np->np_mountd_inval = TRUE;
np->np_error = -1;
}
}
}
/*
* Startup the NFS ping
*/
static void start_ping(P_void);
static void start_ping()
{
XDR ping_xdr;
struct rpc_msg ping_msg;
rpc_msg_init(&ping_msg, NFS_PROGRAM, NFS_VERSION, NFSPROC_NULL);
/*
* Create an XDR endpoint
*/
xdrmem_create(&ping_xdr, ping_buf, sizeof(ping_buf), XDR_ENCODE);
/*
* Create the NFS ping message
*/
if (!xdr_callmsg(&ping_xdr, &ping_msg)) {
plog(XLOG_ERROR, "Couldn't create ping RPC message");
going_down(3);
}
/*
* Find out how long it is
*/
ping_len = xdr_getpos(&ping_xdr);
/*
* Destroy the XDR endpoint - we don't need it anymore
*/
xdr_destroy(&ping_xdr);
}
/*
* Called when a portmap reply arrives
*/
/*ARGSUSED*/
static void got_portmap P((voidp pkt, int len, struct sockaddr_in *sa, struct sockaddr_in *ia, voidp idv, int done));
static void got_portmap(pkt, len, sa, ia, idv, done)
voidp pkt;
int len;
struct sockaddr_in *sa;
struct sockaddr_in *ia;
voidp idv;
int done;
{
fserver *fs2 = (fserver *) idv;
fserver *fs = 0;
/*
* Find which fileserver we are talking about
*/
ITER(fs, fserver, &nfs_srvr_list)
if (fs == fs2)
break;
if (fs == fs2) {
u_long port = 0; /* XXX - should be short but protocol is naff */
int error = done ? pickup_rpc_reply(pkt, len, (voidp) &port, xdr_u_long) : -1;
nfs_private *np = (nfs_private *) fs->fs_private;
if (!error && port) {
#ifdef DEBUG
dlog("got port (%d) for mountd on %s", port, fs->fs_host);
#endif /* DEBUG */
/*
* Grab the port number. Portmap sends back
* an unsigned long in native ordering, so it
* needs converting to a unsigned short in
* network ordering.
*/
np->np_mountd = htons((u_short) port);
np->np_mountd_inval = FALSE;
np->np_error = 0;
} else {
#ifdef DEBUG
dlog("Error fetching port for mountd on %s", fs->fs_host);
#endif /* DEBUG */
/*
* Almost certainly no mountd running on remote host
*/
np->np_error = error ? error : ETIMEDOUT;
}
if (fs->fs_flags & FSF_WANT)
wakeup_srvr(fs);
} else if (done) {
#ifdef DEBUG
dlog("Got portmap for old port request");
#endif /* DEBUG */
} else {
#ifdef DEBUG
dlog("portmap request timed out");
#endif /* DEBUG */
}
}
/*
* Obtain portmap information
*/
static int call_portmap P((fserver *fs, AUTH *auth, unsigned long prog, unsigned long vers, unsigned long prot));
static int call_portmap(fs, auth, prog, vers, prot)
fserver *fs;
AUTH *auth;
unsigned long prog, vers, prot;
{
struct rpc_msg pmap_msg;
int len;
char iobuf[UDPMSGSIZE];
int error;
struct pmap pmap;
rpc_msg_init(&pmap_msg, PMAPPROG, PMAPVERS, (unsigned long) 0);
pmap.pm_prog = prog;
pmap.pm_vers = vers;
pmap.pm_prot = prot;
pmap.pm_port = 0;
len = make_rpc_packet(iobuf, sizeof(iobuf), PMAPPROC_GETPORT,
&pmap_msg, (voidp) &pmap, xdr_pmap, auth);
if (len > 0) {
struct sockaddr_in sin;
bzero((voidp) &sin, sizeof(sin));
sin = *fs->fs_ip;
sin.sin_port = htons(PMAPPORT);
error = fwd_packet(RPC_XID_PORTMAP, (voidp) iobuf, len,
&sin, &sin, (voidp) fs, got_portmap);
} else {
error = -len;
}
return error;
}
static void nfs_keepalive P((fserver*));
static void recompute_portmap P((fserver *fs));
static void recompute_portmap(fs)
fserver *fs;
{
int error;
if (nfs_auth)
error = 0;
else
error = make_nfs_auth();
if (error) {
nfs_private *np = (nfs_private *) fs->fs_private;
np->np_error = error;
} else {
call_portmap(fs, nfs_auth, MOUNTPROG,
MOUNTVERS, (unsigned long) IPPROTO_UDP);
}
}
/*
* This is called when we get a reply to an RPC ping.
* The value of id was taken from the nfs_private
* structure when the ping was transmitted.
*/
/*ARGSUSED*/
static void nfs_pinged P((voidp pkt, int len, struct sockaddr_in *sp, struct sockaddr_in *tsp, voidp idv, int done));
static void nfs_pinged(pkt, len, sp, tsp, idv, done)
voidp pkt;
int len;
struct sockaddr_in *sp;
struct sockaddr_in *tsp;
voidp idv;
int done;
{
int xid = (int) idv;
fserver *fs;
#ifdef DEBUG
int found_map = 0;
#endif /* DEBUG */
if (!done)
return;
/*
* For each node...
*/
ITER(fs, fserver, &nfs_srvr_list) {
nfs_private *np = (nfs_private *) fs->fs_private;
if (np->np_xid == xid) {
/*
* Reset the ping counter.
* Update the keepalive timer.
* Log what happened.
*/
if (fs->fs_flags & FSF_DOWN) {
fs->fs_flags &= ~FSF_DOWN;
if (fs->fs_flags & FSF_VALID) {
srvrlog(fs, "is up");
} else {
if (np->np_ping > 1)
srvrlog(fs, "ok");
#ifdef DEBUG
else
srvrlog(fs, "starts up");
#endif
fs->fs_flags |= FSF_VALID;
}
#ifdef notdef
/* why ??? */
if (fs->fs_flags & FSF_WANT)
wakeup_srvr(fs);
#endif /* notdef */
map_flush_srvr(fs);
} else {
if (fs->fs_flags & FSF_VALID) {
#ifdef DEBUG
dlog("file server %s type nfs is still up", fs->fs_host);
#endif /* DEBUG */
} else {
if (np->np_ping > 1)
srvrlog(fs, "ok");
fs->fs_flags |= FSF_VALID;
}
}
/*
* Adjust ping interval
*/
untimeout(fs->fs_cid);
fs->fs_cid = timeout(fs->fs_pinger, nfs_keepalive, (voidp) fs);
/*
* Update ttl for this server
*/
np->np_ttl = clocktime() +
(MAX_ALLOWED_PINGS - 1) * FAST_NFS_PING + fs->fs_pinger - 1;
/*
* New RPC xid...
*/
np->np_xid = NPXID_ALLOC();
/*
* Failed pings is zero...
*/
np->np_ping = 0;
/*
* Recompute portmap information if not known
*/
if (np->np_mountd_inval)
recompute_portmap(fs);
#ifdef DEBUG
found_map++;
#endif /* DEBUG */
break;
}
}
#ifdef DEBUG
if (found_map == 0)
dlog("Spurious ping packet");
#endif /* DEBUG */
}
/*
* Called when no ping-reply received
*/
static void nfs_timed_out P((fserver *fs));
static void nfs_timed_out(fs)
fserver *fs;
{
nfs_private *np = (nfs_private *) fs->fs_private;
/*
* Another ping has failed
*/
np->np_ping++;
/*
* Not known to be up any longer
*/
if (FSRV_ISUP(fs)) {
fs->fs_flags &= ~FSF_VALID;
if (np->np_ping > 1)
srvrlog(fs, "not responding");
}
/*
* If ttl has expired then guess that it is dead
*/
if (np->np_ttl < clocktime()) {
int oflags = fs->fs_flags;
if ((fs->fs_flags & FSF_DOWN) == 0) {
/*
* Server was up, but is now down.
*/
srvrlog(fs, "is down");
fs->fs_flags |= FSF_DOWN|FSF_VALID;
/*
* Since the server is down, the portmap
* information may now be wrong, so it
* must be flushed from the local cache
*/
flush_nfs_fhandle_cache(fs);
np->np_error = -1;
#ifdef notdef
/*
* Pretend just one ping has failed now
*/
np->np_ping = 1;
#endif
} else {
/*
* Known to be down
*/
#ifdef DEBUG
if ((fs->fs_flags & FSF_VALID) == 0)
srvrlog(fs, "starts down");
#endif
fs->fs_flags |= FSF_VALID;
}
if (oflags != fs->fs_flags && (fs->fs_flags & FSF_WANT))
wakeup_srvr(fs);
} else {
#ifdef DEBUG
if (np->np_ping > 1)
dlog("%d pings to %s failed - at most %d allowed", np->np_ping, fs->fs_host, MAX_ALLOWED_PINGS);
#endif /* DEBUG */
}
/*
* Run keepalive again
*/
nfs_keepalive(fs);
}
/*
* Keep track of whether a server is alive
*/
static void nfs_keepalive P((fserver *fs));
static void nfs_keepalive(fs)
fserver *fs;
{
int error;
nfs_private *np = (nfs_private *) fs->fs_private;
int fstimeo = -1;
/*
* Send an NFS ping to this node
*/
if (ping_len == 0)
start_ping();
/*
* Queue the packet...
*/
error = fwd_packet(MK_RPC_XID(RPC_XID_NFSPING, np->np_xid), (voidp) ping_buf,
ping_len, fs->fs_ip, (struct sockaddr_in *) 0, (voidp) np->np_xid, nfs_pinged);
/*
* See if a hard error occured
*/
switch (error) {
case ENETDOWN:
case ENETUNREACH:
case EHOSTDOWN:
case EHOSTUNREACH:
np->np_ping = MAX_ALLOWED_PINGS; /* immediately down */
np->np_ttl = (time_t) 0;
/*
* This causes an immediate call to nfs_timed_out
* whenever the server was thought to be up.
* See +++ below.
*/
fstimeo = 0;
break;
case 0:
#ifdef DEBUG
dlog("Sent NFS ping to %s", fs->fs_host);
#endif /* DEBUG */
break;
}
#ifdef DEBUG
/*dlog("keepalive, ping = %d", np->np_ping);*/
#endif /* DEBUG */
/*
* Back off the ping interval if we are not getting replies and
* the remote system is know to be down.
*/
switch (fs->fs_flags & (FSF_DOWN|FSF_VALID)) {
case FSF_VALID: /* Up */
if (fstimeo < 0) /* +++ see above */
fstimeo = FAST_NFS_PING;
break;
case FSF_VALID|FSF_DOWN: /* Down */
fstimeo = fs->fs_pinger;
break;
default: /* Unknown */
fstimeo = FAST_NFS_PING;
break;
}
#ifdef DEBUG
dlog("NFS timeout in %d seconds", fstimeo);
#endif /* DEBUG */
fs->fs_cid = timeout(fstimeo, nfs_timed_out, (voidp) fs);
}
int nfs_srvr_port P((fserver *fs, u_short *port, voidp wchan));
int nfs_srvr_port(fs, port, wchan)
fserver *fs;
u_short *port;
voidp wchan;
{
int error = -1;
if ((fs->fs_flags & FSF_VALID) == FSF_VALID) {
if ((fs->fs_flags & FSF_DOWN) == 0) {
nfs_private *np = (nfs_private *) fs->fs_private;
if (np->np_error == 0) {
*port = np->np_mountd;
error = 0;
} else {
error = np->np_error;
}
/*
* Now go get the port mapping again in case it changed.
* Note that it is used even if (np_mountd_inval)
* is True. The flag is used simply as an
* indication that the mountd may be invalid, not
* that it is known to be invalid.
*/
if (np->np_mountd_inval)
recompute_portmap(fs);
else
np->np_mountd_inval = TRUE;
} else {
error = EWOULDBLOCK;
}
}
if (error < 0 && wchan && !(fs->fs_flags & FSF_WANT)) {
/*
* If a wait channel is supplied, and no
* error has yet occured, then arrange
* that a wakeup is done on the wait channel,
* whenever a wakeup is done on this fs node.
* Wakeup's are done on the fs node whenever
* it changes state - thus causing control to
* come back here and new, better things to happen.
*/
fs->fs_flags |= FSF_WANT;
sched_task(wakeup_task, wchan, (voidp) fs);
}
return error;
}
static void start_nfs_pings P((fserver *fs, int pingval));
static void start_nfs_pings(fs, pingval)
fserver *fs;
int pingval;
{
if (!(fs->fs_flags & FSF_PINGING)) {
fs->fs_flags |= FSF_PINGING;
if (fs->fs_cid)
untimeout(fs->fs_cid);
if (pingval < 0) {
srvrlog(fs, "wired up");
fs->fs_flags |= FSF_VALID;
fs->fs_flags &= ~FSF_DOWN;
} else {
nfs_keepalive(fs);
}
} else {
#ifdef DEBUG
dlog("Already running pings to %s", fs->fs_host);
#endif /* DEBUG */
}
}
/*
* Find an nfs server for a host.
*/
fserver *find_nfs_srvr P((mntfs *mf));
fserver *find_nfs_srvr(mf)
mntfs *mf;
{
fserver *fs;
struct hostent *hp = 0;
char *host = mf->mf_fo->opt_rhost;
struct sockaddr_in *ip;
nfs_private *np;
int pingval;
/*
* Get ping interval from mount options.
* Current only used to decide whether pings
* are required or not. < 0 = no pings.
*/
{ struct mntent mnt;
mnt.mnt_opts = mf->mf_mopts;
pingval = hasmntval(&mnt, "ping");
#ifdef HAS_TCP_NFS
/*
* Over TCP mount, don't bother to do pings.
* This is experimental - maybe you want to
* do pings anyway...
*/
if (pingval == 0 && hasmntopt(&mnt, "tcp"))
pingval = -1;
#endif /* HAS_TCP_NFS */
}
/*
* lookup host address and canonical name
*/
hp = gethostbyname(host);
/*
* New code from Bob Harris <harris@basil-rathbone.mit.edu>
* Use canonical name to keep track of file server
* information. This way aliases do not generate
* multiple NFS pingers. (Except when we're normalizing
* hosts.)
*/
if (hp && !normalize_hosts) host = hp->h_name;
ITER(fs, fserver, &nfs_srvr_list) {
if (STREQ(host, fs->fs_host)) {
start_nfs_pings(fs, pingval);
fs->fs_refc++;
return fs;
}
}
/*
* Get here if we can't find an entry
*/
if (hp) {
switch (hp->h_addrtype) {
case AF_INET:
ip = ALLOC(sockaddr_in);
bzero((voidp) ip, sizeof(*ip));
ip->sin_family = AF_INET;
bcopy((voidp) hp->h_addr, (voidp) &ip->sin_addr, sizeof(ip->sin_addr));
ip->sin_port = htons(NFS_PORT);
break;
default:
ip = 0;
break;
}
} else {
plog(XLOG_USER, "Unknown host: %s", host);
ip = 0;
}
/*
* Allocate a new server
*/
fs = ALLOC(fserver);
fs->fs_refc = 1;
fs->fs_host = strdup(hp ? hp->h_name : "unknown_hostname");
if (normalize_hosts) host_normalize(&fs->fs_host);
fs->fs_ip = ip;
fs->fs_cid = 0;
if (ip) {
fs->fs_flags = FSF_DOWN; /* Starts off down */
} else {
fs->fs_flags = FSF_ERROR|FSF_VALID;
mf->mf_flags |= MFF_ERROR;
mf->mf_error = ENOENT;
}
fs->fs_type = "nfs";
fs->fs_pinger = AM_PINGER;
np = ALLOC(nfs_private);
bzero((voidp) np, sizeof(*np));
np->np_mountd_inval = TRUE;
np->np_xid = NPXID_ALLOC();
np->np_error = -1;
/*
* Initially the server will be deemed dead after
* MAX_ALLOWED_PINGS of the fast variety have failed.
*/
np->np_ttl = clocktime() + MAX_ALLOWED_PINGS * FAST_NFS_PING - 1;
fs->fs_private = (voidp) np;
fs->fs_prfree = (void (*)()) free;
if (!(fs->fs_flags & FSF_ERROR)) {
/*
* Start of keepalive timer
*/
start_nfs_pings(fs, pingval);
}
/*
* Add to list of servers
*/
ins_que(&fs->fs_q, &nfs_srvr_list);
return fs;
}

178
usr.sbin/amd/amd/ufs_ops.c Normal file
View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)ufs_ops.c 8.1 (Berkeley) 6/6/93
*
* $Id: ufs_ops.c,v 5.2.2.1 1992/02/09 15:09:08 jsp beta $
*
*/
#include "am.h"
#ifdef HAS_UFS
#include <sys/stat.h>
#ifdef NFS_3
typedef nfs_fh fhandle_t;
#endif /* NFS_3 */
#ifdef UFS_HDR
#include UFS_HDR
#endif /* UFS_HDR */
#include <sys/mount.h>
/*
* UN*X file system
*/
/*
* UFS needs local filesystem and device.
*/
static char *ufs_match P((am_opts *fo));
static char *ufs_match(fo)
am_opts *fo;
{
if (!fo->opt_dev) {
plog(XLOG_USER, "ufs: no device specified");
return 0;
}
#ifdef DEBUG
dlog("UFS: mounting device \"%s\" on \"%s\"",
fo->opt_dev, fo->opt_fs);
#endif /* DEBUG */
/*
* Determine magic cookie to put in mtab
*/
return strdup(fo->opt_dev);
}
static mount_ufs(dir, fs_name, opts)
char *dir;
char *fs_name;
char *opts;
{
struct ufs_args ufs_args;
struct mntent mnt;
int flags;
/*
* Figure out the name of the file system type.
*/
#ifdef M_NEWTYPE
char *type = MOUNT_TYPE_UFS;
#else
int type = MOUNT_TYPE_UFS;
#endif /* M_NEWTYPE */
bzero((voidp) &ufs_args, sizeof(ufs_args)); /* Paranoid */
/*
* Fill in the mount structure
*/
mnt.mnt_dir = dir;
mnt.mnt_fsname = fs_name;
mnt.mnt_type = MTAB_TYPE_UFS;
mnt.mnt_opts = opts;
mnt.mnt_freq = 1;
mnt.mnt_passno = 2;
flags = compute_mount_flags(&mnt);
#ifdef ULTRIX_HACK
ufs_args.ufs_flags = flags;
ufs_args.ufs_pgthresh = 64; /* 64K - XXX */
flags &= M_RDONLY;
#else
ufs_args.fspec = fs_name;
#endif /* ULTRIX_HACK */
/*
* Call generic mount routine
*/
return mount_fs(&mnt, flags, (caddr_t) &ufs_args, 0, type);
}
/*ARGSUSED*/
static int ufs_fmount(mf)
mntfs *mf;
{
int error;
error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts);
if (error) {
errno = error;
plog(XLOG_ERROR, "mount_ufs: %m");
return error;
}
return 0;
}
static int ufs_fumount(mf)
mntfs *mf;
{
return UMOUNT_FS(mf->mf_mount);
}
/*
* Ops structure
*/
am_ops ufs_ops = {
"ufs",
ufs_match,
0, /* ufs_init */
auto_fmount,
ufs_fmount,
auto_fumount,
ufs_fumount,
efs_lookuppn,
efs_readdir,
0, /* ufs_readlink */
0, /* ufs_mounted */
0, /* ufs_umounted */
find_afs_srvr,
#ifdef FLUSH_KERNEL_NAME_CACHE
FS_MKMNT|FS_NOTIMEOUT|FS_UBACKGROUND|FS_AMQINFO
#else /* FLUSH_KERNEL_NAME_CACHE */
FS_MKMNT|FS_NOTIMEOUT|FS_UBACKGROUND|FS_AMQINFO
#endif /* FLUSH_KERNEL_NAME_CACHE */
};
#endif /* HAS_UFS */

View file

@ -0,0 +1,225 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)umount_fs.c 8.1 (Berkeley) 6/6/93
*
* $Id: umount_fs.c,v 5.2.2.1 1992/02/09 15:09:10 jsp beta $
*
*/
#include "am.h"
#ifdef NEED_UMOUNT_BSD
int umount_fs P((char *fs_name));
int umount_fs(fs_name)
char *fs_name;
{
int error;
eintr:
error = unmount(fs_name, 0);
if (error < 0)
error = errno;
switch (error) {
case EINVAL:
case ENOTBLK:
case ENOENT:
plog(XLOG_WARNING, "unmount: %s is not mounted", fs_name);
error = 0; /* Not really an error */
break;
case EINTR:
#ifdef DEBUG
/* not sure why this happens, but it does. ask kirk one day... */
dlog("%s: unmount: %m", fs_name);
#endif /* DEBUG */
goto eintr;
#ifdef DEBUG
default:
dlog("%s: unmount: %m", fs_name);
break;
#endif /* DEBUG */
}
return error;
}
#endif /* NEED_UMOUNT_BSD */
#ifdef NEED_UMOUNT_OSF
#include <sys/mount.h> /* For MNT_NOFORCE */
int umount_fs(fs_name)
char *fs_name;
{
int error;
eintr:
error = umount(fs_name, MNT_NOFORCE);
if (error < 0)
error = errno;
switch (error) {
case EINVAL:
case ENOTBLK:
plog(XLOG_WARNING, "unmount: %s is not mounted", fs_name);
error = 0; /* Not really an error */
break;
case ENOENT:
plog(XLOG_ERROR, "mount point %s: %m", fs_name);
break;
case EINTR:
#ifdef DEBUG
/* not sure why this happens, but it does. ask kirk one day... */
dlog("%s: unmount: %m", fs_name);
#endif /* DEBUG */
goto eintr;
#ifdef DEBUG
default:
dlog("%s: unmount: %m", fs_name);
break;
#endif /* DEBUG */
}
return error;
}
#endif /* NEED_UMOUNT_OSF */
#ifdef NEED_UMOUNT_FS
int umount_fs(fs_name)
char *fs_name;
{
mntlist *mlist, *mp, *mp_save = 0;
int error = 0;
mp = mlist = read_mtab(fs_name);
/*
* Search the mount table looking for
* the correct (ie last) matching entry
*/
while (mp) {
if (strcmp(mp->mnt->mnt_fsname, fs_name) == 0 ||
strcmp(mp->mnt->mnt_dir, fs_name) == 0)
mp_save = mp;
mp = mp->mnext;
}
if (mp_save) {
#ifdef DEBUG
dlog("Trying unmount(%s)", mp_save->mnt->mnt_dir);
#endif /* DEBUG */
/*
* This unmount may hang leaving this
* process with an exlusive lock on
* /etc/mtab. Therefore it is necessary
* to unlock mtab, do the unmount, then
* lock mtab (again) and reread it and
* finally update it.
*/
unlock_mntlist();
if (UNMOUNT_TRAP(mp_save->mnt) < 0) {
switch (error = errno) {
case EINVAL:
case ENOTBLK:
plog(XLOG_WARNING, "unmount: %s is not mounted", mp_save->mnt->mnt_dir);
error = 0; /* Not really an error */
break;
case ENOENT:
plog(XLOG_ERROR, "mount point %s: %m", mp_save->mnt->mnt_dir);
break;
default:
#ifdef DEBUG
dlog("%s: unmount: %m", mp_save->mnt->mnt_dir);
#endif /* DEBUG */
break;
}
}
#ifdef DEBUG
dlog("Finished unmount(%s)", mp_save->mnt->mnt_dir);
#endif
#ifdef UPDATE_MTAB
if (!error) {
free_mntlist(mlist);
mp = mlist = read_mtab(fs_name);
/*
* Search the mount table looking for
* the correct (ie last) matching entry
*/
mp_save = 0;
while (mp) {
if (strcmp(mp->mnt->mnt_fsname, fs_name) == 0 ||
strcmp(mp->mnt->mnt_dir, fs_name) == 0)
mp_save = mp;
mp = mp->mnext;
}
if (mp_save) {
mnt_free(mp_save->mnt);
mp_save->mnt = 0;
rewrite_mtab(mlist);
}
}
#endif /* UPDATE_MTAB */
} else {
plog(XLOG_ERROR, "Couldn't find how to unmount %s", fs_name);
/*
* Assume it is already unmounted
*/
error = 0;
}
free_mntlist(mlist);
return error;
}
#endif /* NEED_UMOUNT_FS */

648
usr.sbin/amd/amd/util.c Normal file
View file

@ -0,0 +1,648 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)util.c 8.1 (Berkeley) 6/6/93
*
* $Id: util.c,v 5.2.2.2 1992/03/07 17:52:06 jsp Exp $
*
*/
/*
* Utils
*/
#include "am.h"
#include <ctype.h>
#include <sys/stat.h>
#include <netdb.h>
char *strnsave(str, len)
Const char *str;
int len;
{
char *sp = (char *) xmalloc(len+1);
bcopy(str, sp, len);
sp[len] = 0;
return sp;
}
char *strdup(s)
Const char *s;
{
return strnsave(s, strlen(s));
}
/*
* Concatenate three strings and store in buffer pointed to
* by p, making p large enough to hold the strings
*/
char *str3cat(p, s1, s2, s3)
char *p;
char *s1;
char *s2;
char *s3;
{
int l1 = strlen(s1);
int l2 = strlen(s2);
int l3 = strlen(s3);
p = (char *) xrealloc(p, l1 + l2 + l3 + 1);
bcopy(s1, p, l1);
bcopy(s2, p + l1, l2);
bcopy(s3, p + l1 + l2, l3 + 1);
return p;
}
char *strealloc(p, s)
char *p;
char *s;
{
int len = strlen(s) + 1;
p = (char *) xrealloc((voidp) p, len);
strcpy(p, s);
#ifdef DEBUG_MEM
malloc_verify();
#endif /* DEBUG_MEM */
return p;
}
char **strsplit P((char *s, int ch, int qc));
char **strsplit(s, ch, qc)
char *s;
int ch;
int qc;
{
char **ivec;
int ic = 0;
int done = 0;
ivec = (char **) xmalloc((ic+1)*sizeof(char *));
while (!done) {
char *v;
/*
* skip to split char
*/
while (*s && (ch == ' ' ? (isascii(*s) && isspace(*s)) : *s == ch))
*s++ = '\0';
/*
* End of string?
*/
if (!*s)
break;
/*
* remember start of string
*/
v = s;
/*
* skip to split char
*/
while (*s && !(ch == ' ' ? (isascii(*s) && isspace(*s)) : *s == ch)) {
if (*s++ == qc) {
/*
* Skip past string.
*/
s++;
while (*s && *s != qc)
s++;
if (*s == qc)
s++;
}
}
if (!*s)
done = 1;
*s++ = '\0';
/*
* save string in new ivec slot
*/
ivec[ic++] = v;
ivec = (char **) xrealloc((voidp) ivec, (ic+1)*sizeof(char *));
#ifdef DEBUG
Debug(D_STR)
plog(XLOG_DEBUG, "strsplit saved \"%s\"", v);
#endif /* DEBUG */
}
#ifdef DEBUG
Debug(D_STR)
plog(XLOG_DEBUG, "strsplit saved a total of %d strings", ic);
#endif /* DEBUG */
ivec[ic] = 0;
return ivec;
}
/*
* Strip off the trailing part of a domain
* to produce a short-form domain relative
* to the local host domain.
* Note that this has no effect if the domain
* names do not have the same number of
* components. If that restriction proves
* to be a problem then the loop needs recoding
* to skip from right to left and do partial
* matches along the way -- ie more expensive.
*/
static void domain_strip P((char *otherdom, char *localdom));
static void domain_strip(otherdom, localdom)
char *otherdom, *localdom;
{
#ifdef PARTIAL_DOMAINS
char *p1 = otherdom-1;
char *p2 = localdom-1;
do {
if (p1 = strchr(p1+1, '.'))
if (p2 = strchr(p2+1, '.'))
if (strcmp(p1+1, p2+1) == 0) {
*p1 = '\0';
break;
}
} while (p1 && p2);
#else
char *p1, *p2;
if ((p1 = strchr(otherdom, '.')) &&
(p2 = strchr(localdom, '.')) &&
(strcmp(p1+1, p2+1) == 0))
*p1 = '\0';
#endif /* PARTIAL_DOMAINS */
}
/*
* Normalize a host name
*/
void host_normalize P((char **chp));
void host_normalize(chp)
char **chp;
{
/*
* Normalize hosts is used to resolve host name aliases
* and replace them with the standard-form name.
* Invoked with "-n" command line option.
*/
if (normalize_hosts) {
struct hostent *hp;
clock_valid = 0;
hp = gethostbyname(*chp);
if (hp && hp->h_addrtype == AF_INET) {
#ifdef DEBUG
dlog("Hostname %s normalized to %s", *chp, hp->h_name);
#endif /* DEBUG */
*chp = strealloc(*chp, hp->h_name);
}
}
domain_strip(*chp, hostd);
}
/*
* Make a dotted quad from a 32bit IP address
* addr is in network byte order.
* sizeof(buf) needs to be at least 16.
*/
char *inet_dquad P((char *buf, unsigned long addr));
char *inet_dquad(buf, addr)
char *buf;
unsigned long addr;
{
addr = ntohl(addr);
sprintf(buf, "%d.%d.%d.%d",
((addr >> 24) & 0xff),
((addr >> 16) & 0xff),
((addr >> 8) & 0xff),
((addr >> 0) & 0xff));
return buf;
}
/*
* Keys are not allowed to contain " ' ! or ; to avoid
* problems with macro expansions.
*/
static char invalid_keys[] = "\"'!;@ \t\n";
int valid_key P((char *key));
int valid_key(key)
char *key;
{
while (*key)
if (strchr(invalid_keys, *key++))
return FALSE;
return TRUE;
}
void going_down P((int rc));
void going_down(rc)
int rc;
{
if (foreground) {
if (amd_state != Start) {
if (amd_state != Done)
return;
unregister_amq();
}
}
if (foreground) {
plog(XLOG_INFO, "Finishing with status %d", rc);
} else {
#ifdef DEBUG
dlog("background process exiting with status %d", rc);
#endif /* DEBUG */
}
exit(rc);
}
int bind_resv_port P((int so, u_short *pp));
int bind_resv_port(so, pp)
int so;
u_short *pp;
{
struct sockaddr_in sin;
int rc;
unsigned short port;
bzero((voidp) &sin, sizeof(sin));
sin.sin_family = AF_INET;
port = IPPORT_RESERVED;
do {
--port;
sin.sin_port = htons(port);
rc = bind(so, (struct sockaddr *) &sin, sizeof(sin));
} while (rc < 0 && port > IPPORT_RESERVED/2);
if (pp && rc == 0)
*pp = port;
return rc;
}
void forcibly_timeout_mp P((am_node *mp));
void forcibly_timeout_mp(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
/*
* Arrange to timeout this node
*/
if (mf && ((mp->am_flags & AMF_ROOT) ||
(mf->mf_flags & (MFF_MOUNTING|MFF_UNMOUNTING)))) {
if (!(mf->mf_flags & MFF_UNMOUNTING))
plog(XLOG_WARNING, "ignoring timeout request for active node %s", mp->am_path);
} else {
plog(XLOG_INFO, "\"%s\" forcibly timed out", mp->am_path);
mp->am_flags &= ~AMF_NOTIMEOUT;
mp->am_ttl = clocktime();
reschedule_timeout_mp();
}
}
void mf_mounted P((mntfs *mf));
void mf_mounted(mf)
mntfs *mf;
{
int quoted;
int wasmounted = mf->mf_flags & MFF_MOUNTED;
if (!wasmounted) {
/*
* If this is a freshly mounted
* filesystem then update the
* mntfs structure...
*/
mf->mf_flags |= MFF_MOUNTED;
mf->mf_error = 0;
/*
* Do mounted callback
*/
if (mf->mf_ops->mounted)
(*mf->mf_ops->mounted)(mf);
mf->mf_fo = 0;
}
/*
* Log message
*/
quoted = strchr(mf->mf_info, ' ') != 0;
plog(XLOG_INFO, "%s%s%s %s fstype %s on %s",
quoted ? "\"" : "",
mf->mf_info,
quoted ? "\"" : "",
wasmounted ? "referenced" : "mounted",
mf->mf_ops->fs_type, mf->mf_mount);
}
void am_mounted P((am_node *mp));
void am_mounted(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
mf_mounted(mf);
/*
* Patch up path for direct mounts
*/
if (mp->am_parent && mp->am_parent->am_mnt->mf_ops == &dfs_ops)
mp->am_path = str3cat(mp->am_path, mp->am_parent->am_path, "/", ".");
/*
* Check whether this mount should be cached permanently
*/
if (mf->mf_ops->fs_flags & FS_NOTIMEOUT) {
mp->am_flags |= AMF_NOTIMEOUT;
} else if (mf->mf_mount[1] == '\0' && mf->mf_mount[0] == '/') {
mp->am_flags |= AMF_NOTIMEOUT;
} else {
struct mntent mnt;
if (mf->mf_mopts) {
mnt.mnt_opts = mf->mf_mopts;
if (hasmntopt(&mnt, "nounmount"))
mp->am_flags |= AMF_NOTIMEOUT;
if ((mp->am_timeo = hasmntval(&mnt, "utimeout")) == 0)
mp->am_timeo = am_timeo;
}
}
/*
* If this node is a symlink then
* compute the length of the returned string.
*/
if (mp->am_fattr.type == NFLNK)
mp->am_fattr.size = strlen(mp->am_link ? mp->am_link : mp->am_mnt->mf_mount);
/*
* Record mount time
*/
mp->am_fattr.mtime.seconds = mp->am_stats.s_mtime = clocktime();
new_ttl(mp);
/*
* Update mtime of parent node
*/
if (mp->am_parent && mp->am_parent->am_mnt)
mp->am_parent->am_fattr.mtime.seconds = mp->am_stats.s_mtime;
/*
* Update stats
*/
amd_stats.d_mok++;
}
int mount_node P((am_node *mp));
int mount_node(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
int error;
mf->mf_flags |= MFF_MOUNTING;
error = (*mf->mf_ops->mount_fs)(mp);
mf = mp->am_mnt;
if (error >= 0)
mf->mf_flags &= ~MFF_MOUNTING;
if (!error && !(mf->mf_ops->fs_flags & FS_MBACKGROUND)) {
/* ...but see ifs_mount */
am_mounted(mp);
}
return error;
}
void am_unmounted P((am_node *mp));
void am_unmounted(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
if (!foreground) /* firewall - should never happen */
return;
#ifdef DEBUG
/*dlog("in am_unmounted(), foreground = %d", foreground);*/
#endif /* DEBUG */
/*
* Do unmounted callback
*/
if (mf->mf_ops->umounted)
(*mf->mf_ops->umounted)(mp);
/*
* Update mtime of parent node
*/
if (mp->am_parent && mp->am_parent->am_mnt)
mp->am_parent->am_fattr.mtime.seconds = clocktime();
free_map(mp);
}
int auto_fmount P((am_node *mp));
int auto_fmount(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
return (*mf->mf_ops->fmount_fs)(mf);
}
int auto_fumount P((am_node *mp));
int auto_fumount(mp)
am_node *mp;
{
mntfs *mf = mp->am_mnt;
return (*mf->mf_ops->fumount_fs)(mf);
}
/*
* Fork the automounter
*
* TODO: Need a better strategy for handling errors
*/
static int dofork(P_void);
static int dofork()
{
int pid;
top:
pid = fork();
if (pid < 0) {
sleep(1);
goto top;
}
if (pid == 0) {
mypid = getpid();
foreground = 0;
}
return pid;
}
int background(P_void);
int background()
{
int pid = dofork();
if (pid == 0) {
#ifdef DEBUG
dlog("backgrounded");
#endif
foreground = 0;
}
return pid;
}
/*
* Make all the directories in the path.
*/
int mkdirs P((char *path, int mode));
int mkdirs(path, mode)
char *path;
int mode;
{
/*
* take a copy in case path is in readonly store
*/
char *p2 = strdup(path);
char *sp = p2;
struct stat stb;
int error_so_far = 0;
/*
* Skip through the string make the directories.
* Mostly ignore errors - the result is tested at the end.
*
* This assumes we are root so that we can do mkdir in a
* mode 555 directory...
*/
while (sp = strchr(sp+1, '/')) {
*sp = '\0';
if (mkdir(p2, mode) < 0) {
error_so_far = errno;
} else {
#ifdef DEBUG
dlog("mkdir(%s)", p2);
#endif
}
*sp = '/';
}
if (mkdir(p2, mode) < 0) {
error_so_far = errno;
} else {
#ifdef DEBUG
dlog("mkdir(%s)", p2);
#endif
}
#ifdef SUNOS4_WORKAROUND
/*
* Do a sync - if we do rmdirs() immediately
* and then the system crashes it leaves
* the filesystem in a state that fsck -p
* can't fix. (Observed more than once on
* SunOS 4 ...)
*
* The problem was caused by a bug somewhere
* in the UFS code which has since been fixed
* (at least at Berkeley).
*
* Attempted workaround - XXX.
*/
sync();
#endif /* SUNOS4_WORKAROUND */
free(p2);
return stat(path, &stb) == 0 &&
(stb.st_mode & S_IFMT) == S_IFDIR ? 0 : error_so_far;
}
/*
* Remove as many directories in the path as possible.
* Give up if the directory doesn't appear to have
* been created by Amd (not mode dr-x) or an rmdir
* fails for any reason.
*/
void rmdirs P((char *dir));
void rmdirs(dir)
char *dir;
{
char *xdp = strdup(dir);
char *dp;
do {
struct stat stb;
/*
* Try to find out whether this was
* created by amd. Do this by checking
* for owner write permission.
*/
if (stat(xdp, &stb) == 0 && (stb.st_mode & 0200) == 0) {
if (rmdir(xdp) < 0) {
if (errno != ENOTEMPTY &&
errno != EBUSY &&
errno != EEXIST &&
errno != EINVAL)
plog(XLOG_ERROR, "rmdir(%s): %m", xdp);
break;
} else {
#ifdef DEBUG
dlog("rmdir(%s)", xdp);
#endif
}
} else {
break;
}
dp = strrchr(xdp, '/');
if (dp)
*dp = '\0';
} while (dp && dp > xdp);
free(xdp);
}

281
usr.sbin/amd/amd/wire.c Normal file
View file

@ -0,0 +1,281 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)wire.c 8.1 (Berkeley) 6/6/93
*
* $Id: wire.c,v 5.2.2.1 1992/02/09 15:09:15 jsp beta $
*
*/
/*
* This function returns the subnet (address&netmask) for the primary network
* interface. If the resulting address has an entry in the hosts file, the
* corresponding name is retuned, otherwise the address is returned in
* standard internet format.
* As a side-effect, a list of local IP/net address is recorded for use
* by the islocalnet() function.
*
* Derived from original by Paul Anderson (23/4/90)
* Updates from Dirk Grunwald (11/11/91)
*/
#include "am.h"
#include <sys/ioctl.h>
#define NO_SUBNET "notknown"
/*
* List of locally connected networks
*/
typedef struct addrlist addrlist;
struct addrlist {
addrlist *ip_next;
unsigned long ip_addr;
unsigned long ip_mask;
};
static addrlist *localnets = 0;
#ifdef SIOCGIFFLAGS
#ifdef STELLIX
#include <sys/sema.h>
#endif /* STELLIX */
#include <net/if.h>
#include <netdb.h>
#if defined(IFF_LOCAL_LOOPBACK) && !defined(IFF_LOOPBACK)
#define IFF_LOOPBACK IFF_LOCAL_LOOPBACK
#endif
#define GFBUFLEN 1024
#define clist (ifc.ifc_ifcu.ifcu_req)
#define count (ifc.ifc_len/sizeof(struct ifreq))
char *getwire P((void));
char *getwire()
{
struct hostent *hp;
struct netent *np;
struct ifconf ifc;
struct ifreq *ifr;
caddr_t cp, cplim;
unsigned long address, netmask, subnet;
char buf[GFBUFLEN], *s;
int sk = -1;
char *netname = 0;
/*
* Get suitable socket
*/
if ((sk = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
goto out;
/*
* Fill in ifconf details
*/
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = buf;
/*
* Get network interface configurations
*/
if (ioctl(sk, SIOCGIFCONF, (caddr_t) &ifc) < 0)
goto out;
/*
* Upper bound on array
*/
cplim = buf + ifc.ifc_len;
/*
* This is some magic to cope with both "traditional" and the
* new 4.4BSD-style struct sockaddrs. The new structure has
* variable length and a size field to support longer addresses.
* AF_LINK is a new definition for 4.4BSD.
*/
#ifdef AF_LINK
#define max(a, b) ((a) > (b) ? (a) : (b))
#define size(ifr) (max((ifr)->ifr_addr.sa_len, sizeof((ifr)->ifr_addr)) + sizeof(ifr->ifr_name))
#else
#define size(ifr) sizeof(*ifr)
#endif
/*
* Scan the list looking for a suitable interface
*/
for (cp = buf; cp < cplim; cp += size(ifr)) {
addrlist *al;
ifr = (struct ifreq *) cp;
if (ifr->ifr_addr.sa_family != AF_INET)
continue;
else
address = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
/*
* Get interface flags
*/
if (ioctl(sk, SIOCGIFFLAGS, (caddr_t) ifr) < 0)
continue;
/*
* If the interface is a loopback, or its not running
* then ignore it.
*/
if ((ifr->ifr_flags & IFF_LOOPBACK) != 0)
continue;
if ((ifr->ifr_flags & IFF_RUNNING) == 0)
continue;
/*
* Get the netmask of this interface
*/
if (ioctl(sk, SIOCGIFNETMASK, (caddr_t) ifr) < 0)
continue;
netmask = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
/*
* Add interface to local network list
*/
al = ALLOC(addrlist);
al->ip_addr = address;
al->ip_mask = netmask;
al->ip_next = localnets;
localnets = al;
if (netname == 0) {
unsigned long net;
unsigned long mask;
unsigned long subnetshift;
/*
* Figure out the subnet's network address
*/
subnet = address & netmask;
#ifdef IN_CLASSA
subnet = ntohl(subnet);
if (IN_CLASSA(subnet)) {
mask = IN_CLASSA_NET;
subnetshift = 8;
} else if (IN_CLASSB(subnet)) {
mask = IN_CLASSB_NET;
subnetshift = 8;
} else {
mask = IN_CLASSC_NET;
subnetshift = 4;
}
/*
* If there are more bits than the standard mask
* would suggest, subnets must be in use.
* Guess at the subnet mask, assuming reasonable
* width subnet fields.
* XXX: Or-in at least 1 byte's worth of 1s to make
* sure the top bits remain set.
*/
while (subnet &~ mask)
mask = (mask >> subnetshift) | 0xff000000;
net = subnet & mask;
while ((mask & 1) == 0)
mask >>= 1, net >>= 1;
/*
* Now get a usable name.
* First use the network database,
* then the host database,
* and finally just make a dotted quad.
*/
np = getnetbyaddr(net, AF_INET);
#else
/* This is probably very wrong. */
np = getnetbyaddr(subnet, AF_INET);
#endif /* IN_CLASSA */
if (np)
s = np->n_name;
else {
subnet = address & netmask;
hp = gethostbyaddr((char *) &subnet, 4, AF_INET);
if (hp)
s = hp->h_name;
else
s = inet_dquad(buf, subnet);
}
netname = strdup(s);
}
}
out:
if (sk >= 0)
(void) close(sk);
if (netname)
return netname;
return strdup(NO_SUBNET);
}
#else
char *getwire P((void));
char *getwire()
{
return strdup(NO_SUBNET);
}
#endif /* SIOCGIFFLAGS */
/*
* Determine whether a network is on a local network
* (addr) is in network byte order.
*/
int islocalnet P((unsigned long addr));
int islocalnet(addr)
unsigned long addr;
{
addrlist *al;
for (al = localnets; al; al = al->ip_next)
if (((addr ^ al->ip_addr) & al->ip_mask) == 0)
return TRUE;
#ifdef DEBUG
{ char buf[16];
plog(XLOG_INFO, "%s is on a remote network", inet_dquad(buf, addr));
}
#endif
return FALSE;
}

491
usr.sbin/amd/amd/xutil.c Normal file
View file

@ -0,0 +1,491 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)xutil.c 8.1 (Berkeley) 6/6/93
*
* $Id: xutil.c,v 5.2.2.3 1992/03/07 10:36:09 jsp Exp $
*
*/
#include "config.h"
#ifdef HAS_SYSLOG
#include <syslog.h>
#endif /* HAS_SYSLOG */
#ifdef HAS_STRERROR
#include <string.h>
#endif
FILE *logfp = stderr; /* Log errors to stderr initially */
#ifdef HAS_SYSLOG
int syslogging;
#endif /* HAS_SYSLOG */
int xlog_level = XLOG_ALL & ~XLOG_MAP & ~XLOG_STATS;
int xlog_level_init = ~0;
/*
* List of log options
*/
struct opt_tab xlog_opt[] = {
{ "all", XLOG_ALL }, /* All messages */
#ifdef DEBUG
{ "debug", XLOG_DEBUG }, /* Debug messages */
#endif /* DEBUG */
{ "error", XLOG_ERROR }, /* Non-fatal system errors */
{ "fatal", XLOG_FATAL }, /* Fatal errors */
{ "info", XLOG_INFO }, /* Information */
{ "map", XLOG_MAP }, /* Map errors */
{ "stats", XLOG_STATS }, /* Additional statistical information */
{ "user", XLOG_USER }, /* Non-fatal user errors */
{ "warn", XLOG_WARNING }, /* Warnings */
{ "warning", XLOG_WARNING }, /* Warnings */
{ 0, 0 }
};
voidp xmalloc(len)
int len;
{
voidp p;
int retries = 600;
/*
* Avoid malloc's which return NULL for malloc(0)
*/
if (len == 0)
len = 1;
do {
p = (voidp) malloc((unsigned) len);
if (p) {
#if defined(DEBUG) && defined(DEBUG_MEM)
Debug(D_MEM) plog(XLOG_DEBUG, "Allocated size %d; block %#x", len, p);
#endif /* defined(DEBUG) && defined(DEBUG_MEM) */
return p;
}
if (retries > 0) {
plog(XLOG_ERROR, "Retrying memory allocation");
sleep(1);
}
} while (--retries);
plog(XLOG_FATAL, "Out of memory");
going_down(1);
abort();
return 0;
}
voidp xrealloc(ptr, len)
voidp ptr;
int len;
{
#if defined(DEBUG) && defined(DEBUG_MEM)
Debug(D_MEM) plog(XLOG_DEBUG, "Reallocated size %d; block %#x", len, ptr);
#endif /* defined(DEBUG) && defined(DEBUG_MEM) */
if (len == 0)
len = 1;
if (ptr)
ptr = (voidp) realloc(ptr, (unsigned) len);
else
ptr = (voidp) xmalloc((unsigned) len);
if (!ptr) {
plog(XLOG_FATAL, "Out of memory in realloc");
going_down(1);
abort();
}
return ptr;
}
#if defined(DEBUG) && defined(DEBUG_MEM)
xfree(f, l, p)
char *f;
int l;
voidp p;
{
Debug(D_MEM) plog(XLOG_DEBUG, "Free in %s:%d: block %#x", f, l, p);
#undef free
free(p);
}
#endif /* defined(DEBUG) && defined(DEBUG_MEM) */
#ifdef DEBUG_MEM
static int mem_bytes;
static int orig_mem_bytes;
static void checkup_mem(P_void)
{
extern struct mallinfo __mallinfo;
if (mem_bytes != __mallinfo.uordbytes) {
if (orig_mem_bytes == 0)
mem_bytes = orig_mem_bytes = __mallinfo.uordbytes;
else {
fprintf(logfp, "%s[%d]: ", progname, mypid);
if (mem_bytes < __mallinfo.uordbytes) {
fprintf(logfp, "ALLOC: %d bytes",
__mallinfo.uordbytes - mem_bytes);
} else {
fprintf(logfp, "FREE: %d bytes",
mem_bytes - __mallinfo.uordbytes);
}
mem_bytes = __mallinfo.uordbytes;
fprintf(logfp, ", making %d missing\n",
mem_bytes - orig_mem_bytes);
}
}
malloc_verify();
}
#endif /* DEBUG_MEM */
/*
* Take a log format string and expand occurences of %m
* with the current error code take from errno.
*/
INLINE
static void expand_error(f, e)
char *f;
char *e;
{
#ifndef HAS_STRERROR
extern int sys_nerr;
extern char *sys_errlist[];
#endif
char *p;
int error = errno;
for (p = f; *e = *p; e++, p++) {
if (p[0] == '%' && p[1] == 'm') {
char *errstr;
#ifdef HAS_STRERROR
errstr = strerror(error);
#else
if (error < 0 || error >= sys_nerr)
errstr = 0;
else
errstr = sys_errlist[error];
#endif
if (errstr)
strcpy(e, errstr);
else
sprintf(e, "Error %d", error);
e += strlen(e) - 1;
p++;
}
}
}
/*
* Output the time of day and hostname to the logfile
*/
static void show_time_host_and_name(lvl)
int lvl;
{
static time_t last_t = 0;
static char *last_ctime = 0;
time_t t = clocktime();
char *sev;
extern char *ctime();
#if defined(DEBUG) && defined(PARANOID)
extern char **gargv;
#endif /* defined(DEBUG) && defined(PARANOID) */
if (t != last_t) {
last_ctime = ctime(&t);
last_t = t;
}
switch (lvl) {
case XLOG_FATAL: sev = "fatal:"; break;
case XLOG_ERROR: sev = "error:"; break;
case XLOG_USER: sev = "user: "; break;
case XLOG_WARNING: sev = "warn: "; break;
case XLOG_INFO: sev = "info: "; break;
case XLOG_DEBUG: sev = "debug:"; break;
case XLOG_MAP: sev = "map: "; break;
case XLOG_STATS: sev = "stats:"; break;
default: sev = "hmm: "; break;
}
fprintf(logfp, "%15.15s %s %s[%d]/%s ",
last_ctime+4, hostname,
#if defined(DEBUG) && defined(PARANOID)
gargv[0],
#else
progname,
#endif /* defined(DEBUG) && defined(PARANOID) */
mypid,
sev);
}
#ifdef DEBUG
/*VARARGS1*/
void dplog(fmt, j,s,_,p,e,n,d,r,y)
char *fmt;
char *j, *s, *_, *p, *e, *n, *d, *r, *y;
{
plog(XLOG_DEBUG, fmt, j,s,_,p,e,n,d,r,y);
}
#endif /* DEBUG */
/*VARARGS1*/
void plog(lvl, fmt, j,s,_,p,e,n,d,r,y)
int lvl;
char *fmt;
char *j, *s, *_, *p, *e, *n, *d, *r, *y;
{
char msg[1024];
char efmt[1024];
char *ptr = msg;
if (!(xlog_level & lvl))
return;
#ifdef DEBUG_MEM
checkup_mem();
#endif /* DEBUG_MEM */
expand_error(fmt, efmt);
sprintf(ptr, efmt, j,s,_,p,e,n,d,r,y);
ptr += strlen(ptr);
if (ptr[-1] == '\n')
*--ptr = '\0';
#ifdef HAS_SYSLOG
if (syslogging) {
switch(lvl) { /* from mike <mcooper@usc.edu> */
case XLOG_FATAL: lvl = LOG_CRIT; break;
case XLOG_ERROR: lvl = LOG_ERR; break;
case XLOG_USER: lvl = LOG_WARNING; break;
case XLOG_WARNING: lvl = LOG_WARNING; break;
case XLOG_INFO: lvl = LOG_INFO; break;
case XLOG_DEBUG: lvl = LOG_DEBUG; break;
case XLOG_MAP: lvl = LOG_DEBUG; break;
case XLOG_STATS: lvl = LOG_INFO; break;
default: lvl = LOG_ERR; break;
}
syslog(lvl, "%s", msg);
return;
}
#endif /* HAS_SYSLOG */
*ptr++ = '\n';
*ptr = '\0';
/*
* Mimic syslog header
*/
show_time_host_and_name(lvl);
fwrite(msg, ptr - msg, 1, logfp);
fflush(logfp);
}
void show_opts P((int ch, struct opt_tab *opts));
void show_opts(ch, opts)
int ch;
struct opt_tab *opts;
{
/*
* Display current debug options
*/
int i;
int s = '{';
fprintf(stderr, "\t[-%c {no}", ch);
for (i = 0; opts[i].opt; i++) {
fprintf(stderr, "%c%s", s, opts[i].opt);
s = ',';
}
fputs("}]\n", stderr);
}
int cmdoption P((char *s, struct opt_tab *optb, int *flags));
int cmdoption(s, optb, flags)
char *s;
struct opt_tab *optb;
int *flags;
{
char *p = s;
int errs = 0;
while (p && *p) {
int neg;
char *opt;
struct opt_tab *dp, *dpn = 0;
s = p;
p = strchr(p, ',');
if (p)
*p = '\0';
if (s[0] == 'n' && s[1] == 'o') {
opt = s + 2;
neg = 1;
} else {
opt = s;
neg = 0;
}
/*
* Scan the array of debug options to find the
* corresponding flag value. If it is found
* then set (or clear) the flag (depending on
* whether the option was prefixed with "no").
*/
for (dp = optb; dp->opt; dp++) {
if (strcmp(opt, dp->opt) == 0)
break;
if (opt != s && !dpn && strcmp(s, dp->opt) == 0)
dpn = dp;
}
if (dp->opt || dpn) {
if (!dp->opt) {
dp = dpn;
neg = !neg;
}
if (neg)
*flags &= ~dp->flag;
else
*flags |= dp->flag;
} else {
/*
* This will log to stderr when parsing the command line
* since any -l option will not yet have taken effect.
*/
plog(XLOG_USER, "option \"%s\" not recognised", s);
errs++;
}
/*
* Put the comma back
*/
if (p)
*p++ = ',';
}
return errs;
}
/*
* Switch on/off logging options
*/
int switch_option(opt)
char *opt;
{
int xl = xlog_level;
int rc = cmdoption(opt, xlog_opt, &xl);
if (rc) {
rc = EINVAL;
} else {
/*
* Keep track of initial log level, and
* don't allow options to be turned off.
*/
if (xlog_level_init == ~0)
xlog_level_init = xl;
else
xl |= xlog_level_init;
xlog_level = xl;
}
return rc;
}
/*
* Change current logfile
*/
int switch_to_logfile P((char *logfile));
int switch_to_logfile(logfile)
char *logfile;
{
FILE *new_logfp = stderr;
if (logfile) {
#ifdef HAS_SYSLOG
syslogging = 0;
#endif /* HAS_SYSLOG */
if (strcmp(logfile, "/dev/stderr") == 0)
new_logfp = stderr;
else if (strcmp(logfile, "syslog") == 0) {
#ifdef HAS_SYSLOG
syslogging = 1;
new_logfp = stderr;
#if defined(LOG_CONS) && defined(LOG_NOWAIT)
openlog(progname, LOG_PID|LOG_CONS|LOG_NOWAIT,
LOG_DAEMON);
#else
/* 4.2 compat mode - XXX */
openlog(progname, LOG_PID);
#endif /* LOG_CONS && LOG_NOWAIT */
#else
plog(XLOG_WARNING, "syslog option not supported, logging unchanged");
#endif /* HAS_SYSLOG */
} else {
(void) umask(orig_umask);
new_logfp = fopen(logfile, "a");
umask(0);
}
}
/*
* If we couldn't open a new file, then continue using the old.
*/
if (!new_logfp && logfile) {
plog(XLOG_USER, "%s: Can't open logfile: %m", logfile);
return 1;
}
/*
* Close the previous file
*/
if (logfp && logfp != stderr)
(void) fclose(logfp);
logfp = new_logfp;
return 0;
}
time_t clock_valid = 0;
time_t xclock_valid = 0;
#ifndef clocktime
time_t clocktime(P_void)
{
time_t now = time(&clock_valid);
if (xclock_valid > now) {
/*
* Someone set the clock back!
*/
plog(XLOG_WARNING, "system clock reset");
reschedule_timeouts(now, xclock_valid);
}
return xclock_valid = now;
}
#endif /* clocktime */

15
usr.sbin/amd/amq/Makefile Normal file
View file

@ -0,0 +1,15 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG = amq
SRCS = amq.c amq_clnt.c amq_xdr.c misc_rpc.c
LDADD+=-lrpc
CFLAGS+=-I${.CURDIR}/../include
CFLAGS+=-I${.CURDIR}/../rpcx
CFLAGS+=-I${.CURDIR}/../config
CFLAGS+=-DARCH_REP=\"${MACHINE}\"
CFLAGS+=-DOS_REP=\"bsd44\"
CFLAGS+=-DOS_HDR=\"os-bsd44.h\"
.PATH: ${.CURDIR}/../rpcx ${.CURDIR}/../amd
.include "../../Makefile.inc"
.include <bsd.prog.mk>

130
usr.sbin/amd/amq/amq.8 Normal file
View file

@ -0,0 +1,130 @@
.\"
.\" Copyright (c) 1990 Jan-Simon Pendry
.\" Copyright (c) 1990 Imperial College of Science, Technology & Medicine
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Jan-Simon Pendry at Imperial College, London.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)amq.8 8.3 (Berkeley) 4/18/94
.\"
.\" $Id: amq.8,v 5.2.2.1 1992/02/09 15:11:41 jsp beta $
.\"
.Dd March 16, 1991
.Dt AMQ 8
.Os
.Sh NAME
.Nm amq
.Nd automounter query tool
.Sh SYNOPSIS
.Nm amq
.Op Fl f
.Op Fl h Ar hostname
.Op Fl M Ar mountmap_entry
.Op Fl m
.Op Fl s
.Op Fl u
.Op Fl v
.Op Ar directory
.Ar ...
.Sh DESCRIPTION
.Nm Amq
provides a simple way of determining the current state of the
.Xr amd 8
program.
Communication is by
.Tn RPC .
Three modes of operation are supported by the current protocol.
By default a list of mount points and auto-mounted filesystems
is output.
An alternative host can be specified using the
.Fl h
option.
.Pp
If directory names are given, as output by default,
then per-filesystem information is displayed.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl f
Request automounter to flush the internal caches.
.It Fl h Ar hostname
Query alternate host
.Ar hostname .
By default the local host is used. In an
.Tn HP-UX
cluster, the root server is queried by default, since
that is the system on which the automounter is normally run.
.It Fl m
Request the automounter to provide a list of mounted filesystems,
including the number of references to each filesystem and any error
which occurred while mounting.
.It Fl s
Request the automounter to provide system-wide mount statistics.
.It Fl u
Request the automounter to unmount the named filesystems
instead of providing information about them. Unmounts are requested,
not forced. They merely cause the mounted filesystem to timeout,
which will be picked up by
.Xr amd Ns \'s
main scheduler thus causing the normal timeout action to be taken.
.It Fl v
Request the automounter to provide version information. This is a subset
of the information provided by
.Xr amd Ns \'s Fl v
option.
.It Fl M
Request automounter to add the given map entry to the root map and then
trigger a mount request for it.
.El
.Sh FILES
.Bl -tag -width amq.xxxxx -compact
.Bl -tag -width Ds
.It Pa amq.x
.Tn RPC
protocol description.
.El
.Sh CAVEATS
.Nm Amq
uses a Sun registered
.Tn RPC
program number (300019 decimal) which may not
be in the
.Pa /etc/rpc
database.
.Sh SEE ALSO
.Xr amd 8
.Sh AUTHOR
.An Jan-Simon Pendry
<jsp@doc.ic.ac.uk>, Department of Computing, Imperial College, London, UK.
.Sh HISTORY
.Nm Amq
.At

666
usr.sbin/amd/amq/amq.c Normal file
View file

@ -0,0 +1,666 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)amq.c 8.1 (Berkeley) 6/7/93
*
* $Id: amq.c,v 5.2.2.1 1992/02/09 15:09:16 jsp beta $
*
*/
/*
* Automounter query tool
*/
#ifndef lint
char copyright[] = "\
@(#)Copyright (c) 1990 Jan-Simon Pendry\n\
@(#)Copyright (c) 1990 Imperial College of Science, Technology & Medicine\n\
@(#)Copyright (c) 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char rcsid[] = "$Id: amq.c,v 5.2.2.1 1992/02/09 15:09:16 jsp beta $";
static char sccsid[] = "@(#)amq.c 8.1 (Berkeley) 6/7/93";
#endif /* not lint */
#include "am.h"
#include "amq.h"
#include <stdio.h>
#include <fcntl.h>
#include <netdb.h>
static int privsock();
char *progname;
static int flush_flag;
static int minfo_flag;
static int unmount_flag;
static int stats_flag;
static int getvers_flag;
static char *debug_opts;
static char *logfile;
static char *mount_map;
static char *xlog_optstr;
static char localhost[] = "localhost";
static char *def_server = localhost;
extern int optind;
extern char *optarg;
static struct timeval tmo = { 10, 0 };
#define TIMEOUT tmo
enum show_opt { Full, Stats, Calc, Short, ShowDone };
/*
* If (e) is Calc then just calculate the sizes
* Otherwise display the mount node on stdout
*/
static void show_mti(mt, e, mwid, dwid, twid)
amq_mount_tree *mt;
enum show_opt e;
int *mwid;
int *dwid;
int *twid;
{
switch (e) {
case Calc: {
int mw = strlen(mt->mt_mountinfo);
int dw = strlen(mt->mt_directory);
int tw = strlen(mt->mt_type);
if (mw > *mwid) *mwid = mw;
if (dw > *dwid) *dwid = dw;
if (tw > *twid) *twid = tw;
} break;
case Full: {
struct tm *tp = localtime((time_t *) &mt->mt_mounttime);
printf("%-*.*s %-*.*s %-*.*s %s\n\t%-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%02d\n",
*dwid, *dwid,
*mt->mt_directory ? mt->mt_directory : "/", /* XXX */
*twid, *twid,
mt->mt_type,
*mwid, *mwid,
mt->mt_mountinfo,
mt->mt_mountpoint,
mt->mt_mountuid,
mt->mt_getattr,
mt->mt_lookup,
mt->mt_readdir,
mt->mt_readlink,
mt->mt_statfs,
tp->tm_year > 99 ? tp->tm_year - 100 : tp->tm_year,
tp->tm_mon+1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec);
} break;
case Stats: {
struct tm *tp = localtime((time_t *) &mt->mt_mounttime);
printf("%-*.*s %-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%02d\n",
*dwid, *dwid,
*mt->mt_directory ? mt->mt_directory : "/", /* XXX */
mt->mt_mountuid,
mt->mt_getattr,
mt->mt_lookup,
mt->mt_readdir,
mt->mt_readlink,
mt->mt_statfs,
tp->tm_year > 99 ? tp->tm_year - 100 : tp->tm_year,
tp->tm_mon+1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec);
} break;
case Short: {
printf("%-*.*s %-*.*s %-*.*s %s\n",
*dwid, *dwid,
*mt->mt_directory ? mt->mt_directory : "/",
*twid, *twid,
mt->mt_type,
*mwid, *mwid,
mt->mt_mountinfo,
mt->mt_mountpoint);
} break;
}
}
/*
* Display a mount tree.
*/
static void show_mt(mt, e, mwid, dwid, pwid)
amq_mount_tree *mt;
enum show_opt e;
int *mwid;
int *dwid;
int *pwid;
{
while (mt) {
show_mti(mt, e, mwid, dwid, pwid);
show_mt(mt->mt_next, e, mwid, dwid, pwid);
mt = mt->mt_child;
}
}
static void show_mi(ml, e, mwid, dwid, twid)
amq_mount_info_list *ml;
enum show_opt e;
int *mwid;
int *dwid;
int *twid;
{
int i;
switch (e) {
case Calc: {
for (i = 0; i < ml->amq_mount_info_list_len; i++) {
amq_mount_info *mi = &ml->amq_mount_info_list_val[i];
int mw = strlen(mi->mi_mountinfo);
int dw = strlen(mi->mi_mountpt);
int tw = strlen(mi->mi_type);
if (mw > *mwid) *mwid = mw;
if (dw > *dwid) *dwid = dw;
if (tw > *twid) *twid = tw;
}
} break;
case Full: {
for (i = 0; i < ml->amq_mount_info_list_len; i++) {
amq_mount_info *mi = &ml->amq_mount_info_list_val[i];
printf("%-*.*s %-*.*s %-*.*s %-3d %s is %s",
*mwid, *mwid, mi->mi_mountinfo,
*dwid, *dwid, mi->mi_mountpt,
*twid, *twid, mi->mi_type,
mi->mi_refc, mi->mi_fserver,
mi->mi_up > 0 ? "up" :
mi->mi_up < 0 ? "starting" : "down");
if (mi->mi_error > 0) {
#ifdef HAS_STRERROR
printf(" (%s)", strerror(mi->mi_error));
#else
extern char *sys_errlist[];
extern int sys_nerr;
if (mi->mi_error < sys_nerr)
printf(" (%s)", sys_errlist[mi->mi_error]);
else
printf(" (Error %d)", mi->mi_error);
#endif
} else if (mi->mi_error < 0) {
fputs(" (in progress)", stdout);
}
fputc('\n', stdout);
}
} break;
}
}
/*
* Display general mount statistics
*/
static void show_ms(ms)
amq_mount_stats *ms;
{
printf("\
requests stale mount mount unmount\n\
deferred fhandles ok failed failed\n\
%-9d %-9d %-9d %-9d %-9d\n",
ms->as_drops, ms->as_stale, ms->as_mok, ms->as_merr, ms->as_uerr);
}
static bool_t
xdr_pri_free(xdr_args, args_ptr)
xdrproc_t xdr_args;
caddr_t args_ptr;
{
XDR xdr;
xdr.x_op = XDR_FREE;
return ((*xdr_args)(&xdr, args_ptr));
}
#ifdef hpux
#include <cluster.h>
static char *cluster_server()
{
struct cct_entry *cp;
if (cnodeid() == 0) {
/*
* Not clustered
*/
return def_server;
}
while (cp = getccent())
if (cp->cnode_type == 'r')
return cp->cnode_name;
return def_server;
}
#endif /* hpux */
/*
* MAIN
*/
main(argc, argv)
int argc;
char *argv[];
{
int opt_ch;
int errs = 0;
char *server;
struct sockaddr_in server_addr;
/* In order to pass the Amd security check, we must use a priv port. */
int s;
CLIENT *clnt;
struct hostent *hp;
int nodefault = 0;
/*
* Compute program name
*/
if (argv[0]) {
progname = strrchr(argv[0], '/');
if (progname && progname[1])
progname++;
else
progname = argv[0];
}
if (!progname)
progname = "amq";
/*
* Parse arguments
*/
while ((opt_ch = getopt(argc, argv, "fh:l:msuvx:D:M:")) != EOF)
switch (opt_ch) {
case 'f':
flush_flag = 1;
nodefault = 1;
break;
case 'h':
def_server = optarg;
break;
case 'l':
logfile = optarg;
nodefault = 1;
break;
case 'm':
minfo_flag = 1;
nodefault = 1;
break;
case 's':
stats_flag = 1;
nodefault = 1;
break;
case 'u':
unmount_flag = 1;
nodefault = 1;
break;
case 'v':
getvers_flag = 1;
nodefault = 1;
break;
case 'x':
xlog_optstr = optarg;
nodefault = 1;
break;
case 'D':
debug_opts = optarg;
nodefault = 1;
break;
case 'M':
mount_map = optarg;
nodefault = 1;
break;
default:
errs = 1;
break;
}
if (optind == argc) {
if (unmount_flag)
errs = 1;
}
if (errs) {
show_usage:
fprintf(stderr, "\
Usage: %s [-h host] [[-f] [-m] [-v] [-s]] | [[-u] directory ...]] |\n\
\t[-l logfile|\"syslog\"] [-x log_flags] [-D dbg_opts] [-M mapent]\n", progname);
exit(1);
}
#ifdef hpux
/*
* Figure out root server of cluster
*/
if (def_server == localhost)
server = cluster_server();
else
#endif /* hpux */
server = def_server;
/*
* Get address of server
*/
if ((hp = gethostbyname(server)) == 0 && strcmp(server, localhost) != 0) {
fprintf(stderr, "%s: Can't get address of %s\n", progname, server);
exit(1);
}
bzero(&server_addr, sizeof server_addr);
server_addr.sin_family = AF_INET;
if (hp) {
bcopy((voidp) hp->h_addr, (voidp) &server_addr.sin_addr,
sizeof(server_addr.sin_addr));
} else {
/* fake "localhost" */
server_addr.sin_addr.s_addr = htonl(0x7f000001);
}
/*
* Create RPC endpoint
*/
s = privsock(SOCK_STREAM);
clnt = clnttcp_create(&server_addr, AMQ_PROGRAM, AMQ_VERSION, &s, 0, 0);
if (clnt == 0) {
close(s);
s = privsock(SOCK_DGRAM);
clnt = clntudp_create(&server_addr, AMQ_PROGRAM, AMQ_VERSION, TIMEOUT, &s);
}
if (clnt == 0) {
fprintf(stderr, "%s: ", progname);
clnt_pcreateerror(server);
exit(1);
}
/*
* Control debugging
*/
if (debug_opts) {
int *rc;
amq_setopt opt;
opt.as_opt = AMOPT_DEBUG;
opt.as_str = debug_opts;
rc = amqproc_setopt_1(&opt, clnt);
if (rc && *rc < 0) {
fprintf(stderr, "%s: daemon not compiled for debug", progname);
errs = 1;
} else if (!rc || *rc > 0) {
fprintf(stderr, "%s: debug setting for \"%s\" failed\n", progname, debug_opts);
errs = 1;
}
}
/*
* Control logging
*/
if (xlog_optstr) {
int *rc;
amq_setopt opt;
opt.as_opt = AMOPT_XLOG;
opt.as_str = xlog_optstr;
rc = amqproc_setopt_1(&opt, clnt);
if (!rc || *rc) {
fprintf(stderr, "%s: setting log level to \"%s\" failed\n", progname, xlog_optstr);
errs = 1;
}
}
/*
* Control log file
*/
if (logfile) {
int *rc;
amq_setopt opt;
opt.as_opt = AMOPT_LOGFILE;
opt.as_str = logfile;
rc = amqproc_setopt_1(&opt, clnt);
if (!rc || *rc) {
fprintf(stderr, "%s: setting logfile to \"%s\" failed\n", progname, logfile);
errs = 1;
}
}
/*
* Flush map cache
*/
if (flush_flag) {
int *rc;
amq_setopt opt;
opt.as_opt = AMOPT_FLUSHMAPC;
opt.as_str = "";
rc = amqproc_setopt_1(&opt, clnt);
if (!rc || *rc) {
fprintf(stderr, "%s: amd on %s cannot flush the map cache\n", progname, server);
errs = 1;
}
}
/*
* Mount info
*/
if (minfo_flag) {
int dummy;
amq_mount_info_list *ml = amqproc_getmntfs_1(&dummy, clnt);
if (ml) {
int mwid = 0, dwid = 0, twid = 0;
show_mi(ml, Calc, &mwid, &dwid, &twid);
mwid++; dwid++; twid++;
show_mi(ml, Full, &mwid, &dwid, &twid);
} else {
fprintf(stderr, "%s: amd on %s cannot provide mount info\n", progname, server);
}
}
/*
* Mount map
*/
if (mount_map) {
int *rc;
do {
rc = amqproc_mount_1(&mount_map, clnt);
} while (rc && *rc < 0);
if (!rc || *rc > 0) {
if (rc)
errno = *rc;
else
errno = ETIMEDOUT;
fprintf(stderr, "%s: could not start new ", progname);
perror("autmount point");
}
}
/*
* Get Version
*/
if (getvers_flag) {
amq_string *spp = amqproc_getvers_1((voidp) 0, clnt);
if (spp && *spp) {
printf("%s.\n", *spp);
free(*spp);
} else {
fprintf(stderr, "%s: failed to get version information\n", progname);
errs = 1;
}
}
/*
* Apply required operation to all remaining arguments
*/
if (optind < argc) {
do {
char *fs = argv[optind++];
if (unmount_flag) {
/*
* Unmount request
*/
amqproc_umnt_1(&fs, clnt);
} else {
/*
* Stats request
*/
amq_mount_tree_p *mtp = amqproc_mnttree_1(&fs, clnt);
if (mtp) {
amq_mount_tree *mt = *mtp;
if (mt) {
int mwid = 0, dwid = 0, twid = 0;
show_mt(mt, Calc, &mwid, &dwid, &twid);
mwid++; dwid++, twid++;
printf("%-*.*s Uid Getattr Lookup RdDir RdLnk Statfs Mounted@\n",
dwid, dwid, "What");
show_mt(mt, Stats, &mwid, &dwid, &twid);
} else {
fprintf(stderr, "%s: %s not automounted\n", progname, fs);
}
xdr_pri_free(xdr_amq_mount_tree_p, (caddr_t) mtp);
} else {
fprintf(stderr, "%s: ", progname);
clnt_perror(clnt, server);
errs = 1;
}
}
} while (optind < argc);
} else if (unmount_flag) {
goto show_usage;
} else if (stats_flag) {
amq_mount_stats *ms = amqproc_stats_1((voidp) 0, clnt);
if (ms) {
show_ms(ms);
} else {
fprintf(stderr, "%s: ", progname);
clnt_perror(clnt, server);
errs = 1;
}
} else if (!nodefault) {
amq_mount_tree_list *mlp = amqproc_export_1((voidp) 0, clnt);
if (mlp) {
enum show_opt e = Calc;
int mwid = 0, dwid = 0, pwid = 0;
while (e != ShowDone) {
int i;
for (i = 0; i < mlp->amq_mount_tree_list_len; i++) {
show_mt(mlp->amq_mount_tree_list_val[i],
e, &mwid, &dwid, &pwid);
}
mwid++; dwid++, pwid++;
if (e == Calc) e = Short;
else if (e == Short) e = ShowDone;
}
} else {
fprintf(stderr, "%s: ", progname);
clnt_perror(clnt, server);
errs = 1;
}
}
exit(errs);
}
/*
* udpresport creates a datagram socket and attempts to bind it to a
* secure port.
* returns: The bound socket, or -1 to indicate an error.
*/
static int inetresport(ty)
int ty;
{
int alport;
struct sockaddr_in addr;
int sock;
/* Use internet address family */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
if ((sock = socket(AF_INET, ty, 0)) < 0)
return -1;
for (alport = IPPORT_RESERVED-1; alport > IPPORT_RESERVED/2 + 1; alport--) {
addr.sin_port = htons((u_short)alport);
if (bind(sock, (struct sockaddr *)&addr, sizeof (addr)) >= 0)
return sock;
if (errno != EADDRINUSE) {
close(sock);
return -1;
}
}
close(sock);
errno = EAGAIN;
return -1;
}
/*
* Privsock() calls inetresport() to attempt to bind a socket to a secure
* port. If inetresport() fails, privsock returns a magic socket number which
* indicates to RPC that it should make its own socket.
* returns: A privileged socket # or RPC_ANYSOCK.
*/
static int privsock(ty)
int ty;
{
int sock = inetresport(ty);
if (sock < 0) {
errno = 0;
/* Couldn't get a secure port, let RPC make an insecure one */
sock = RPC_ANYSOCK;
}
return sock;
}
#ifdef DEBUG
xfree(f, l, p)
char *f, *l;
voidp p;
{
free(p);
}
#endif /* DEBUG */

View file

@ -0,0 +1,60 @@
#!/bin/sh -
#
# Copyright (c) 1989 Jan-Simon Pendry
# Copyright (c) 1989 Imperial College of Science, Technology & Medicine
# Copyright (c) 1989, 1993
# The Regents of the University of California. All rights reserved.
#
# This code is derived from software contributed to Berkeley by
# Jan-Simon Pendry at Imperial College, London.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#)Configure 8.1 (Berkeley) 6/6/93
#
# $Id: Configure,v 5.2.1.2 91/05/07 22:20:26 jsp Alpha $
#
echo "Making ./arch and ./os-type executable ..."
until chmod +x ./arch ./os-type; do echo "Error: chmod command failed" >&2; exit 1; done
echo "Checking ./arch and ./os-type ..."
echo ""
arch="`sh ./arch 2>/dev/null`"
os="`sh ./os-type 2>/dev/null`"
case "$arch" in
"") echo "./arch doesn't produce an answer - please check it" >&2; exit 1;;
esac
case "$os" in
"") echo "./os-type doesn't produce an answer - please check it" >&2; exit 1;;
esac
cat << %
This machine appears to be a "$arch" running "$os".
If that is correct just run make.
If those are incorrect please edit ./arch and ./os-type
%
exit 0

View file

@ -0,0 +1,5 @@
# @(#)Makefile.aix3 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.aix3,v 5.2.2.1 1992/02/09 15:10:06 jsp beta $
#
SYSLIB = -lbsd

View file

@ -0,0 +1,8 @@
# @(#)Makefile.bsd44 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.bsd44,v 5.2.2.1 1992/02/09 15:10:12 jsp beta $
#
# Extra Makefile definitions for 4.4 BSD
#
RPCLIB = -lrpc

View file

@ -0,0 +1,91 @@
# @(#)Makefile.config 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.config,v 5.2.2.1 1992/02/09 15:11:17 jsp beta $
#
#
# Comment/uncomment the following lines as required
#
#
# Where local include files are stored
#
#XINCLUDE = -I/usr/local/athena/include
#
# Define RESOLV if your C library does not include support
# for Hesiod and/or Named.
#
#RESOLV = -lhesiod -lresolv
#
# Define XLIBDIR if you have libraries not on the standard
# search path.
#
#XLIBDIR = -L/usr/local/athena/lib
#
# Define DBM if your C library does not include
# support for gdbm and/or ndbm.
#
#DBM = -lgdbm #-lndbm
#
# Define RPCLIB if your C library does not include
# support for RPC
#
#RPCLIB = -lrpc
#
# Include support for Network Information Service (NIS)
# Also define HAS_NIS_RELOAD to include map
# enumeration code implementing "cache:=all"
#
#HAS_NIS_MAPS = -DHAS_NIS_MAPS -DHAS_NIS_RELOAD
#
# Include support for file maps
#
HAS_FILE_MAPS = -DHAS_FILE_MAPS
#
# Include support for Hesiod
# Also define HAS_HESIOD_RELOAD to include zone
# transfer code implementing "cache:=all"
#
#HAS_HESIOD_MAPS = -DHAS_HESIOD_MAPS -DHAS_HESIOD_RELOAD
#
# Include support for /etc/passwd
#
HAS_PASSWD_MAPS = -DHAS_PASSWD_MAPS
#
# Include support for union maps
#
HAS_UNION_MAPS = -DHAS_UNION_MAPS
#
# Include support for ndbm.
# This removes support for gdbm and is only supported
# if your operating system supports ndbm
#
#HAS_NDBM_MAPS = -DHAS_NDBM_MAPS
#
# Include support for "regexp" maps
#
HAS_REGEXP = -DHAS_REGEXP
#
# Make sure that the hostname passed in RPC authentication packets
# contains a fully qualified domain name. See nfs_ops.c
#
#HAS_NFS_QUALIFIED_NAMES = -DHAS_NFS_QUALIFIED_NAMES
##############################################################
# Do NOT edit the following lines
#
CONFIG = ${XINCLUDE} ${HAS_NIS_MAPS} ${HAS_FILE_MAPS} ${HAS_HESIOD_MAPS} \
${HAS_NDBM_MAPS} ${HAS_MOUNTD_MAPS} ${HAS_PASSWD_MAPS} ${HAS_UNION_MAPS} \
${HAS_REGEXP} ${HAS_NFS_QUALIFIED_NAMES}

View file

@ -0,0 +1,13 @@
# @(#)Makefile.hpux 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.hpux,v 5.2.2.1 1992/02/09 15:10:26 jsp beta $
#
# Extra Makefile definitions for HP-UX
#
#CC = gcc ${GCCOPTS}
# Works only on HP300
CC = cc -Wc,-Nd2000
SYSCC = $(CC)
# Works only Hp800
# CC = cc

View file

@ -0,0 +1,10 @@
# @(#)Makefile.irix 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.irix,v 5.2.2.1 1992/02/09 15:10:31 jsp beta $
#
# Extra Makefile definitions for IRIX
#
DEBUG = #-g -DDEBUG
CCOPTS = -I/usr/include/sun -I/usr/include/bsd -DIRIX
RESOLV = -lrpcsvc -lsun -lbsd

View file

@ -0,0 +1,13 @@
# @(#)Makefile.irix3 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.irix3,v 5.2 1992/05/31 16:40:22 jsp Exp $
#
# Extra Makefile definitions for IRIX
#
# For 3.3.x and earlier we might need to indicate the Sun and BSD include
# paths.
DEBUG = #-g -DDEBUG
CCOPTS = -I/usr/include/sun -I/usr/include/bsd
RESOLV = -lrpcsvc -lsun -lbsd

View file

@ -0,0 +1,14 @@
# @(#)Makefile.irix4 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.irix4,v 5.2 1992/05/31 16:40:22 jsp Exp $
#
# Extra Makefile definitions for IRIX
#
# For 4.0.X and later we need to specify the -cckr option - although amd
# has prototypes - some of the rpc prototypes clash. The special include
# paths are not required. -lsun always comes before -lbsd.
DEBUG = -g
CCOPTS = -cckr
RESOLV = -lrpcsvc -lsun -lbsd

View file

@ -0,0 +1,10 @@
# @(#)Makefile.stellix 8.1 (Berkeley) 6/6/93
#
# $Id: Makefile.stellix,v 5.2.2.1 1992/02/09 15:10:45 jsp beta $
#
# Extra Makefile definitions for STELLIX
#
DEBUG = #-g -DDEBUG
CCOPTS = -DSTELLIX
RESOLV = -lrpcsvc

View file

@ -0,0 +1 @@
$Revision: 5.2.3.1 $ of $Date: 1993/06/01 11:43:31 $ bsd44

126
usr.sbin/amd/config/arch Normal file
View file

@ -0,0 +1,126 @@
#! /bin/sh
#
# Copyright (c) 1989 Jan-Simon Pendry
# Copyright (c) 1989 Imperial College of Science, Technology & Medicine
# Copyright (c) 1989, 1993
# The Regents of the University of California. All rights reserved.
#
# This code is derived from software contributed to Berkeley by
# Jan-Simon Pendry at Imperial College, London.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#)arch 8.1 (Berkeley) 6/6/93
#
# $Id: arch,v 5.2.2.2 1992/05/31 16:45:35 jsp Exp $
#
# Figure out machine architecture
#
PATH=/bin:/usr/bin:/usr/ucb:/etc:/usr/local/bin:${PATH} export PATH
#
# First try to find a standard command
#
a=arch # Sun compat
m=machine # BSD compat
u=uname # Sys5 compat
if [ -f /etc/$a -o -f /bin/$a -o -f /usr/bin/$a -o -f /usr/local/bin/$a ]
then
exec $a
elif [ -f /etc/$m -o -f /bin/$m -o -f /usr/bin/$m -o -f /usr/ucb/$m -o -f /usr/local/bin/$m ]
then
exec $m
elif [ -f /etc/$u -o -f /bin/$u -o -f /usr/bin/$u -o -f /usr/local/bin/$u ]
then
ARCH="`uname`"
case "$ARCH" in
"HP-UX") echo hp9000; exit 0;;
AIX*) MACH="`uname -m`"
case "$MACH" in
00*) echo ibm6000; exit 0;;
10*) echo ibm032; exit 0;;
20*) echo ibm032; exit 0;;
esac
;;
A/UX) echo macII ; exit 0 ;;
dgux) MACH="`uname -m`"
case "$MACH" in
AViiON) echo aviion; exit 0;;
esac
;;
*) MACH="`uname -m`"
case "$MACH" in
IP6) echo mips; exit 0;;
IP7) echo mips; exit 0;;
*) ;;
esac
;;
esac
fi
#
# Take a pot-shot at your machine architecture
#
echo "# ... No ARCH= option specified; dynamically determining architecture" >&2
case "`exec 2>/dev/null; head -2 /etc/motd`" in
*"HP-UX"*) ARCH=hp9000;;
*"Iris"*) ARCH=iris4d;;
*"Ultrix"*) ARCH=vax;;
*"RISC iX"*) ARCH=arm;;
*"Umax 4.2"*) ARCH=encore;;
*"Alliant Concentrix"*) ARCH=alliant;;
*"FPS Model 500"*) ARCH=fps500;;
*"HCX/UX"*) ARCH=harris;;
*) ARCH=unknown;
if [ -d /usr/include/caif ]; then
ARCH=ibm032
elif [ -f /bin/pyr ]; then
if /bin/pyr; then
ARCH=pyr
fi
elif [ -d /NextApps ]; then
ARCH=next
elif [ -f /etc/comply ]; then
# Tex 4300 is essentially a sun 3.
ARCH=sun3
fi
;;
esac
echo "# ... architecture appears to be \"${ARCH}\"" >&2
echo $ARCH
case "$ARCH" in
unknown) exit 1
esac
exit 0

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc-aix3.h 8.1 (Berkeley) 6/6/93
*
* $Id: misc-aix3.h,v 5.2.2.1 1992/02/09 15:10:05 jsp beta $
*
*/
struct ufs_args {
char *fspec; /* Block device */
};
struct nfs_args {
struct sockaddr_in addr; /* file server address */
fhandle_t fh; /* File handle to be mounted */
int flags; /* flags */
int wsize; /* write size in bytes */
int rsize; /* read size in bytes */
int timeo; /* initial timeout in .1 secs */
int retrans; /* times to retry send */
char *hostname; /* server's hostname */
int acregmin; /* attr cache file min secs */
int acregmax; /* attr cache file max secs */
int acdirmin; /* attr cache dir min secs */
int acdirmax; /* attr cache dir max secs */
char *netname; /* server's netname */
int biods; /* number of BIODS */
};
/*
* NFS mount option flags
*/
#define MNTOPT_RO "ro" /* read only */
#define MNTOPT_RW "rw" /* read/write */
#define MNTOPT_SOFT "soft" /* soft mount */
#define MNTOPT_HARD "hard" /* hard mount */
#define MNTOPT_NOSUID "nosuid"/* no set uid allowed */
#define MNTOPT_NOAUTO "noauto"/* hide entry from mount -a */
#define MNTOPT_INTR "intr" /* allow interrupts on hard mount */
#define MNTOPT_SECURE "secure"/* use secure RPC for NFS */
#define MNTOPT_GRPID "grpid" /* SysV-compatible group-id on create */
#define MNTOPT_NOSUB "nosub" /* disallow mounts beneath this one */
#define MNTOPT_MULTI "multi" /* Do multi-component lookup */
#define MNTOPT_NOAC "noac" /* don't cache attributes */
#define NFSMNT_SOFT 0x001 /* soft mount (hard is default) */
#define NFSMNT_WSIZE 0x002 /* set write size */
#define NFSMNT_RSIZE 0x004 /* set read size */
#define NFSMNT_TIMEO 0x008 /* set initial timeout */
#define NFSMNT_RETRANS 0x010 /* set number of request retrys */
#define NFSMNT_HOSTNAME 0x020 /* set hostname for error printf */
#define NFSMNT_INT 0x040 /* allow interrupts on hard mount */
#define NFSMNT_NOAC 0x080 /* don't cache attributes */
#define NFSMNT_ACREGMIN 0x0100 /* set min secs for file attr cache */
#define NFSMNT_ACREGMAX 0x0200 /* set max secs for file attr cache */
#define NFSMNT_ACDIRMIN 0x0400 /* set min secs for dir attr cache */
#define NFSMNT_ACDIRMAX 0x0800 /* set max secs for dir attr cache */
#define NFSMNT_SECURE 0x1000 /* secure mount */
#define NFSMNT_BIODS 0x10000 /* Number of biods for the file system */
#define DEF_BIODS 6

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc-hpux.h 8.1 (Berkeley) 6/6/93
*
* $Id: misc-hpux.h,v 5.2.2.1 1992/02/09 15:10:24 jsp beta $
*
*/
/*
* These definitions are from <nfs/nfs.h>
* Unfortunately, that file cannot be included
* because it contains lots of structure definitions
* that are not wanted (they produce name clashes).
* Isn't HP-UX wonderful!
*/
/*
* HP-UX specific definitions
*/
struct nfs_args {
struct sockaddr_in *addr; /* file server address */
fhandle_t *fh; /* File handle to be mounted */
int flags; /* flags */
int wsize; /* write size in bytes */
int rsize; /* read size in bytes */
int timeo; /* initial timeout in .1 secs */
int retrans; /* times to retry send */
char *hostname; /* server's name */
#ifdef __hp9000s700 /* XXX for HPUX 8.0 */
char *fsname; /* server's filesystem name */
#endif
};
/*
* NFS mount option flags
*/
#define NFSMNT_SOFT 0x001 /* soft mount (hard is default) */
#define NFSMNT_WSIZE 0x002 /* set write size */
#define NFSMNT_RSIZE 0x004 /* set read size */
#define NFSMNT_TIMEO 0x008 /* set initial timeout */
#define NFSMNT_RETRANS 0x010 /* set number of request retrys */
#define NFSMNT_HOSTNAME 0x020 /* set hostname for error printf */
#define NFSMNT_INT 0x040 /* set option to have interruptable mounts */
#define NFSMNT_NODEVS 0x080 /* turn off device file access (default on) */

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc-irix.h 8.1 (Berkeley) 6/6/93
*
* $Id: misc-irix.h,v 5.2.2.1 1992/02/09 15:10:30 jsp beta $
*
*/
#include <sys/fs/nfs_clnt.h>
#include <sys/fsid.h>
#include <sys/fstyp.h>
struct ufs_args {
char *fspec;
};

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc-next.h 8.1 (Berkeley) 6/6/93
*
* $Id: misc-next.h,v 5.2.2.1 1992/02/09 15:10:34 jsp beta $
*
*/
#include <nfs/nfs_mount.h>

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc-stellix.h 8.1 (Berkeley) 6/6/93
*
*/
#include <sys/fstyp.h>
struct ufs_args {
char *fspec;
};
struct nfs_args {
struct sockaddr_in *addr; /* file server address */
fhandle_t *fh; /* File handle to be mounted */
int flags; /* flags */
int wsize; /* write size in bytes */
int rsize; /* read size in bytes */
int timeo; /* initial timeout in .1 secs *
/
int retrans; /* times to retry send */
char *hostname; /* server's name */
};
#define NFSMNT_SOFT 0x001 /* soft mount (hard is default) */
#define NFSMNT_WSIZE 0x002 /* set write size */
#define NFSMNT_RSIZE 0x004 /* set read size */
#define NFSMNT_TIMEO 0x008 /* set initial timeout (= 1.6 sec) */
#define NFSMNT_RETRANS 0x010 /* set number of request retrys */
#define NFSMNT_HOSTNAME 0x020 /* set hostname for error printf */
#define NFSMNT_INT 0x040 /* allow interrupts on hard mount */

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)misc-ultrix.h 8.1 (Berkeley) 6/6/93
*
* $Id: misc-ultrix.h,v 5.2.2.1 1992/02/09 15:10:49 jsp beta $
*
*/
#include <nfs/nfs_gfs.h>
#define KERNEL
#include <sys/fs_types.h>
#undef KERNEL
#ifndef HOSTNAMESZ
#include <nfs/nfs_clnt.h>
#endif
#include <ufs/ufs_mount.h>
#define ufs_args ufs_specific

View file

@ -0,0 +1,153 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mount_aix.c 8.1 (Berkeley) 6/6/93
*
* $Id: mount_aix.c,v 5.2.2.1 1992/02/09 15:10:08 jsp beta $
*
*/
/*
* AIX 3 Mount helper
*/
#include "misc-aix3.h"
static int aix3_mkvp(p, gfstype, flags, object, stub, host, info, info_size, args)
char *p;
int gfstype;
int flags;
char *object;
char *stub;
char *host;
char *info;
int info_size;
char *args;
{
struct vmount *vp = (struct vmount *) p;
bzero((voidp) vp, sizeof(*vp));
/*
* Fill in standard fields
*/
vp->vmt_revision = VMT_REVISION;
vp->vmt_flags = flags;
vp->vmt_gfstype = gfstype;
#define VMT_ROUNDUP(len) (4 * ((len + 3) / 4))
#define VMT_ASSIGN(vp, idx, data, size) \
vp->vmt_data[idx].vmt_off = p - (char *) vp; \
vp->vmt_data[idx].vmt_size = size; \
bcopy(data, p, size); \
p += VMT_ROUNDUP(size);
/*
* Fill in all variable length data
*/
p += sizeof(*vp);
VMT_ASSIGN(vp, VMT_OBJECT, object, strlen(object) + 1);
VMT_ASSIGN(vp, VMT_STUB, stub, strlen(stub) + 1);
VMT_ASSIGN(vp, VMT_HOST, host, strlen(host) + 1);
VMT_ASSIGN(vp, VMT_HOSTNAME, host, strlen(host) + 1);
VMT_ASSIGN(vp, VMT_INFO, info, info_size);
VMT_ASSIGN(vp, VMT_ARGS, args, strlen(args) + 1);
#undef VMT_ASSIGN
#undef VMT_ROUNDUP
/*
* Return length
*/
return vp->vmt_length = p - (char *) vp;
}
/*
* Map from conventional mount arguments
* to AIX 3-style arguments.
*/
aix3_mount(fsname, dir, flags, type, data, args)
char *fsname;
char *dir;
int flags;
int type;
void *data;
char *args;
{
char buf[4096];
int size;
#ifdef DEBUG
dlog("aix3_mount: fsname %s, dir %s, type %d", fsname, dir, type);
#endif /* DEBUG */
/* aix3_mkvp(p, gfstype, flags, object, stub, host, info, info_size, args) */
switch (type) {
case MOUNT_TYPE_NFS: {
char *host = strdup(fsname);
char *rfs = strchr(host, ':');
int free_rfs = 0;
if (rfs) {
*rfs++ = '\0';
} else {
rfs = host;
free_rfs = 1;
host = strdup(hostname);
}
size = aix3_mkvp(buf, type, flags, rfs, dir, host, data, sizeof(struct nfs_args), args);
if (free_rfs)
free((voidp) rfs);
free(host);
} break;
case MOUNT_TYPE_UFS:
/* Need to open block device and extract log device info from sblk. */
return EINVAL;
default:
return EINVAL;
}
#ifdef DEBUG
/*dlog("aix3_mkvp: flags %#x, size %d, args %s", flags, size, args);*/
#endif /* DEBUG */
return vmount(buf, size);
}

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mount_irix.c 8.1 (Berkeley) 6/6/93
*
* $Id: mount_irix.c,v 5.2.2.1 1992/02/09 15:10:32 jsp beta $
*
*/
/*
* IRIX Mount helper
*/
#include "misc-irix.h"
/*
* Map from conventional mount arguments
* to IRIX style arguments.
*/
irix_mount(fsname, dir, flags, type, data)
char *fsname;
char *dir;
int flags;
int type;
void *data;
{
int size;
#ifdef DEBUG
dlog("irix_mount: fsname %s, dir %s, type %d", fsname, dir, type);
#endif /* DEBUG */
if (type == MOUNT_TYPE_NFS) {
size = sizeof (struct nfs_args);
return mount(dir, dir, (MS_FSS|MS_DATA|flags),
type, (struct nfs_args *) data, size);
} else if (type == MOUNT_TYPE_UFS) {
return mount(fsname, dir, (MS_FSS|flags), type);
} else {
return EINVAL;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mount_stellix.c 8.1 (Berkeley) 6/6/93
*/
/*
* IRIX Mount helper
*/
#include "misc-stellix.h"
/*
* Map from conventional mount arguments
* to IRIX style arguments.
*/
stellix_mount(fsname, dir, flags, type, data)
char *fsname;
char *dir;
int flags;
int type;
void *data;
{
#ifdef DEBUG
dlog("stellix_mount: fsname %s, dir %s, type %d", fsname, dir, type);
#endif /* DEBUG */
if (type == MOUNT_TYPE_NFS) {
return mount(dir, dir, (MS_FSS|MS_NFS|flags),
type, (caddr_t) data );
} else if (type == MOUNT_TYPE_UFS) {
return mount(fsname, dir, (MS_FSS|flags), type);
} else {
return EINVAL;
}
}

View file

@ -0,0 +1,137 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mtab_aix.c 8.1 (Berkeley) 6/6/93
*
* $Id: mtab_aix.c,v 5.2.2.1 1992/02/09 15:10:07 jsp beta $
*
*/
#include "am.h"
#ifdef READ_MTAB_AIX3_STYLE
#include <sys/mntctl.h>
#include <sys/vmount.h>
static struct mntent *mnt_dup(mp)
struct vmount *mp;
{
struct mntent *new_mp = ALLOC(mntent);
char *ty;
new_mp->mnt_fsname = strdup(vmt2dataptr(mp, VMT_OBJECT));
new_mp->mnt_dir = strdup(vmt2dataptr(mp, VMT_STUB));
new_mp->mnt_opts = strdup(vmt2dataptr(mp, VMT_ARGS));
switch (mp->vmt_gfstype) {
case MNT_JFS: ty = MTAB_TYPE_UFS; break;
case MNT_NFS:
ty = MTAB_TYPE_NFS;
new_mp->mnt_fsname = str3cat(new_mp->mnt_fsname,
vmt2dataptr(mp, VMT_HOSTNAME),
":", new_mp->mnt_fsname);
break;
default: ty = "unknown"; break;
}
new_mp->mnt_type = strdup(ty);
new_mp->mnt_passno = mp->vmt_vfsnumber;
new_mp->mnt_freq = 0;
return new_mp;
}
/*
* Read a mount table into memory
*/
mntlist *read_mtab(fs)
char *fs;
{
mntlist **mpp, *mhp;
int i;
char *mntinfo = 0, *cp;
struct vmount *vp;
int ret;
/*
* First figure out size of mount table
* and allocate space for a copy...
* Then get mount table for real.
*/
ret = mntctl(MCTL_QUERY, sizeof(i), &i);
if (ret == 0) {
mntinfo = xmalloc(i);
ret = mntctl(MCTL_QUERY, i, mntinfo);
}
if (ret <= 0) {
plog(XLOG_ERROR, "mntctl: %m");
goto out;
}
#ifdef DEBUG
/*dlog("mntctl returns %d structures", ret);*/
#endif /* DEBUG */
mpp = &mhp;
for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) {
vp = (struct vmount *) cp;
/*
* Allocate a new slot
*/
*mpp = ALLOC(mntlist);
/*
* Copy the data returned by mntctl
*/
(*mpp)->mnt = mnt_dup(vp);
/*
* Move to next pointer
*/
mpp = &(*mpp)->mnext;
}
*mpp = 0;
out:
if (mntinfo)
free(mntinfo);
return mhp;
}
#endif /* READ_MTAB_AIX3_STYLE */

View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mtab_bsd.c 8.1 (Berkeley) 6/6/93
*
* $Id: mtab_bsd.c,v 5.2.2.1 1992/02/09 15:10:13 jsp beta $
*
*/
#include "am.h"
#ifdef READ_MTAB_BSD_STYLE
#include <sys/mount.h>
static struct mntent *mnt_dup(mp)
struct statfs *mp;
{
struct mntent *new_mp = ALLOC(mntent);
char *ty;
new_mp->mnt_fsname = strdup(mp->f_mntfromname);
new_mp->mnt_dir = strdup(mp->f_mntonname);
switch (mp->f_type) {
case MOUNT_UFS: ty = MTAB_TYPE_UFS; break;
case MOUNT_NFS: ty = MTAB_TYPE_NFS; break;
case MOUNT_MFS: ty = MTAB_TYPE_MFS; break;
default: ty = "unknown"; break;
}
new_mp->mnt_type = strdup(ty);
new_mp->mnt_opts = strdup("unset");
new_mp->mnt_freq = 0;
new_mp->mnt_passno = 0;
return new_mp;
}
/*
* Read a mount table into memory
*/
mntlist *read_mtab(fs)
char *fs;
{
mntlist **mpp, *mhp;
struct statfs *mntbufp, *mntp;
int nloc = getmntinfo(&mntbufp, MNT_NOWAIT);
if (nloc == 0) {
plog(XLOG_ERROR, "Can't read mount table");
return 0;
}
mpp = &mhp;
for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) {
/*
* Allocate a new slot
*/
*mpp = ALLOC(mntlist);
/*
* Copy the data returned by getmntent
*/
(*mpp)->mnt = mnt_dup(mntp);
/*
* Move to next pointer
*/
mpp = &(*mpp)->mnext;
}
/*
* Terminate the list
*/
*mpp = 0;
return mhp;
}
#endif /* READ_MTAB_BSD_STYLE */

View file

@ -0,0 +1,472 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mtab_file.c 8.1 (Berkeley) 6/6/93
*
* $Id: mtab_file.c,v 5.2.2.1 1992/02/09 15:10:42 jsp beta $
*
*/
#include "am.h"
#ifdef READ_MTAB_FROM_FILE
#ifdef USE_FCNTL
#include <fcntl.h>
#else
#include <sys/file.h>
#endif /* USE_FCNTL */
#ifdef UPDATE_MTAB
/*
* Do strict /etc/mtab locking
*/
#define MTAB_LOCKING
/*
* Firewall mtab entries
*/
#define MTAB_STRIPNL
#include <sys/stat.h>
static FILE *mnt_file;
/*
* If the system is being trashed by something, then
* opening mtab may fail with ENFILE. So, go to sleep
* for a second and try again. (Yes - this has happened to me.)
*
* Note that this *may* block the automounter, oh well.
* If we get to this state then things are badly wrong anyway...
*
* Give the system 10 seconds to recover but then give up.
* Hopefully something else will exit and free up some file
* table slots in that time.
*/
#define NFILE_RETRIES 10 /* seconds */
#ifdef MTAB_LOCKING
#ifdef LOCK_FCNTL
static int lock(fd)
{
int rc;
struct flock lk;
lk.l_type = F_WRLCK;
lk.l_whence = 0;
lk.l_start = 0;
lk.l_len = 0;
again:
rc = fcntl(fd, F_SETLKW, (caddr_t) &lk);
if (rc < 0 && (errno == EACCES || errno == EAGAIN)) {
#ifdef DEBUG
dlog("Blocked, trying to obtain exclusive mtab lock");
#endif /* DEBUG */
sleep(1);
goto again;
}
return rc;
}
#else
#define lock(fd) (flock((fd), LOCK_EX))
#endif /* LOCK_FCNTL */
#endif /* MTAB_LOCKING */
static FILE *open_locked_mtab(mtab_file, mode, fs)
char *mtab_file;
char *mode;
char *fs;
{
FILE *mfp = 0;
#ifdef UPDATE_MTAB
/*
* There is a possible race condition if two processes enter
* this routine at the same time. One will be blocked by the
* exclusive lock below (or by the shared lock in setmntent)
* and by the time the second process has the exclusive lock
* it will be on the wrong underlying object. To check for this
* the mtab file is stat'ed before and after all the locking
* sequence, and if it is a different file then we assume that
* it may be the wrong file (only "may", since there is another
* race between the initial stat and the setmntent).
*
* Simpler solutions to this problem are invited...
*/
int racing = 2;
#ifdef MTAB_LOCKING
int rc;
int retries = 0;
struct stat st_before, st_after;
#endif /* MTAB_LOCKING */
if (mnt_file) {
#ifdef DEBUG
dlog("Forced close on %s in read_mtab", mtab_file);
#endif /* DEBUG */
endmntent(mnt_file);
mnt_file = 0;
}
#ifdef MTAB_LOCKING
again:
if (mfp) {
endmntent(mfp);
mfp = 0;
}
clock_valid = 0;
if (stat(mtab_file, &st_before) < 0) {
plog(XLOG_ERROR, "%s: stat: %m", mtab_file);
if (errno == ESTALE) {
/* happens occasionally */
sleep(1);
goto again;
}
return 0;
}
#endif /* MTAB_LOCKING */
#endif /* UPDATE_MTAB */
eacces:
mfp = setmntent(mtab_file, mode);
if (!mfp) {
/*
* Since setmntent locks the descriptor, it
* is possible it can fail... so retry if
* needed.
*/
if (errno == EACCES || errno == EAGAIN) {
#ifdef DEBUG
dlog("Blocked, trying to obtain exclusive mtab lock");
#endif /* DEBUG */
goto eacces;
} else if (errno == ENFILE && retries++ < NFILE_RETRIES) {
sleep(1);
goto eacces;
}
plog(XLOG_ERROR, "setmntent(\"%s\", \"%s\"): %m", mtab_file, mode);
return 0;
}
#ifdef MTAB_LOCKING
#ifdef UPDATE_MTAB
/*
* At this point we have an exclusive lock on the mount list,
* but it may be the wrong one so...
*/
/*
* Need to get an exclusive lock on the current
* mount table until we have a new copy written
* out, when the lock is released in free_mntlist.
* flock is good enough since the mount table is
* not shared between machines.
*/
do
rc = lock(fileno(mfp));
while (rc < 0 && errno == EINTR);
if (rc < 0) {
plog(XLOG_ERROR, "Couldn't lock %s: %m", mtab_file);
endmntent(mfp);
return 0;
}
/*
* Now check whether the mtab file has changed under our feet
*/
if (stat(mtab_file, &st_after) < 0) {
plog(XLOG_ERROR, "%s: stat", mtab_file);
goto again;
}
if (st_before.st_dev != st_after.st_dev ||
st_before.st_ino != st_after.st_ino) {
struct timeval tv;
if (racing == 0) {
/* Sometimes print a warning */
plog(XLOG_WARNING,
"Possible mount table race - retrying %s", fs);
}
racing = (racing+1) & 3;
/*
* Take a nap. From: Doug Kingston <dpk@morgan.com>
*/
tv.tv_sec = 0;
tv.tv_usec = (mypid & 0x07) << 17;
if (tv.tv_usec)
if (select(0, (voidp) 0, (voidp) 0, (voidp) 0, &tv) < 0)
plog(XLOG_WARNING, "mtab nap failed: %m");
goto again;
}
#endif /* UPDATE_MTAB */
#endif /* MTAB_LOCKING */
return mfp;
}
/*
* Unlock the mount table
*/
void unlock_mntlist P((void));
void unlock_mntlist()
{
/*
* Release file lock, by closing the file
*/
if (mnt_file) {
endmntent(mnt_file);
mnt_file = 0;
}
}
/*
* Write out a mount list
*/
void rewrite_mtab(mp)
mntlist *mp;
{
FILE *mfp;
int error = 0;
/*
* Concoct a temporary name in the same
* directory as the target mount table
* so that rename() will work.
*/
char tmpname[64];
int retries;
int tmpfd;
char *cp;
char *mcp = mtab;
cp = strrchr(mcp, '/');
if (cp) {
bcopy(mcp, tmpname, cp - mcp);
tmpname[cp-mcp] = '\0';
} else {
plog(XLOG_WARNING, "No '/' in mtab (%s), using \".\" as tmp directory", mtab);
tmpname[0] = '.'; tmpname[1] = '\0';
}
strcat(tmpname, "/mtabXXXXXX");
mktemp(tmpname);
retries = 0;
enfile1:
if ((tmpfd = open(tmpname, O_RDWR|O_CREAT|O_TRUNC, 0644)) < 0) {
if (errno == ENFILE && retries++ < NFILE_RETRIES) {
sleep(1);
goto enfile1;
}
plog(XLOG_ERROR, "%s: open: %m", tmpname);
return;
}
if (close(tmpfd) < 0)
plog(XLOG_ERROR, "Couldn't close tmp file descriptor: %m");
retries = 0;
enfile2:
mfp = setmntent(tmpname, "w");
if (!mfp) {
if (errno == ENFILE && retries++ < NFILE_RETRIES) {
sleep(1);
goto enfile2;
}
plog(XLOG_ERROR, "setmntent(\"%s\", \"w\"): %m", tmpname);
error = 1;
goto out;
}
while (mp) {
if (mp->mnt) {
if (addmntent(mfp, mp->mnt)) {
plog(XLOG_ERROR, "Can't write entry to %s", tmpname);
error = 1;
goto out;
}
}
mp = mp->mnext;
}
/*
* SunOS 4.1 manuals say that the return code from entmntent()
* is always 1 and to treat as a void. That means we need to
* call fflush() to make sure the new mtab file got written.
*/
if (fflush(mfp)) {
plog(XLOG_ERROR, "flush new mtab file: %m");
error = 1;
goto out;
}
(void) endmntent(mfp);
/*
* Rename temporary mtab to real mtab
*/
if (rename(tmpname, mtab) < 0) {
plog(XLOG_ERROR, "rename %s to %s: %m", tmpname, mtab);
error = 1;
goto out;
}
out:
if (error)
(void) unlink(tmpname);
}
#ifdef MTAB_STRIPNL
static void mtab_stripnl(s)
char *s;
{
do {
s = strchr(s, '\n');
if (s)
*s++ = ' ';
} while (s);
}
#endif /* MTAB_STRIPNL */
/*
* Append a mntent structure to the
* current mount table.
*/
void write_mntent(mp)
struct mntent *mp;
{
int retries = 0;
FILE *mfp;
enfile:
mfp = open_locked_mtab(mtab, "a", mp->mnt_dir);
if (mfp) {
#ifdef MTAB_STRIPNL
mtab_stripnl(mp->mnt_opts);
#endif /* MTAB_STRIPNL */
if (addmntent(mfp, mp))
plog(XLOG_ERROR, "Couldn't write %s: %m", mtab);
if (fflush(mfp))
plog(XLOG_ERROR, "Couldn't flush %s: %m", mtab);
(void) endmntent(mfp);
} else {
if (errno == ENFILE && retries < NFILE_RETRIES) {
sleep(1);
goto enfile;
}
plog(XLOG_ERROR, "setmntent(\"%s\", \"a\"): %m", mtab);
}
}
#endif /* UPDATE_MTAB */
static struct mntent *mnt_dup(mp)
struct mntent *mp;
{
struct mntent *new_mp = ALLOC(mntent);
new_mp->mnt_fsname = strdup(mp->mnt_fsname);
new_mp->mnt_dir = strdup(mp->mnt_dir);
new_mp->mnt_type = strdup(mp->mnt_type);
new_mp->mnt_opts = strdup(mp->mnt_opts);
new_mp->mnt_freq = mp->mnt_freq;
new_mp->mnt_passno = mp->mnt_passno;
#ifdef FIXUP_MNTENT_DUP
/*
* Additional fields get dup'ed here
*/
FIXUP_MNTENT_DUP(new_mp, mp);
#endif
return new_mp;
}
/*
* Read a mount table into memory
*/
mntlist *read_mtab(fs)
char *fs;
{
mntlist **mpp, *mhp;
struct mntent *mep;
FILE *mfp = open_locked_mtab(mtab, "r+", fs);
if (!mfp)
return 0;
mpp = &mhp;
/*
* XXX - In SunOS 4 there is (yet another) memory leak
* which loses 1K the first time getmntent is called.
* (jsp)
*/
while (mep = getmntent(mfp)) {
/*
* Allocate a new slot
*/
*mpp = ALLOC(mntlist);
/*
* Copy the data returned by getmntent
*/
(*mpp)->mnt = mnt_dup(mep);
/*
* Move to next pointer
*/
mpp = &(*mpp)->mnext;
}
*mpp = 0;
#ifdef UPDATE_MTAB
/*
* If we are not updating the mount table then we
* can free the resources held here, otherwise they
* must be held until the mount table update is complete
*/
mnt_file = mfp;
#else
endmntent(mfp);
#endif /* UPDATE_MTAB */
return mhp;
}
#endif /* READ_MTAB_FROM_FILE */

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mtab_ultrix.c 8.1 (Berkeley) 6/6/93
*
* $Id: mtab_ultrix.c,v 5.2.2.1 1992/02/09 15:10:50 jsp beta $
*
*/
#include "am.h"
#ifdef READ_MTAB_ULTRIX_STYLE
#include <sys/mount.h>
#include <sys/fs_types.h>
static struct mntent *mnt_dup(mp)
struct fs_data *mp;
{
struct mntent *new_mp = ALLOC(mntent);
new_mp->mnt_fsname = strdup(mp->fd_devname);
new_mp->mnt_dir = strdup(mp->fd_path);
if (mp->fd_fstype >= GT_NUMTYPES)
mp->fd_fstype = GT_UNKWN;
else if (gt_names[mp->fd_fstype] == 0)
mp->fd_fstype = GT_UNKWN;
new_mp->mnt_type = strdup(gt_names[mp->fd_fstype]);
new_mp->mnt_opts = strdup("unset");
new_mp->mnt_freq = 0;
new_mp->mnt_passno = mp->fd_dev;
return new_mp;
}
/*
* Read a mount table into memory
*/
mntlist *read_mtab(fs)
char *fs;
{
mntlist **mpp, *mhp;
/* From: Piete Brooks <pb@cl.cam.ac.uk> */
int loc=0;
#undef NMOUNT
#define NMOUNT 20
struct fs_data mountbuffer[NMOUNT], *fs_data;
int ret;
mpp = &mhp;
while ((ret = getmountent(&loc, mountbuffer, NMOUNT)) > 0) {
for (fs_data = mountbuffer; fs_data < &mountbuffer[ret]; fs_data++) {
/*
* Allocate a new slot
*/
*mpp = ALLOC(mntlist);
/*
* Copy the data returned by getmntent
*/
(*mpp)->mnt = mnt_dup(fs_data);
/*
* Move to next pointer
*/
mpp = &(*mpp)->mnext;
}
}
if (ret < 0) {
plog(XLOG_ERROR, "getmountent: %m");
return 0;
}
*mpp = 0;
return mhp;
}
#endif /* READ_MTAB_ULTRIX_STYLE */

View file

@ -0,0 +1,88 @@
#!/bin/sh -
#
# Copyright (c) 1989 Jan-Simon Pendry
# Copyright (c) 1989 Imperial College of Science, Technology & Medicine
# Copyright (c) 1989, 1993
# The Regents of the University of California. All Rights Reserved.
#
# This code is derived from software contributed to Berkeley by
# Jan-Simon Pendry at Imperial College, London.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#)newvers.sh 8.1 (Berkeley) 6/6/93
#
# $Id: newvers.sh,v 5.2.2.1 1992/02/09 15:11:19 jsp beta $
#
PATH=/usr/ucb:/bin:/usr/bin:$PATH
if [ $# -ne 3 ]; then echo "Usage: newvers program arch os" >&2; exit 1; fi
version="version.$1"
if [ ! -r $version ]; then echo 0 > $version; chmod 444 $version; fi
v=`cat $version`
u=${USER-${LOGNAME-root}}
h=`hostname`
#h=`expr "$h" : '\([^.]*\)'`
t=`date`
if [ ! -s "$d../config/RELEASE" -o ! -s "$d../text/COPYRIGHT" ]; then
echo ERROR: config file missing >&2
exit 1
fi
rm -f vers.$1.c
(
cat << %%
char copyright[] = "\\
%%
sed 's/$/\\n\\/' $d../text/COPYRIGHT
cat << %%
";
char version[] = "\\
%%
cat << %%
$1 \\
%%
sed \
-e 's/\$//g' \
-e 's/[A-Z][a-z]*://g' \
-e 's/ */ /g' \
-e 's/^ //' \
-e 's/$/\\/' \
$d../config/RELEASE
cat << %%
#${v}: ${t}\\n\\
Built by ${u}@${h} for \\
%%
case "$2" in
[aeiou]*) echo "an \\" ;;
*) echo "a \\";;
esac
echo "$2 running $3\";"
) > vers.$1.c
rm -f $version
expr ${v} + 1 > $version
chmod 444 $version

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-acis43.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-acis43.h,v 5.2.2.1 1992/02/09 15:10:02 jsp beta $
*
* IBM RT ACIS4.3 definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Does this OS have NDBM support?
*/
#define OS_HAS_NDBM
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MOUNT_NFS
#define MOUNT_TYPE_UFS MOUNT_UFS
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "ufs"
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Need precise symlink lengths
#define PRECISE_SYMLINKS
*/

View file

@ -0,0 +1,181 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-aix3.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-aix3.h,v 5.2.2.2 1992/05/31 16:38:49 jsp Exp $
*
* AIX 3.1 definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_4
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_AIX3
/*
* Does this OS have NDBM support?
*/
#define OS_HAS_NDBM
/*
* The mount table is obtained from the kernel
*/
#undef UPDATE_MTAB
/*
* Pick up BSD bits from include files
* Try for 4.4 compatibility if available (AIX 3.2 and later)
*/
#define _BSD 44
/*
* No mntent info on AIX 3
*/
#undef MNTENT_HDR
#define MNTENT_HDR <sys/mntctl.h>
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MNT_NFS
#define MOUNT_TYPE_UFS MNT_JFS
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "jfs"
/*
* How to unmount filesystems
*/
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flag, mnt_data) \
aix3_mount(mnt->mnt_fsname, mnt->mnt_dir, flag, type, mnt_data, mnt->mnt_opts)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) uvmount(mnt->mnt_passno, 0)
/*
* Byte ordering
*/
#ifndef BYTE_ORDER
#include <sys/machine.h>
#endif /* BYTE_ORDER */
#undef ARCH_ENDIAN
#if BYTE_ORDER == LITTLE_ENDIAN
#define ARCH_ENDIAN "little"
#else
#if BYTE_ORDER == BIG_ENDIAN
#define ARCH_ENDIAN "big"
#else
XXX - Probably no hope of running Amd on this machine!
#endif /* BIG */
#endif /* LITTLE */
/*
* Miscellaneous AIX 3 bits
*/
#define NEED_MNTOPT_PARSER
#define SHORT_MOUNT_NAME
#define MNTMAXSTR 128
#define MNTTYPE_UFS "jfs" /* Un*x file system */
#define MNTTYPE_NFS "nfs" /* network file system */
#define MNTTYPE_IGNORE "ignore" /* No type specified, ignore this entry */
struct mntent {
char *mnt_fsname; /* name of mounted file system */
char *mnt_dir; /* file system path prefix */
char *mnt_type; /* MNTTYPE_* */
char *mnt_opts; /* MNTOPT* */
int mnt_freq; /* dump frequency, in days */
int mnt_passno; /* pass number on parallel fsck */
};
#define NFS_HDR "misc-aix3.h"
#define UFS_HDR "misc-aix3.h"
#undef NFS_FH_DREF
#define NFS_FH_DREF(dst, src) { (dst) = *(src); }
#undef NFS_SA_DREF
#define NFS_SA_DREF(dst, src) { (dst).addr = *(src); }
#define M_RDONLY MNT_READONLY
/*
* How to get a mount list
*/
#undef READ_MTAB_FROM_FILE
#define READ_MTAB_AIX3_STYLE
/*
* The data for the mount syscall needs the path in addition to the
* host name since that is the only source of information about the
* mounted filesystem.
#define NFS_ARGS_NEEDS_PATH
*/
#define NFS_LOMAP 34
#define NFS_HIMAP 99
#define NFS_ERROR_MAPPING \
static nfs_errormap[] = { 0,75,77,99,99,99, \
99,99,99,99,99,78,99,99,99,79, \
99,99,70,99,35,36,37,38,39,40, \
41,42,43,44,45,46,47,48,49,50, \
51,52,53,54,55,56,57,58,60,61, \
64,65,99,67,68,62,63,66,69,68, \
99,99,99,71,99,99,99,99,99,99 \
};
#define MOUNT_HELPER_SOURCE "mount_aix.c"
/*
* Need this too
*/
#include <time.h>

View file

@ -0,0 +1,117 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-aux.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-aux.h,v 5.2.2.1 1992/02/09 15:10:10 jsp beta $
*
* A/UX macII definitions for Amd (automounter)
* Contributed by Julian Onions <jpo@cs.nott.ac.uk>
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* No support for ndbm
*/
#undef OS_HAS_NDBM
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_UFS MOUNT_UFS
#define MOUNT_TYPE_NFS MOUNT_NFS
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "5.2"
#define SIGCHLD SIGCLD
#define SYS5_SIGNALS
/*
* Use <fcntl.h> rather than <sys/file.h>
*/
#define USE_FCNTL
/*
* Use fcntl() rather than flock()
*/
#define LOCK_FCNTL
#ifdef __GNUC__
#define alloca(sz) __builtin_alloca(sz)
#endif
#define bzero(ptr, len) memset(ptr, 0, len)
#define bcopy(from, to, len) memcpy(to, from, len)
#define getpagesize() (2048)
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
fsmount(type, mnt->mnt_dir, flags, mnt_data)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) unmount(mnt->mnt_dir)
#define NFDS 30 /* conservative */
/* not included in sys/param.h */
#include <sys/types.h>
/* not part of sys/time.h */
#include <time.h>
/* for NMOUNT */
#include <sys/config.h>

View file

@ -0,0 +1,191 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-bsd44.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-bsd44.h,v 5.2.2.1 1992/02/09 15:10:11 jsp beta $
*
* 4.4 BSD definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_4
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_44
#define HAS_TCP_NFS
/*
* Does this OS have NDBM support?
*/
#define OS_HAS_NDBM
/*
* 4.4 doesn't provide NIS.
*/
#undef HAS_NIS_MAPS
/*
* OS provides strerror()
*/
#define HAS_STRERROR
/*
* The mount table is obtained from the kernel
*/
#undef UPDATE_MTAB
/*
* No mntent info on 4.4 BSD
*/
#undef MNTENT_HDR
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MOUNT_NFS
#define MOUNT_TYPE_UFS MOUNT_UFS
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "ufs"
#define MTAB_TYPE_MFS "mfs"
/*
* How to unmount filesystems
*/
#undef UNMOUNT_TRAP
#undef NEED_UMOUNT_FS
#define NEED_UMOUNT_BSD
/*
* How to copy an address into an NFS filehandle
*/
#undef NFS_SA_DREF
#define NFS_SA_DREF(dst, src) { \
(dst).addr = (struct sockaddr *) (src); \
(dst).addrlen = sizeof(*src); \
(dst).sotype = SOCK_DGRAM; \
(dst).proto = 0; \
}
/*
* Byte ordering
*/
#ifndef BYTE_ORDER
#include <machine/endian.h>
#endif /* BYTE_ORDER */
#undef ARCH_ENDIAN
#if BYTE_ORDER == LITTLE_ENDIAN
#define ARCH_ENDIAN "little"
#else
#if BYTE_ORDER == BIG_ENDIAN
#define ARCH_ENDIAN "big"
#else
XXX - Probably no hope of running Amd on this machine!
#endif /* BIG */
#endif /* LITTLE */
/*
* Miscellaneous 4.4 BSD bits
*/
#define NEED_MNTOPT_PARSER
#define SHORT_MOUNT_NAME
#define MNTMAXSTR 128
#define MNTTYPE_UFS "ufs" /* Un*x file system */
#define MNTTYPE_NFS "nfs" /* network file system */
#define MNTTYPE_MFS "mfs" /* memory file system */
#define MNTTYPE_IGNORE "ignore" /* No type specified, ignore this entry */
#define M_RDONLY MNT_RDONLY
#define M_SYNC MNT_SYNCHRONOUS
#define M_NOEXEC MNT_NOEXEC
#define M_NOSUID MNT_NOSUID
#define M_NODEV MNT_NODEV
#define MNTOPT_SOFT "soft" /* soft mount */
#define MNTOPT_INTR "intr" /* interrupts allowed */
#define NFSMNT_HOSTNAME 0 /* hostname on 4.4 is not optional */
struct mntent {
char *mnt_fsname; /* name of mounted file system */
char *mnt_dir; /* file system path prefix */
char *mnt_type; /* MNTTYPE_* */
char *mnt_opts; /* MNTOPT* */
int mnt_freq; /* dump frequency, in days */
int mnt_passno; /* pass number on parallel fsck */
};
/*
* Type of a file handle
*/
#undef NFS_FH_TYPE
#define NFS_FH_TYPE nfsv2fh_t *
/*
* How to get a mount list
*/
#undef READ_MTAB_FROM_FILE
#define READ_MTAB_BSD_STYLE
/*
* The data for the mount syscall needs the path in addition to the
* host name since that is the only source of information about the
* mounted filesystem.
*/
#define NFS_ARGS_NEEDS_PATH
/*
* 4.4 has RE support built in
*/
#undef RE_HDR
#define RE_HDR <regexp.h>

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-concentrix.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-concentrix.h,v 5.2.2.1 1992/02/09 15:10:14 jsp beta $
*
* Alliant Concentrix 5.0.0 definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#undef VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Does this OS have NDBM support?
*/
#define OS_HAS_NDBM
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MOUNT_NFS
#define MOUNT_TYPE_UFS MOUNT_UFS

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-convex.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-convex.h,v 5.2.2.1 1992/02/09 15:10:16 jsp beta $
*
* Convex C220, version 7.1 definitions for Amd (automounter)
* from Eitan Mizrotsky <eitan@shum.huji.ac.il>
*/
/*
* Does the compiler grok void *
*/
#undef VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_UFS MOUNT_UFS
#define MOUNT_TYPE_NFS MOUNT_NFS
#define strrchr rindex
#define strchr index

View file

@ -0,0 +1,143 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-defaults.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-defaults.h,v 5.2.2.1 1992/02/09 15:10:17 jsp beta $
*
* Common OS definitions. These may be overridden in
* the OS specific files ("os-foo.h").
*/
/*
* What level of AMD are we backward compatible with?
* This only applies to externally visible characteristics.
* Rev.Minor.Branch.Patch (2 digits each)
*/
#define AMD_COMPAT 5000000 /* 5.0 */
/*
* What type is free(void*) returning?
*/
#define FREE_RETURN_TYPE void
/*
* Is the mount table mirrored in software
*/
#define UPDATE_MTAB
/*
* Where to get union wait
*/
#define WAIT <sys/wait.h>
/*
* Where to get mount entry info
*/
#define MNTENT_HDR <mntent.h>
/*
* Include support for syslog()
*/
#define HAS_SYSLOG
/*
* Byte ordering
*/
#define ARCH_ENDIAN "unknown"
/*
* Name of filesystem types
*/
#define MTAB_TYPE_NFS "nfs"
#define MTAB_TYPE_UFS "4.2"
/*
* Name of mount & unmount system calls
*
* NOTE:
* UNMOUNT_TRAP takes a struct mntent *
*/
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
mount(type, mnt->mnt_dir, flags, mnt_data)
#define UNMOUNT_TRAP(mnt) unmount(mnt->mnt_dir)
/*
* How to unmount filesystems.
* NEED_UMOUNT_FS includes code to scan the mount table
* to find the correct information for the unmount system
* call. Some systems, such as 4.4bsd, do not require
* this - they can just do an unmount system call directly.
*/
#define NEED_UMOUNT_FS
#define UMOUNT_FS(dir) umount_fs(dir)
/*
* Type of a file handle
*/
#define NFS_FH_TYPE fhandle_t *
#define NFS_FH_DREF(dst, src) { (dst) = (src); }
/*
* How to copy an address into an NFS filehandle
*/
#define NFS_SA_DREF(dst, src) { (dst).addr = (src); }
/*
* Type of filesystem type
*/
#define MTYPE_TYPE int
/*
* How to get a mount list
*/
#define READ_MTAB_FROM_FILE
/*
* Make Amd automount points appear
* to be zero sized. undef this
* if the O/S has a divide by zero
* problem in df et al.
*/
#define HAS_EMPTY_AUTOMOUNTS
/*
* For the RE matcher
*/
#define CHARBITS 0377
#define STRCSPN
#define RE_HDR "re.h"

View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-dgux.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-dgux.h,v 5.2.2.1 1992/02/09 15:10:18 jsp beta $
*
* dg/ux definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_4
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_4
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS "nfs"
#define MOUNT_TYPE_UFS "dg/ux"
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "dg/ux"
/*
* Need the following in more places than just NFS_HDR
*/
#include <sys/dg_mount.h>
/*
* This is braindead
* dg/ux has nfs 4.0 but doesn't have the following options
*/
#define NFSMNT_HOSTNAME 0x0
#define NFSMNT_INT 0x0
#define M_NEWTYPE 0
/*
* DG have their own filesystem.
*/
#define ufs_args dgux_args
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
#define _BSD_WAIT_FLAVOR
#define _BSD_TTY_FLAVOR
#define _BSD_SIGNAL_FLAVOR
#define _DGUX_SOURCE
/*
* Use fcntl() rather than flock()
*/
#define LOCK_FCNTL
#define bzero(ptr, len) memset(ptr, 0, len)
#define bcopy(from, to, len) memcpy(to, from, len)
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
((struct nfs_args *)mnt_data)->version = !strcmp(type, MOUNT_TYPE_UFS)?\
DG_MOUNT_DGUX_VERSION:DG_MOUNT_NFS_VERSION, \
dg_mount(type, mnt->mnt_dir, flags, mnt_data)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) umount(mnt->mnt_dir)

View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-fpx4.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-fpx4.h,v 5.2.2.2 1992/05/31 16:39:34 jsp Exp $
*
* Celerity FPX 4.1/2 definitions for Amd (automounter)
* from Stephen Pope <scp@grizzly.acl.lanl.gov>
*/
/*
* FPX wants to include sys headers multiple times
*/
#define INCLUDE_HEADERS
/*
* FPX sys/mount.h includes sys/nfs.h; prevent this
*/
#define INCLUDED_nfs
/*
* FPX doesn't define NMOUNT anywhere
*/
#define NMOUNT 40
/*
* Does the compiler grok void *
*/
/* #define VOIDP */
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_4
#define svc_fdset svc_fds
#define svc_getreqset(p) svc_getreq((*p).fds_bits[0])
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MOUNT_NFS
#define MOUNT_TYPE_UFS MOUNT_UFS

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-hcx.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-hcx.h,v 5.2.2.1 1992/02/09 15:10:20 jsp beta $
*
* Harris HCX/UX Release 3.0 definitions for Amd (automounter)
*/
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Deviant call necessary. The mount() routine in libc only works for UFS
* (it's a backward-compatible piece of C code which traps to mountsyscall).
*/
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
mountsyscall(type, mnt->mnt_dir, flags, mnt_data)
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MOUNT_NFS
#define MOUNT_TYPE_UFS MOUNT_UFS
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#ifdef _hcx
#define ARCH_ENDIAN "big"
#else
XXX - bizarre!
#endif

View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-hlh42.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-hlh42.h,v 5.2.2.1 1992/02/09 15:10:22 jsp beta $
*
* HLH OTS definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#undef VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#if defined(hlh)
#define ARCH_ENDIAN "little"
#endif
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_NFS MOUNT_NFS
#define MOUNT_TYPE_UFS MOUNT_UFS
/*
* Miscellaneous HLH 4.2 incantations
*/
#define strchr index
#define strrchr rindex
#define sigmask(x) (1 << ((x)-1))
/*
* HLH's 4.2 needs the extra RPC definitions.
*/
#define NEED_XDR_POINTER
#define NEED_CLNT_SPERRNO

View file

@ -0,0 +1,150 @@
/*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-hpux.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-hpux.h,v 5.2.2.1 1992/02/09 15:10:23 jsp beta $
*
* HP/9000 HP-UX definitions for Amd (automounter)
*/
/*
* Does the compiler grok void *
*/
#ifdef __GNUC__
#define VOIDP
#endif
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#if defined(hp9000s200) || defined(hp9000s300) || defined(hp9000s800)
#define ARCH_ENDIAN "big"
#endif
#ifndef __hpux
#define HPUX_VERSION_6
#endif
/*
* No support for syslog() prior to 7.0
*/
#ifdef HPUX_VERSION_6
#undef HAS_SYSLOG
#endif
/*
* No support for ndbm
*/
#undef OS_HAS_NDBM
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_UFS MOUNT_UFS
#define MOUNT_TYPE_NFS MOUNT_NFS
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "hfs"
/*
* Where to get NFS definitions
*/
#define NFS_HDR "misc-hpux.h"
/*
* Where to get union wait
*/
#undef WAIT
#define WAIT "uwait.h"
#ifdef HPUX_VERSION_6
#define SIGCHLD SIGCLD
#endif
#define SYS5_SIGNALS
/*
* Miscellaneous HP-UX definitions
*/
#define NEED_XDR_POINTER
#define NEED_CLNT_SPERRNO
/*
* Use <fcntl.h> rather than <sys/file.h>
*/
#define USE_FCNTL
/*
* Use fcntl() rather than flock()
*/
#define LOCK_FCNTL
/*
* Additional fields in struct mntent
* are fixed up here
*/
#define FIXUP_MNTENT(mntp) { \
(mntp)->mnt_time = clocktime(); \
}
#define FIXUP_MNTENT_DUP(mntp, mp) { \
(mntp)->mnt_time = (mp)->mnt_time; \
}
#define bzero(ptr, len) memset(ptr, 0, len)
#define bcopy(from, to, len) memcpy(to, from, len)
#define getpagesize() (2048)
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
vfsmount(type, mnt->mnt_dir, flags, mnt_data)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) umount(mnt->mnt_dir)
#define NFDS 30 /* conservative */
#define MOUNTED MNT_MNTTAB

View file

@ -0,0 +1,133 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-irix.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-irix.h,v 5.2.2.1 1992/02/09 15:10:28 jsp beta $
*
* IRIX 3.3 definitions for Amd (automounter)
* Contributed by Scott R. Presnell <srp@cgl.ucsf.edu>
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Has support for syslog()
*/
#define HAS_SYSLOG
#define M_GRPID MS_GRPID
#define M_RDONLY MS_RDONLY
/*
* Support for ndbm
*/
#define OS_HAS_NDBM
#define UPDATE_MTAB
#undef MTAB_TYPE_NFS
#define MTAB_TYPE_NFS "nfs"
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "efs"
#define NMOUNT 40 /* The std sun value */
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_UFS sysfs(GETFSIND, FSID_EFS)
#define MOUNT_TYPE_NFS sysfs(GETFSIND, FSID_NFS)
#define SYS5_SIGNALS
/*
* Use <fcntl.h> rather than <sys/file.h>
*/
/*#define USE_FCNTL*/
/*
* Use fcntl() rather than flock()
*/
/*#define LOCK_FCNTL*/
#ifdef __GNUC__
#define alloca(sz) __builtin_alloca(sz)
#endif
#define bzero(ptr, len) memset(ptr, 0, len)
#define bcopy(from, to, len) memcpy(to, from, len)
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
irix_mount(mnt->mnt_fsname, mnt->mnt_dir,flags, type, mnt_data)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) umount(mnt->mnt_dir)
#define NFDS 30 /* conservative */
#define NFS_HDR "misc-irix.h"
#define UFS_HDR "misc-irix.h"
/* not included in sys/param.h */
#include <sys/types.h>
#define MOUNT_HELPER_SOURCE "mount_irix.c"
#define MNTINFO_DEV "fsid"
#define MNTINFO_PREF "0x"

View file

@ -0,0 +1,133 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-irix3.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-irix3.h,v 5.2 1992/05/31 16:40:22 jsp Exp $
*
* IRIX 3.3 definitions for Amd (automounter)
* Contributed by Scott R. Presnell <srp@cgl.ucsf.edu>
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Has support for syslog()
*/
#define HAS_SYSLOG
#define M_GRPID MS_GRPID
#define M_RDONLY MS_RDONLY
/*
* Support for ndbm
*/
#define OS_HAS_NDBM
#define UPDATE_MTAB
#undef MTAB_TYPE_NFS
#define MTAB_TYPE_NFS "nfs"
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "efs"
#define NMOUNT 40 /* The std sun value */
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_UFS sysfs(GETFSIND, FSID_EFS)
#define MOUNT_TYPE_NFS sysfs(GETFSIND, FSID_NFS)
#define SYS5_SIGNALS
/*
* Use <fcntl.h> rather than <sys/file.h>
*/
/*#define USE_FCNTL*/
/*
* Use fcntl() rather than flock()
*/
/*#define LOCK_FCNTL*/
#ifdef __GNUC__
#define alloca(sz) __builtin_alloca(sz)
#endif
#define bzero(ptr, len) memset(ptr, 0, len)
#define bcopy(from, to, len) memcpy(to, from, len)
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
irix_mount(mnt->mnt_fsname, mnt->mnt_dir,flags, type, mnt_data)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) umount(mnt->mnt_dir)
#define NFDS 30 /* conservative */
#define NFS_HDR "misc-irix.h"
#define UFS_HDR "misc-irix.h"
/* not included in sys/param.h */
#include <sys/types.h>
#define MOUNT_HELPER_SOURCE "mount_irix.c"
#define MNTINFO_DEV "fsid"
#define MNTINFO_PREF "0x"

View file

@ -0,0 +1,150 @@
/*
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)os-irix4.h 8.1 (Berkeley) 6/6/93
*
* $Id: os-irix4.h,v 5.2 1992/05/31 16:40:22 jsp Exp $
*
* IRIX 4.0.X definitions for Amd (automounter)
* Contributed by Scott R. Presnell <srp@cgl.ucsf.edu>
*/
/*
* Does the compiler grok void *
*/
#define VOIDP
/*
* Which version of the Sun RPC library we are using
* This is the implementation release number, not
* the protocol revision number.
*/
#define RPC_3
/*
* Which version of the NFS interface are we using.
* This is the implementation release number, not
* the protocol revision number.
*/
#define NFS_3
/*
* Byte ordering
*/
#undef ARCH_ENDIAN
#define ARCH_ENDIAN "big"
/*
* Has support for syslog()
*/
#define HAS_SYSLOG
#define M_RDONLY MS_RDONLY
#define M_GRPID MS_GRPID
#define M_NOSUID MS_NOSUID
#define M_NONDEV MS_NODEV
/*
* Support for ndbm
*/
#define OS_HAS_NDBM
#define UPDATE_MTAB
#undef MTAB_TYPE_NFS
#define MTAB_TYPE_NFS "nfs"
#undef MTAB_TYPE_UFS
#define MTAB_TYPE_UFS "efs"
#define NMOUNT 40 /* The std sun value */
/*
* Name of filesystem types
*/
#define MOUNT_TYPE_UFS sysfs(GETFSIND, FSID_EFS)
#define MOUNT_TYPE_NFS sysfs(GETFSIND, FSID_NFS)
#define SYS5_SIGNALS
/*
* Use <fcntl.h> rather than <sys/file.h>
*/
/*#define USE_FCNTL*/
/*
* Use fcntl() rather than flock()
*/
/*#define LOCK_FCNTL*/
#ifdef __GNUC__
#define alloca(sz) __builtin_alloca(sz)
#endif
#define bzero(ptr, len) memset(ptr, 0, len)
#define bcopy(from, to, len) memcpy(to, from, len)
#undef MOUNT_TRAP
#define MOUNT_TRAP(type, mnt, flags, mnt_data) \
irix_mount(mnt->mnt_fsname, mnt->mnt_dir,flags, type, mnt_data)
#undef UNMOUNT_TRAP
#define UNMOUNT_TRAP(mnt) umount(mnt->mnt_dir)
#define NFDS 30 /* conservative */
#define NFS_HDR "misc-irix.h"
#define UFS_HDR "misc-irix.h"
/* not included in sys/param.h */
#include <sys/types.h>
#define MOUNT_HELPER_SOURCE "mount_irix.c"
/*
* Under 4.0.X this information is in /usr/include/mntent.h
* Below is what is used to be for Irix 3.3.X.
*/
/*#define MNTINFO_DEV "fsid"*/
/*#define MNTINFO_PREF "0x"*/
#define MNTINFO_PREF ""
/*
* Under Irix, mount type "auto" is probed by statfs() in df. A statfs() of
* a direct mount causes that mount to fire. So change the mount type in
* /etc/mtab to "ignore" to stop that (this is what SGI does for their
* automounter. Use the old FASCIST define for this.
*/
#define FASCIST_DF_COMMAND MNTTYPE_IGNORE

Some files were not shown because too many files have changed in this diff Show more