1
0

Source code upload

This commit is contained in:
calmsacibis995
2022-09-29 17:59:04 +03:00
parent 72fa9da3d7
commit 8fc8fa8089
33399 changed files with 11964078 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
#!smake
#
# Makefile for rcp.bootparamd, the boot parameters daemon.
#
# $Revision: 1.16 $
include $(ROOT)/usr/include/make/commondefs
LCDEFS+= -D_BSD_TIME
LLDLIBS+= -lrpcsvc
CVERSION=-cckr
CFILES= bootparam_svc.c bootparam_subr.c bootparam_lib.c
D_FILE= bootparams
TARGETS= rpc.bootparamd
default: ${TARGETS}
include ${COMMONRULES}
rpc.bootparamd: ${OBJECTS}
${CCF} ${OBJECTS} ${LDFLAGS} -o $@
install: default
${INSTALL} -F /usr/etc -idb nfs.sw.nfs ${TARGETS}
${INSTALL} -idb "config(noupdate)" -u root -g sys \
-m 644 -F /etc $(D_FILE)
+407
View File
@@ -0,0 +1,407 @@
#ifndef lint
static char sccsid[] = "@(#)bootparam_lib.c 1.1 88/03/07 4.0NFSSRC; from 1.2 87/10/14 SMI";
#endif
/*
* Copyright (c) 1988 by Sun Microsystems, Inc.
*/
/*
* Library routines of the bootparam server.
*/
#include <stdio.h>
#include <strings.h>
#include <rpcsvc/ypclnt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
extern int debug;
#define iseol(c) (c == '\0' || c == '\n' || c == '#')
#define issep(c) (index(sep,c) != NULL)
#define isignore(c) (index(ignore,c) != NULL)
#define BOOTPARAMS "/etc/bootparams"
#define LINESIZE 512
#define NAMESIZE 256
#define DOMAINSIZE 256
static char domain[DOMAINSIZE]; /* NIS domain name */
/*
* getline()
* Read a line from a file.
* What's returned is a cookie to be passed to getname
*/
char **
getline(line,maxlinelen,f)
char *line;
int maxlinelen;
FILE *f;
{
char *p;
static char *lp;
do {
if (! fgets(line, maxlinelen, f)) {
return(NULL);
}
} while (iseol(line[0]));
p = line;
for (;;) {
while (*p) {
p++;
}
if (*--p == '\n' && *--p == '\\') {
if (! fgets(p, maxlinelen, f)) {
break;
}
} else {
break;
}
}
lp = line;
return(&lp);
}
/*
* getname()
* Get the next entry from the line.
* You tell getname() which characters to ignore before storing them
* into name, and which characters separate entries in a line.
* The cookie is updated appropriately.
* return:
* 1: one entry parsed
* 0: partial entry parsed, ran out of space in name
* -1: no more entries in line
*/
int
getname(name, namelen, ignore, sep, linep)
char *name;
int namelen;
char *ignore;
char *sep;
char **linep;
{
char c;
char *lp;
char *np;
int maxnamelen;
lp = *linep;
do {
c = *lp++;
} while (isignore(c) && !iseol(c));
if (iseol(c)) {
*linep = lp - 1;
return(-1);
}
np = name;
while (! issep(c) && ! iseol(c) && np - name < namelen) {
*np++ = c;
c = *lp++;
}
lp--;
if (issep(c) || iseol(c)) {
if (np - name != namelen) {
*np = 0;
}
if (iseol(c)) {
*lp = 0;
} else {
lp++; /* advance over separator */
}
} else {
*linep = lp;
return(0);
}
*linep = lp;
return(1);
}
/*
* getclntent reads the line buffer and returns a string of client entry
* in NIS or the "/etc/bootparams" file. Called by bp_getclntent.
*/
static int
getclntent(lp, clnt_entry)
register char **lp; /* function input */
register char *clnt_entry; /* function output */
{
char name[NAMESIZE];
int append = 0;
while (getname(name, sizeof(name), " \t", " \t", lp) >= 0) {
if (!append) {
strcpy(clnt_entry, name);
append++;
} else {
strcat(clnt_entry, " ");
strcat(clnt_entry, name);
}
}
return (0);
}
/*
* getfileent returns the client entry in the "/etc/bootparams"
* file given the client name.
*/
static int
getfileent(clnt_name, clnt_entry)
register char *clnt_name; /* function input */
register char *clnt_entry; /* function output */
{
FILE *fp;
char line[LINESIZE];
char name[NAMESIZE];
char **lp;
int reason;
reason = -1;
if ((fp = fopen(BOOTPARAMS, "r")) == NULL) {
return (-1);
}
while (lp = getline(line, sizeof(line), fp)) {
if ((getname(name, sizeof(name), " \t", " \t",
lp) >= 0) && (strcmp(name,clnt_name) == 0)) {
if (getclntent(lp, clnt_entry) == 0)
reason = 0;
break;
}
}
fclose(fp);
return (reason);
}
/*
* bp_getclntent returns the client entry in either the NIS map or
* the "/etc/bootparams" file given the client name.
*/
int
bp_getclntent(clnt_name, clnt_entry)
register char *clnt_name; /* function input */
register char *clnt_entry; /* function output */
{
char *val, *buf;
int vallen;
int reason;
reason = getfileent(clnt_name, clnt_entry);
if (!reason)
return 0;
if (useyp() && ((reason = yp_match(domain, "bootparams", clnt_name,
strlen(clnt_name), &val, &vallen) == 0))) {
buf = val;
reason = getclntent(&buf, clnt_entry);
free(val);
return(reason);
}
}
/*
* getclntkey reads the line buffer and returns a string of pathname
* in NIS or the "/etc/bootparams" file. Called by bp_getclntkey.
*/
static int
aliasmatch(clnt_name, buf)
register char *clnt_name; /* function input */
register char **buf; /* function output */
{
char name[NAMESIZE];
char *val, *val1;
int reason;
int vallen;
if (reason = yp_match(domain, "hosts.name", clnt_name,
strlen(clnt_name), &val, &vallen)) {
if (debug)
syslog(LOG_ERR, "aliasmatch: invalid host=%s",
clnt_name);
return(reason);
}
if (debug)
syslog(LOG_ERR, "aliasmatch: host=%s", val);
val1 = val;
while (getname(name, sizeof(name), " \t", " \t", &val) >= 0) {
if (debug)
syslog(LOG_ERR, "aliasmatch: name=%s", name);
reason = yp_match(domain, "bootparams", name,
strlen(name), buf, &vallen);
if (!reason) {
break;
}
}
free(val1);
return (reason);
}
/*
* getclntkey reads the line buffer and returns a string of pathname
* in NIS or the "/etc/bootparams" file. Called by bp_getclntkey.
*/
static int
getclntkey(lp, clnt_key, clnt_entry)
register char **lp; /* function input */
register char *clnt_key; /* function input */
register char *clnt_entry; /* function output */
{
char name[NAMESIZE];
char *cp;
while (getname(name, sizeof(name), " \t", " \t", lp) >= 0) {
if (debug)
syslog(LOG_ERR, "getclntkey: name=%s", name);
if ((cp = (char *)index(name, '=')) == 0) {
if (debug)
syslog(LOG_ERR, " no =");
return (-1);
}
*cp++ = '\0';
if (strcmp(name, clnt_key) == 0) {
strcpy(clnt_entry, cp);
return (0);
}
}
if (strcmp(clnt_key, "dump") == 0) {
/*
* This is a gross hack to handle the case where
* no dump file exists in bootparams. The null
* server and path names indicate this fact to the
* client.
*/
strcpy(clnt_entry, ":");
return (0);
}
return (-1);
}
/*
* getfilekey returns the client's server name and its pathname from
* the "/etc/bootparams" file given the client name and the key.
*/
static int
getfilekey(clnt_name, clnt_key, clnt_entry)
register char *clnt_name; /* function input */
register char *clnt_key; /* function input */
register char *clnt_entry; /* function output */
{
FILE *fp;
char line[LINESIZE];
char name[NAMESIZE];
char **lp;
int reason;
reason = -1;
if ((fp = fopen(BOOTPARAMS, "r")) == NULL) {
if (debug)
syslog(LOG_ERR,
"getfilekey: open /etc/bootparams failed");
return (-1);
}
while (lp = getline(line, sizeof(line), fp)) {
if (debug)
syslog(LOG_ERR, "getfilekey: line=%s", *lp);
if ((getname(name, sizeof(name), " \t", " \t",
lp) >= 0) && (strcmp(name,clnt_name) == 0)) {
if (getclntkey(lp, clnt_key, clnt_entry) == 0)
reason = 0;
break;
}
}
fclose(fp);
return (reason);
}
/*
* bp_getclntkey returns the client's server name and its pathname from either
* the NIS or the "/etc/bootparams" file given the client name and
* the key.
*/
int
bp_getclntkey(clnt_name, clnt_key, clnt_entry)
register char *clnt_name; /* function input */
register char *clnt_key; /* function input */
register char *clnt_entry; /* function output */
{
char *val, *buf;
int vallen;
int reason;
if (useyp()) {
if (debug)
syslog(LOG_ERR, "yp_match(%s, bootparams, %s)",
domain, clnt_name);
if (reason = yp_match(domain, "bootparams", clnt_name,
strlen(clnt_name), &val, &vallen)) {
if (debug)
syslog(LOG_ERR, "bp_getclntkey: %d", reason);
if (reason == YPERR_MAP)
return(getfilekey(clnt_name,
clnt_key, clnt_entry));
/* try aliases */
if (reason == YPERR_KEY) {
reason = aliasmatch(clnt_name, &val);
}
if (reason) {
return(getfilekey(clnt_name,clnt_key,clnt_entry));
}
}
buf = val;
reason = getclntkey(&buf, clnt_key, clnt_entry);
free(val);
return(reason);
}
return(getfilekey(clnt_name, clnt_key, clnt_entry));
}
/*
* Determine whether or not to use the NIS service to do lookups.
*/
static int initted;
static int usingyp;
static int
useyp()
{
if (!initted) {
getdomainname(domain, sizeof(domain));
usingyp = !yp_bind(domain);
initted = 1;
}
return (usingyp);
}
/*
* Determine if a descriptor belongs to a socket or not
*/
issock(fd)
int fd;
{
struct stat st;
if (fstat(fd, &st) < 0) {
return (0);
}
/*
* SunOS returns S_IFIFO for sockets, while 4.3 returns 0 and
* does not even have an S_IFIFO mode. Since there is confusion
* about what the mode is, we check for what it is not instead of
* what it is.
*/
switch (st.st_mode & S_IFMT) {
case S_IFCHR:
case S_IFREG:
case S_IFLNK:
case S_IFDIR:
case S_IFBLK:
return (0);
default:
return (1);
}
}
+281
View File
@@ -0,0 +1,281 @@
#ifndef lint
static char sccsid[] = "@(#)bootparam_subr.c 1.1 88/03/07 4.0NFSSRC; from 1.3 87/11/17 SMI";
#endif
/*
* Copyright (c) 1988 by Sun Microsystems, Inc.
*/
/*
* Subroutines that implement the bootparam services.
*/
#include <rpcsvc/bootparam.h>
#include <netdb.h>
#include <nlist.h>
#include <stdio.h>
#include <strings.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/mbuf.h>
#include <sys/syssgi.h>
#include <net/route.h>
#include <sys/sbd.h>
#include <net/if.h> /* for structs ifnet and ifaddr */
#include <netinet/in.h>
/* include <netinet/in_var.h>*/ /* for struct in_ifaddr */
#include <syslog.h>
/*
* If true, reject whoami's from hosts in other NIS domains by requiring
* that the hostname's IP domain matches our NIS domain's name.
*/
int interdomain;
#define LINESIZE 1024
int debug = 0;
static struct in_addr get_route(struct in_addr);
void getf_printres(bp_getfile_res *, bp_getfile_arg *);
/*
* Whoami turns a client address into a client name
* and suggested route machine.
*/
bp_whoami_res *
bootparamproc_whoami_1(argp)
bp_whoami_arg *argp;
{
static bp_whoami_res res;
struct in_addr clnt_addr;
struct in_addr route_addr;
struct hostent *hp;
static char clnt_entry[LINESIZE];
static char domain[32];
if (argp->client_address.address_type != IP_ADDR_TYPE) {
if (debug)
syslog(LOG_ERR,
"Whoami failed: unknown address type %d",
argp->client_address.address_type);
return (NULL);
}
bcopy ((char *) &argp->client_address.bp_address.ip_addr,
(char *) &clnt_addr, sizeof (clnt_addr));
hp = gethostbyaddr((char *)&clnt_addr, sizeof clnt_addr, AF_INET);
if (hp == NULL) {
if (debug)
syslog(LOG_ERR,
"Whoami failed: gethostbyaddr for %s.",
inet_ntoa (clnt_addr));
return (NULL);
}
if (bp_getclntent(hp->h_name, clnt_entry) != 0) {
/*
* When diskless wants to install client tree, the entry
* may not exist in bootparam data base.
*/
if (debug)
syslog(LOG_ERR, "bp_getclntent for %s failed.",
hp->h_name);
return (NULL);
}
res.client_name = hp->h_name;
getdomainname(domain, sizeof domain);
if (domain[0] == '\0') {
if (debug)
syslog(LOG_ERR, "null domainname.");
return (NULL);
}
if (interdomain) {
char *dp;
dp = strchr(hp->h_name, '.');
if (dp && strcasecmp(dp + 1, domain)) {
if (debug)
syslog(LOG_ERR,
"interdomain whoami request from %s.",
hp->h_name);
return (NULL);
}
}
res.domain_name = domain;
res.router_address.address_type = IP_ADDR_TYPE;
route_addr = get_route(clnt_addr);
bcopy ((char *) &route_addr,
(char *) &res.router_address.bp_address.ip_addr,
sizeof (res.router_address.bp_address.ip_addr));
if (debug) {
char buf[16];
strcpy(buf, inet_ntoa(clnt_addr));
syslog(LOG_ERR,
"Whoami_1: name of addr \"%s\" is \"%s\", router addr=\"%s\"",
buf, res.client_name,
inet_ntoa(res.router_address.bp_address.ip_addr));
}
return (&res);
}
#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(__uint64_t) - 1))) \
: sizeof(__uint64_t))
#ifdef _HAVE_SA_LEN
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
#else
#define ADVANCE(x, n) (x += ROUNDUP(_FAKE_SA_LEN_DST(n)))
#endif
/*
* get_route paws through the kernel's routing table looking for a route
* via a gateway that is on the same network and subnet as the client.
* Any gateway will do because the selected gateway will return ICMP redirect
* messages to the client if it can not route the traffic itself.
*/
static struct in_addr
get_route(struct in_addr client_addr)
{
int l, i;
char *cp;
struct sockaddr_in *gate;
struct {
struct rt_msghdr rtm;
struct sockaddr_in dst;
} req;
struct {
struct rt_msghdr rtm;
char m_space[512];
} ans;
static struct in_addr no_addr;
static int s;
u_short ident;
ident = getpid();
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0) {
syslog(LOG_ERR,
"get_route() socket(PF_ROUTE,SOCK_RAW): %m");
return no_addr;
}
bzero(&req, sizeof(req));
req.rtm.rtm_type = RTM_GET;
req.rtm.rtm_flags = RTF_HOST;
req.rtm.rtm_version = RTM_VERSION;
req.rtm.rtm_addrs = RTA_DST;
req.dst.sin_family = AF_INET;
req.dst.sin_addr = client_addr;
req.rtm.rtm_msglen = sizeof(req);
if (write(s, &req, req.rtm.rtm_msglen) < 0) {
syslog(LOG_ERR, "get_route() write(routing socket): %m");
close(s);
return no_addr;
}
do {
l = read(s, &ans, sizeof(ans));
if (l < 0) {
syslog(LOG_ERR,"get_route: read(routing socket): %m");
close(s);
return no_addr;
}
} while (l > 0 && ans.rtm.rtm_pid != ident);
close(s);
if (ans.rtm.rtm_version != RTM_VERSION) {
syslog(LOG_ERR, "get_route(): routing message version %d"
" not understood\n",
ans.rtm.rtm_version);
return no_addr;
}
if (ans.rtm.rtm_msglen > sizeof(ans)) {
syslog(LOG_ERR, "get_route(): message length mismatch,"
" in packet %d, returned %d\n",
ans.rtm.rtm_msglen, sizeof(ans));
return no_addr;
}
if (ans.rtm.rtm_errno) {
syslog(LOG_ERR, "get_route(): RTM_GET: %s (errno %d)",
strerror(ans.rtm.rtm_errno),
ans.rtm.rtm_errno);
return no_addr;
}
for (cp = ans.m_space, i = 1; i; i <<= 1) {
gate = (struct sockaddr_in *)cp;
if (i & ans.rtm.rtm_addrs) {
if (i == RTA_GATEWAY)
return gate->sin_addr;
ADVANCE(cp, (struct sockaddr*)gate);
}
}
if (debug)
syslog(LOG_ERR, "No route found for client %s.",
inet_ntoa(client_addr));
return no_addr;
}
/*
* Getfile gets the client name and the key and returns its server
* and the pathname for that key.
*/
bp_getfile_res *
bootparamproc_getfile_1(argp)
bp_getfile_arg *argp;
{
static bp_getfile_res res;
static char clnt_entry[LINESIZE];
struct hostent *hp;
char *cp;
if (bp_getclntkey(argp->client_name, argp->file_id, clnt_entry) != 0) {
if (debug)
syslog(LOG_ERR, "bp_getclntkey(%s,%s) failed.",
argp->client_name, argp->file_id);
return (NULL);
}
if ((cp = (char *)index(clnt_entry, ':')) == 0) {
return (NULL);
}
*cp++ = '\0';
res.server_name = clnt_entry;
res.server_path = cp;
if (*res.server_name == 0) {
res.server_address.address_type = IP_ADDR_TYPE;
bzero(&res.server_address.bp_address.ip_addr,
sizeof(res.server_address.bp_address.ip_addr));
} else {
if ((hp = gethostbyname(res.server_name)) == NULL) {
if (debug)
syslog(LOG_ERR,
"getfile_1: gethostbyname(%s) failed",
res.server_name);
return (NULL);
}
res.server_address.address_type = IP_ADDR_TYPE;
bcopy ((char *) hp->h_addr,
(char *) &res.server_address.bp_address.ip_addr,
sizeof (res.server_address.bp_address.ip_addr));
}
getf_printres(&res, argp);
return (&res);
}
void
getf_printres(res, argp)
bp_getfile_res *res;
bp_getfile_arg *argp;
{
syslog(LOG_ERR, "getfile_1: \"%s of %s\" is \"%s(%s):%s\"",
argp->file_id, argp->client_name,
res->server_name,
inet_ntoa(res->server_address.bp_address.ip_addr),
res->server_path);
}
+168
View File
@@ -0,0 +1,168 @@
#ifndef lint
static char sccsid[] = "@(#)bootparam_svc.c 1.1 88/03/07 4.0NFSSRC; from 1.2 87/11/17 SMI";
#endif
/*
* Copyright (c) 1988 by Sun Microsystems, Inc.
*/
/*
* Main program of the bootparam server.
*/
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <rpc/rpc.h>
#include <rpcsvc/bootparam.h>
#include <syslog.h>
#ifdef sgi
#define dup2(x,y) BSDdup2(x,y)
#endif
extern int debug;
extern int interdomain;
static void background();
static void bootparamprog_1();
main(argc, argv)
int argc;
char **argv;
{
SVCXPRT *transp;
openlog("rpc.bootparamd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
if (argc > 1) {
if (strncmp(argv[1], "-d", 2) == 0) {
debug++;
syslog(LOG_ERR, "In debug mode");
} else if (strncmp(argv[1], "-i", 2) == 0) {
interdomain++;
} else {
syslog(LOG_ERR, "usage: %s [-d]", argv[0]);
exit(1);
}
}
if (! issock(0)) {
/*
* Started by user.
*/
if (!debug)
background();
pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS);
if ((transp = svcudp_create(RPC_ANYSOCK)) == NULL) {
syslog(LOG_ERR, "cannot create udp service.");
exit(1);
}
if (! svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS,
bootparamprog_1, IPPROTO_UDP)) {
syslog(LOG_ERR, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp).");
exit(1);
}
} else {
/*
* Started by inetd.
*/
if ((transp = svcudp_create(0)) == NULL) {
syslog(LOG_ERR, "cannot create udp service.");
exit(1);
}
if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS,
bootparamprog_1, 0)) {
syslog(LOG_ERR, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp).");
exit(1);
}
}
/*
* Start serving
*/
svc_run();
syslog(LOG_ERR, "svc_run returned");
exit(1);
}
static void
background()
{
#ifndef DEBUG
if (fork())
exit(0);
{ int s;
for (s = 0; s < 10; s++)
(void) close(s);
}
(void) open("/", O_RDONLY);
(void) dup2(0, 1);
(void) dup2(0, 2);
#endif
{ int tt = open("/dev/tty", O_RDWR);
if (tt > 0) {
ioctl(tt, TIOCNOTTY, 0);
close(tt);
}
}
}
static void
bootparamprog_1(rqstp, transp)
struct svc_req *rqstp;
SVCXPRT *transp;
{
union {
bp_whoami_arg bootparamproc_whoami_1_arg;
bp_getfile_arg bootparamproc_getfile_1_arg;
} argument;
char *result;
bool_t (*xdr_argument)(), (*xdr_result)();
char *(*local)();
extern bp_whoami_res *bootparamproc_whoami_1();
extern bp_getfile_res *bootparamproc_getfile_1();
if (debug)
syslog(LOG_ERR,"receive request %d", rqstp->rq_proc);
switch (rqstp->rq_proc) {
case NULLPROC:
svc_sendreply(transp, xdr_void, NULL);
return;
case BOOTPARAMPROC_WHOAMI:
xdr_argument = xdr_bp_whoami_arg;
xdr_result = xdr_bp_whoami_res;
local = (char *(*)()) bootparamproc_whoami_1;
break;
case BOOTPARAMPROC_GETFILE:
xdr_argument = xdr_bp_getfile_arg;
xdr_result = xdr_bp_getfile_res;
local = (char *(*)()) bootparamproc_getfile_1;
break;
default:
svcerr_noproc(transp);
return;
}
bzero(&argument, sizeof(argument));
if (! svc_getargs(transp, xdr_argument, &argument)) {
svcerr_decode(transp);
return;
}
if ((result = (*local)(&argument)) != NULL) {
if (!svc_sendreply(transp, xdr_result, result)) {
svcerr_systemerr(transp);
if (debug)
syslog(LOG_ERR, "svc_sendreply failed");
} else if (debug)
syslog(LOG_ERR, "svc_sendreply done");
} else if (debug)
syslog(LOG_ERR, "request %d failed", rqstp->rq_proc);
if (! svc_freeargs(transp, xdr_argument, &argument)) {
syslog(LOG_ERR,"unable to free arguments");
exit(1);
}
}
+1
View File
@@ -0,0 +1 @@
#