ypserv_proc.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 970 行 · 第 1/2 页

C
970
字号
		    		resp.ypmatch_resp_valdat = fetch(req.ypmatch_req_keydat);		if (resp.ypmatch_resp_valptr != NULL) {			resp.ypmatch_resp_status = YP_TRUE;		} else {			resp.ypmatch_resp_status = YP_NOKEY;		}	}	resp.yp_resptype = YPMATCH_RESPTYPE;	if (!svc_sendreply(transp, _xdr_ypresponse, &resp) ) {		RESPOND_ERR;	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		FREE_ERR;	}}/* * This implements the yp "get first" function. */voidypoldfirst(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	char mapname[YPDBPATH_LENGTH + YPMAXDOMAIN + YPMAXMAP + 3];	bool dbmop_ok = TRUE;	struct yprequest req;	struct ypresponse resp;	char *fun = "ypoldfirst";		req.ypfirst_req_domain = req.ypfirst_req_map = NULL;	resp.ypfirst_resp_keyptr = resp.ypfirst_resp_valptr = NULL;	resp.ypfirst_resp_keysize = resp.ypfirst_resp_valsize = 0;	if (!svc_getargs(transp, _xdr_yprequest, &req) ) {		svcerr_decode(transp);		return;	}	if (req.yp_reqtype != YPFIRST_REQTYPE) {		resp.ypfirst_resp_status = YP_BADARGS;		dbmop_ok = FALSE;	};	if (dbmop_ok && ypset_current_map(req.ypfirst_req_map,	    req.ypfirst_req_domain, &resp.ypfirst_resp_status) ) {		resp.ypfirst_resp_keydat = firstkey();		if (resp.ypfirst_resp_keyptr != NULL) {			resp.ypfirst_resp_valdat =			    fetch(resp.ypfirst_resp_keydat);			if (resp.ypfirst_resp_valptr != NULL) {				resp.ypfirst_resp_status = YP_TRUE;			} else {				resp.ypfirst_resp_status = YP_BADDB;			}		} else {			resp.ypfirst_resp_status = YP_NOKEY;		}	}	resp.yp_resptype = YPFIRST_RESPTYPE;	if (!svc_sendreply(transp, _xdr_ypresponse, &resp) ) {		RESPOND_ERR;	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		FREE_ERR;	}}/* * This implements the yp "get next" function. */voidypoldnext(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	char mapname[YPDBPATH_LENGTH + YPMAXDOMAIN + YPMAXMAP + 3];	bool dbmop_ok = TRUE;	struct yprequest req;	struct ypresponse resp;	char *fun = "ypoldnext";		req.ypnext_req_domain = req.ypnext_req_map = NULL;	req.ypnext_req_keyptr = NULL;	resp.ypnext_resp_keyptr = resp.ypnext_resp_valptr = NULL;	resp.ypnext_resp_keysize = resp.ypnext_resp_valsize = 0;	if (!svc_getargs(transp, _xdr_yprequest, &req) ) {		svcerr_decode(transp);		return;	}	if (req.yp_reqtype != YPNEXT_REQTYPE) {		resp.ypnext_resp_status = YP_BADARGS;		dbmop_ok = FALSE;	};	if (dbmop_ok && ypset_current_map(req.ypnext_req_map,	    req.ypnext_req_domain, &resp.ypnext_resp_status) ) {		resp.ypnext_resp_keydat = nextkey(req.ypnext_req_keydat);		if (resp.ypnext_resp_keyptr != NULL) {			resp.ypnext_resp_valdat =			    fetch(resp.ypnext_resp_keydat);			if (resp.ypnext_resp_valptr != NULL) {				resp.ypnext_resp_status = YP_TRUE;			} else {				resp.ypnext_resp_status = YP_BADDB;			}		} else {			resp.ypnext_resp_status = YP_NOMORE;		}	}		resp.yp_resptype = YPNEXT_RESPTYPE;	if (!svc_sendreply(transp, _xdr_ypresponse, &resp) ) {		RESPOND_ERR;	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		FREE_ERR;	}}/* * This retrieves the order number and master peer name from the map. * The conditions for the various message fields are: * 	domain is filled in iff the domain exists. *	map is filled in iff the map exists. * 	order number is filled in iff it's in the map. * 	owner is filled in iff the master peer is in the map. */voidypoldpoll(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	struct yprequest req;	struct ypresponse resp;	char *map = "";	char *domain = "";	char *owner = "";	unsigned error;	char *fun = "ypoldpoll";		req.yppoll_req_domain = req.yppoll_req_map = NULL;	if (!svc_getargs(transp, _xdr_yprequest, &req) ) {		svcerr_decode(transp);		return;	}	resp.yppoll_resp_ordernum = 0;	if (req.yp_reqtype == YPPOLL_REQTYPE) {		if (strcmp(req.yppoll_req_domain,"yp_private")==0 ||		    strcmp(req.yppoll_req_map,"ypdomains")==0 ||		    strcmp(req.yppoll_req_map,"ypmaps")==0 ) {		  /*		   * backward compatibility for 2.0 YP servers		   */			domain = req.yppoll_req_domain;			map = req.yppoll_req_map;			resp.yppoll_resp_ordernum = 0;		    		}		else if (ypset_current_map(req.yppoll_req_map,		    req.yppoll_req_domain, &error)) {			domain = req.yppoll_req_domain;			map = req.yppoll_req_map;			(void) ypget_map_order(map, domain,			    &resp.yppoll_resp_ordernum);			(void) ypget_map_master(map, domain,				    &owner);		} else {						switch (error) {							case YP_BADDB:				map = req.yppoll_req_map;				/* Fall through to set the domain, too. */						case YP_NOMAP:				domain = req.yppoll_req_domain;				break;			}		}	}		resp.yp_resptype = YPPOLL_RESPTYPE;	resp.yppoll_resp_domain = domain;	resp.yppoll_resp_map = map;	resp.yppoll_resp_owner = owner;	if (!svc_sendreply(transp, _xdr_ypresponse, &resp) ) {		RESPOND_ERR;	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		FREE_ERR;	}}/* * yppush */voidyppush(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	struct yprequest req;	int pid;	char *fun = "yppush";	req.yppush_req_domain = req.yppush_req_map = NULL;	if (!svc_getargs(transp, _xdr_yprequest, &req) ) {		svcerr_decode(transp);		return;	}	pid = vfork();			if (pid == -1) {		FORK_ERR;	} else if (pid == 0) {		ypclr_current_map();		if (execl(yppush_proc, "yppush", "-d", req.yppush_req_domain, 		    req.yppush_req_map, NULL) ) {			EXEC_ERR;		}		_exit(1);	}	if (!svc_sendreply(transp, xdr_void, 0) ) {		RESPOND_ERR;	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		FREE_ERR;	}}/* * This clears the current map, vforks, and execs the ypxfr process to get * the map referred to in the request. */voidypget(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	struct yprequest req;	int pid;	char *fun = "ypget";	req.ypget_req_domain = req.ypget_req_map = req.ypget_req_owner = NULL;	req.ypget_req_ordernum = 0;		if (!svc_getargs(transp, _xdr_yprequest, &req) ) {		svcerr_decode(transp);		return;	}	if (!svc_sendreply(transp, xdr_void, 0) ) {		RESPOND_ERR;	}	if (req.yp_reqtype == YPGET_REQTYPE) {				pid = vfork();				if (pid == -1) {			FORK_ERR;		} else if (pid == 0) {			ypclr_current_map();			if (execl(ypxfr_proc, "ypxfr", "-d",			    req.ypget_req_domain, "-h", req.ypget_req_owner,			    req.ypget_req_map, NULL) ) {				EXEC_ERR;			}			_exit(1);		}	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		RESPOND_ERR;	}}/* * This clears the current map, vforks, and execs the ypxfr process to get * the map referred to in the request. */voidyppull(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	struct yprequest req;	int pid;	char *fun = "yppull";	req.yppull_req_domain = req.yppull_req_map = NULL;		if (!svc_getargs(transp, _xdr_yprequest, &req) ) {		svcerr_decode(transp);		return;	}	if (!svc_sendreply(transp, xdr_void, 0) ) {		RESPOND_ERR;	}	if (req.yp_reqtype == YPPULL_REQTYPE) {				pid = vfork();				if (pid == -1) {			FORK_ERR;		} else if (pid == 0) {			ypclr_current_map();			if (execl(ypxfr_proc, "ypxfr", "-d",			    req.yppull_req_domain, req.yppull_req_map, NULL) ) {				EXEC_ERR;			}			_exit(1);		}	}	if (!svc_freeargs(transp, _xdr_yprequest, &req) ) {		FREE_ERR;	}}/* * Ancillary functions used by the top-level functions within this module *//* * This returns TRUE if a given key is a yp-private symbol, otherwise FALSE */static boolisypsym(key)	datum *key;{	struct yppriv_sym *psym;	if (key->dptr == NULL) {		return (FALSE);	}		for (psym = filter_set; psym->sym; psym++) {				if (psym->len == key->dsize &&		    !bcmp(psym->sym, key->dptr, key->dsize) ) {			return (TRUE);		}	}	return (FALSE);}/* * This provides private-symbol filtration for the enumeration functions. */static voidypfilter(inkey, outkey, val, status)	datum *inkey;	datum *outkey;	datum *val;	int *status;{	datum k;	if (inkey) {		if (isypsym(inkey) ) {			*status = YP_BADARGS;			return;		}				k = nextkey(*inkey);	} else {		k = firstkey();	}		while (k.dptr && isypsym(&k)) {		k = nextkey(k);	}			if (k.dptr == NULL) {		*status = YP_NOMORE;		return;	}	*outkey = k;	*val = fetch(k);	if (val->dptr != NULL) {		*status = YP_TRUE;	} else {		*status = YP_BADDB;	}}		/* * Serializes a stream of struct ypresp_key_val's.  This is used * only by the ypserv side of the transaction. */static boolxdrypserv_ypall(xdrs, req)	XDR * xdrs;	struct ypreq_nokey *req;{	bool more = TRUE;	struct ypresp_key_val resp;	resp.keydat.dptr = resp.valdat.dptr = (char *) NULL;	resp.keydat.dsize = resp.valdat.dsize = 0;		if (ypset_current_map(req->map, req->domain, &resp.status)) {		ypfilter(NULL, &resp.keydat, &resp.valdat, &resp.status);		while (resp.status == YP_TRUE) {			if (!xdr_bool(xdrs, &more) ) {				return (FALSE);			}			if (!xdr_ypresp_key_val(xdrs, &resp) ) {				return (FALSE);			}			ypfilter(&resp.keydat, &resp.keydat, &resp.valdat,			    &resp.status);		}			}		if (!xdr_bool(xdrs, &more) ) {		return (FALSE);	}	if (!xdr_ypresp_key_val(xdrs, &resp) ) {		return (FALSE);	}	more = FALSE;		if (!xdr_bool(xdrs, &more) ) {		return (FALSE);	}	return (TRUE);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?