char * get_uaddr(int fd, struct netconfig *nconf, struct netbuf *nb) { struct nfs_svc_args nsa; char *ua, *ua2, *mua = NULL; char me[MAXHOSTNAMELEN]; struct nd_addrlist *nas; struct nd_hostserv hs; struct nd_mergearg ma; ua = taddr2uaddr(nconf, nb); if (ua == NULL) { #ifdef DEBUG fprintf(stderr, "taddr2uaddr failed for netid %s\n", nconf->nc_netid); #endif return (NULL); } gethostname(me, MAXHOSTNAMELEN); hs.h_host = me; hs.h_serv = "nfs"; if (netdir_getbyname(nconf, &hs, &nas)) { #ifdef DEBUG netdir_perror("netdir_getbyname"); #endif return (NULL); } ua2 = taddr2uaddr(nconf, nas->n_addrs); if (ua2 == NULL) { #ifdef DEBUG fprintf(stderr, "taddr2uaddr failed for netid %s.\n", nconf->nc_netid); #endif return (NULL); } ma.s_uaddr = ua; ma.c_uaddr = ua2; ma.m_uaddr = NULL; if (netdir_options(nconf, ND_MERGEADDR, 0, (char *)&ma)) { #ifdef DEBUG netdir_perror("netdir_options"); #endif return (NULL); } mua = ma.m_uaddr; return (mua); }
/* * check for trusted host and user */ static int check_host( struct svc_req *rqstp /* RPC stuff */ ) { struct authsys_parms *sys_credp; SVCXPRT *transp = rqstp->rq_xprt; struct netconfig *nconfp = NULL; struct nd_hostservlist *hservlistp = NULL; int i; int rval = -1; char *inplace = NULL; /* check for root */ /*LINTED*/ sys_credp = (struct authsys_parms *)rqstp->rq_clntcred; assert(sys_credp != NULL); if (sys_credp->aup_uid != 0) goto out; /* get hostnames */ if (transp->xp_netid == NULL) { md_eprintf("transp->xp_netid == NULL\n"); goto out; } if ((nconfp = getnetconfigent(transp->xp_netid)) == NULL) { #ifdef DEBUG nc_perror("getnetconfigent(transp->xp_netid)"); #endif goto out; } if ((__netdir_getbyaddr_nosrv(nconfp, &hservlistp, &transp->xp_rtaddr) != 0) || (hservlistp == NULL)) { #ifdef DEBUG netdir_perror("netdir_getbyaddr(transp->xp_rtaddr)"); #endif goto out; } /* check hostnames */ for (i = 0; (i < hservlistp->h_cnt); ++i) { struct nd_hostserv *hservp = &hservlistp->h_hostservs[i]; char *hostname = hservp->h_host; inplace = strdup(hostname); /* localhost is OK */ if (strcmp(hostname, mynode()) == 0) { rval = 0; goto out; } /* check for remote root access */ if (ruserok(hostname, 1, "root", "root") == 0) { rval = 0; goto out; } sdssc_cm_nm2nid(inplace); if (strcmp(inplace, hostname)) { /* * If the names are now different it indicates * that hostname was converted to a nodeid. This * will only occur if hostname is part of the same * cluster that the current node is in. * If the machine is not running in a cluster than * sdssc_cm_nm2nid is a noop which leaves inplace * alone. */ rval = 0; goto out; } } /* cleanup, return success */ out: if (inplace) free(inplace); if (hservlistp != NULL) netdir_free(hservlistp, ND_HOSTSERVLIST); if (nconfp != NULL) Free(nconfp); return (rval); }