Ejemplo n.º 1
0
static void
universal(struct svc_req *rqstp, SVCXPRT *transp)
{
	rpcprog_t prog;
	rpcvers_t vers;
	rpcproc_t proc;
	char *outdata;
	char *xdrbuf;
	struct proglst *pl;

	/*
	 * enforce "procnum 0 is echo" convention
	 */
	if (rqstp->rq_proc == NULLPROC) {
		if (svc_sendreply(transp, (xdrproc_t) xdr_void, NULL) ==
		    FALSE) {
			warnx("svc_sendreply failed");
		}
		return;
	}
	prog = rqstp->rq_prog;
	vers = rqstp->rq_vers;
	proc = rqstp->rq_proc;
	mutex_lock(&proglst_lock);
	for (pl = proglst; pl; pl = pl->p_nxt)
		if (pl->p_prognum == prog && pl->p_procnum == proc &&
			pl->p_versnum == vers &&
			(strcmp(pl->p_netid, transp->xp_netid) == 0)) {
			/* decode arguments into a CLEAN buffer */
			xdrbuf = pl->p_xdrbuf;
			/* Zero the arguments: reqd ! */
			(void) memset(xdrbuf, 0, (size_t)pl->p_recvsz);
			/*
			 * Assuming that sizeof (xdrbuf) would be enough
			 * for the arguments; if not then the program
			 * may bomb. BEWARE!
			 */
			if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
				svcerr_decode(transp);
				mutex_unlock(&proglst_lock);
				return;
			}
			outdata = (*(pl->p_progname))(xdrbuf);
			if (outdata == NULL &&
				pl->p_outproc != (xdrproc_t) xdr_void){
				/* there was an error */
				mutex_unlock(&proglst_lock);
				return;
			}
			if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
				warnx(
			"rpc: rpc_reg trouble replying to prog %u vers %u",
				(unsigned)prog, (unsigned)vers);
				mutex_unlock(&proglst_lock);
				return;
			}
			/* free the decoded arguments */
			(void)svc_freeargs(transp, pl->p_inproc, xdrbuf);
			mutex_unlock(&proglst_lock);
			return;
		}
	mutex_unlock(&proglst_lock);
	/* This should never happen */
	warnx("rpc: rpc_reg: never registered prog %u vers %u",
		(unsigned)prog, (unsigned)vers);
	return;
}
Ejemplo n.º 2
0
void
export_program_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		epgw_mount_arg_t ep_mount_1_arg;
		uint32_t ep_umount_1_arg;
		uint32_t ep_statfs_1_arg;
		epgw_lookup_arg_t ep_lookup_1_arg;
		epgw_mfile_arg_t ep_getattr_1_arg;
		epgw_setattr_arg_t ep_setattr_1_arg;
		epgw_mfile_arg_t ep_readlink_1_arg;
		epgw_mknod_arg_t ep_mknod_1_arg;
		epgw_mkdir_arg_t ep_mkdir_1_arg;
		epgw_unlink_arg_t ep_unlink_1_arg;
		epgw_rmdir_arg_t ep_rmdir_1_arg;
		epgw_symlink_arg_t ep_symlink_1_arg;
		epgw_rename_arg_t ep_rename_1_arg;
		epgw_readdir_arg_t ep_readdir_1_arg;
		epgw_write_block_arg_t ep_write_block_1_arg;
		epgw_link_arg_t ep_link_1_arg;
		epgw_setxattr_arg_t ep_setxattr_1_arg;
		epgw_getxattr_arg_t ep_getxattr_1_arg;
		epgw_removexattr_arg_t ep_removexattr_1_arg;
		epgw_listxattr_arg_t ep_listxattr_1_arg;
		epgw_cluster_arg_t ep_list_cluster_1_arg;
		epgw_conf_stor_arg_t ep_conf_storage_1_arg;
		ep_gateway_t ep_poll_conf_1_arg;
		ep_path_t ep_conf_expgw_1_arg;
		epgw_lock_arg_t ep_set_file_lock_1_arg;
		epgw_lock_arg_t ep_get_file_lock_1_arg;
		epgw_lock_arg_t ep_clear_owner_file_lock_1_arg;
		epgw_lock_arg_t ep_clear_client_file_lock_1_arg;
		epgw_lock_arg_t ep_poll_file_lock_1_arg;
		epgw_symlink2_arg_t ep_symlink2_1_arg;
		epgw_mount_arg_t ep_mount_msite_1_arg;
		epgw_cluster_arg_t ep_list_cluster2_1_arg;
		epgw_getxattr_arg_t ep_getxattr_raw_1_arg;
		epgw_readdir_arg_t ep_readdir2_1_arg;
		epgw_lock_arg_t ep_poll_owner_lock_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case EP_NULL:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) ep_null_1_svc;
		break;

	case EP_MOUNT:
		_xdr_argument = (xdrproc_t) xdr_epgw_mount_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mount_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_mount_1_svc;
		break;

	case EP_UMOUNT:
		_xdr_argument = (xdrproc_t) xdr_uint32_t;
		_xdr_result = (xdrproc_t) xdr_epgw_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_umount_1_svc;
		break;

	case EP_STATFS:
		_xdr_argument = (xdrproc_t) xdr_uint32_t;
		_xdr_result = (xdrproc_t) xdr_epgw_statfs_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_statfs_1_svc;
		break;

	case EP_LOOKUP:
		_xdr_argument = (xdrproc_t) xdr_epgw_lookup_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_lookup_1_svc;
		break;

	case EP_GETATTR:
		_xdr_argument = (xdrproc_t) xdr_epgw_mfile_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_getattr_1_svc;
		break;

	case EP_SETATTR:
		_xdr_argument = (xdrproc_t) xdr_epgw_setattr_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_setattr_1_svc;
		break;

	case EP_READLINK:
		_xdr_argument = (xdrproc_t) xdr_epgw_mfile_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_readlink_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_readlink_1_svc;
		break;

	case EP_MKNOD:
		_xdr_argument = (xdrproc_t) xdr_epgw_mknod_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_mknod_1_svc;
		break;

	case EP_MKDIR:
		_xdr_argument = (xdrproc_t) xdr_epgw_mkdir_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_mkdir_1_svc;
		break;

	case EP_UNLINK:
		_xdr_argument = (xdrproc_t) xdr_epgw_unlink_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_fid_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_unlink_1_svc;
		break;

	case EP_RMDIR:
		_xdr_argument = (xdrproc_t) xdr_epgw_rmdir_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_fid_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_rmdir_1_svc;
		break;

	case EP_SYMLINK:
		_xdr_argument = (xdrproc_t) xdr_epgw_symlink_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_symlink_1_svc;
		break;

	case EP_RENAME:
		_xdr_argument = (xdrproc_t) xdr_epgw_rename_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_rename_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_rename_1_svc;
		break;

	case EP_READDIR:
		_xdr_argument = (xdrproc_t) xdr_epgw_readdir_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_readdir_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_readdir_1_svc;
		break;

	case EP_WRITE_BLOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_write_block_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_write_block_1_svc;
		break;

	case EP_LINK:
		_xdr_argument = (xdrproc_t) xdr_epgw_link_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_link_1_svc;
		break;

	case EP_SETXATTR:
		_xdr_argument = (xdrproc_t) xdr_epgw_setxattr_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_setxattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_setxattr_1_svc;
		break;

	case EP_GETXATTR:
		_xdr_argument = (xdrproc_t) xdr_epgw_getxattr_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_getxattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_getxattr_1_svc;
		break;

	case EP_REMOVEXATTR:
		_xdr_argument = (xdrproc_t) xdr_epgw_removexattr_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_removexattr_1_svc;
		break;

	case EP_LISTXATTR:
		_xdr_argument = (xdrproc_t) xdr_epgw_listxattr_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_listxattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_listxattr_1_svc;
		break;

	case EP_LIST_CLUSTER:
		_xdr_argument = (xdrproc_t) xdr_epgw_cluster_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_cluster_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_list_cluster_1_svc;
		break;

	case EP_CONF_STORAGE:
		_xdr_argument = (xdrproc_t) xdr_epgw_conf_stor_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_conf_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_conf_storage_1_svc;
		break;

	case EP_POLL_CONF:
		_xdr_argument = (xdrproc_t) xdr_ep_gateway_t;
		_xdr_result = (xdrproc_t) xdr_epgw_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_poll_conf_1_svc;
		break;

	case EP_CONF_EXPGW:
		_xdr_argument = (xdrproc_t) xdr_ep_path_t;
		_xdr_result = (xdrproc_t) xdr_ep_gw_gateway_configuration_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_conf_expgw_1_svc;
		break;

	case EP_SET_FILE_LOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_lock_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_lock_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_set_file_lock_1_svc;
		break;

	case EP_GET_FILE_LOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_lock_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_lock_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_get_file_lock_1_svc;
		break;

	case EP_CLEAR_OWNER_FILE_LOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_lock_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_clear_owner_file_lock_1_svc;
		break;

	case EP_CLEAR_CLIENT_FILE_LOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_lock_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_clear_client_file_lock_1_svc;
		break;

	case EP_POLL_FILE_LOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_lock_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_poll_file_lock_1_svc;
		break;

	case EP_GEO_POLL:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) ep_geo_poll_1_svc;
		break;

	case EP_SYMLINK2:
		_xdr_argument = (xdrproc_t) xdr_epgw_symlink2_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mattr_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_symlink2_1_svc;
		break;

	case EP_MOUNT_MSITE:
		_xdr_argument = (xdrproc_t) xdr_epgw_mount_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_mount_msite_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_mount_msite_1_svc;
		break;

	case EP_LIST_CLUSTER2:
		_xdr_argument = (xdrproc_t) xdr_epgw_cluster_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_cluster2_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_list_cluster2_1_svc;
		break;

	case EP_GETXATTR_RAW:
		_xdr_argument = (xdrproc_t) xdr_epgw_getxattr_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_getxattr_raw_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_getxattr_raw_1_svc;
		break;

	case EP_READDIR2:
		_xdr_argument = (xdrproc_t) xdr_epgw_readdir_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_readdir2_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_readdir2_1_svc;
		break;

	case EP_POLL_OWNER_LOCK:
		_xdr_argument = (xdrproc_t) xdr_epgw_lock_arg_t;
		_xdr_result = (xdrproc_t) xdr_epgw_lock_ret_t;
		local = (char *(*)(char *, struct svc_req *)) ep_poll_owner_lock_1_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 3
0
static void
mailbox_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		char *start1_1_arg;
		char *quit1_1_arg;
		struct message insert_message1_1_arg;
		struct usermsgid retrieve_message_1_arg;
		char *list_all_messages_1_arg;
		struct usermsgid delete_message_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case START1:
		_xdr_argument = (xdrproc_t) xdr_wrapstring;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) start1_1_svc;
		break;

	case QUIT1:
		_xdr_argument = (xdrproc_t) xdr_wrapstring;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) quit1_1_svc;
		break;

	case INSERT_MESSAGE1:
		_xdr_argument = (xdrproc_t) xdr_message;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) insert_message1_1_svc;
		break;

	case RETRIEVE_MESSAGE:
		_xdr_argument = (xdrproc_t) xdr_usermsgid;
		_xdr_result = (xdrproc_t) xdr_wrapstring;
		local = (char *(*)(char *, struct svc_req *)) retrieve_message_1_svc;
		break;

	case LIST_ALL_MESSAGES:
		_xdr_argument = (xdrproc_t) xdr_wrapstring;
		_xdr_result = (xdrproc_t) xdr_listmessages;
		local = (char *(*)(char *, struct svc_req *)) list_all_messages_1_svc;
		break;

	case DELETE_MESSAGE:
		_xdr_argument = (xdrproc_t) xdr_usermsgid;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) delete_message_1_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 4
0
void
storage_program_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		sp_write_arg_t sp_write_1_arg;
		sp_read_arg_t sp_read_1_arg;
		sp_truncate_arg_t sp_truncate_1_arg;
		sp_write_repair_arg_t sp_write_repair_1_arg;
		sp_remove_arg_t sp_remove_1_arg;
		sp_rebuild_start_arg_t sp_rebuild_start_1_arg;
		sp_rebuild_stop_arg_t sp_rebuild_stop_1_arg;
		sp_remove_chunk_arg_t sp_remove_chunk_1_arg;
		sp_clear_error_arg_t sp_clear_error_1_arg;
		sp_write_repair2_arg_t sp_write_repair2_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case SP_NULL:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) sp_null_1_svc;
		break;

	case SP_WRITE:
		_xdr_argument = (xdrproc_t) xdr_sp_write_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_write_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_write_1_svc;
		break;

	case SP_READ:
		_xdr_argument = (xdrproc_t) xdr_sp_read_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_read_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_read_1_svc;
		break;

	case SP_TRUNCATE:
		_xdr_argument = (xdrproc_t) xdr_sp_truncate_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_truncate_1_svc;
		break;

	case SP_WRITE_REPAIR:
		_xdr_argument = (xdrproc_t) xdr_sp_write_repair_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_write_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_write_repair_1_svc;
		break;

	case SP_REMOVE:
		_xdr_argument = (xdrproc_t) xdr_sp_remove_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_remove_1_svc;
		break;

	case SP_REBUILD_START:
		_xdr_argument = (xdrproc_t) xdr_sp_rebuild_start_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_rebuild_start_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_rebuild_start_1_svc;
		break;

	case SP_REBUILD_STOP:
		_xdr_argument = (xdrproc_t) xdr_sp_rebuild_stop_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_rebuild_stop_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_rebuild_stop_1_svc;
		break;

	case SP_REMOVE_CHUNK:
		_xdr_argument = (xdrproc_t) xdr_sp_remove_chunk_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_remove_chunk_1_svc;
		break;

	case SP_CLEAR_ERROR:
		_xdr_argument = (xdrproc_t) xdr_sp_clear_error_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_status_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_clear_error_1_svc;
		break;

	case SP_WRITE_REPAIR2:
		_xdr_argument = (xdrproc_t) xdr_sp_write_repair2_arg_t;
		_xdr_result = (xdrproc_t) xdr_sp_write_ret_t;
		local = (char *(*)(char *, struct svc_req *)) sp_write_repair2_1_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 5
0
static void
fs_server_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		int mi_get_size_1_arg;
		mi_creat_1_argument mi_creat_1_arg;
		mi_open_1_argument mi_open_1_arg;
		int mi_close_1_arg;
		char *mi_unlink_1_arg;
		mi_read_1_argument mi_read_1_arg;
		mi_write_1_argument mi_write_1_arg;
	} argument;
	union {
		int mi_get_size_1_res;
		int mi_creat_1_res;
		int mi_open_1_res;
		int mi_close_1_res;
		int mi_unlink_1_res;
		ReadRes mi_read_1_res;
		int mi_write_1_res;
	} result;
	bool_t retval;
	xdrproc_t _xdr_argument, _xdr_result;
	bool_t (*local)(char *, void *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case mi_get_size:
		_xdr_argument = (xdrproc_t) xdr_int;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_get_size_1;
		break;

	case mi_creat:
		_xdr_argument = (xdrproc_t) xdr_mi_creat_1_argument;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_creat_1;
		break;

	case mi_open:
		_xdr_argument = (xdrproc_t) xdr_mi_open_1_argument;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_open_1;
		break;

	case mi_close:
		_xdr_argument = (xdrproc_t) xdr_int;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_close_1;
		break;

	case mi_unlink:
		_xdr_argument = (xdrproc_t) xdr_wrapstring;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_unlink_1;
		break;

	case mi_read:
		_xdr_argument = (xdrproc_t) xdr_mi_read_1_argument;
		_xdr_result = (xdrproc_t) xdr_ReadRes;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_read_1;
		break;

	case mi_write:
		_xdr_argument = (xdrproc_t) xdr_mi_write_1_argument;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (bool_t (*) (char *, void *,  struct svc_req *))_mi_write_1;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
	if (retval > 0 && !svc_sendreply(transp, (xdrproc_t) _xdr_result, (char *)&result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	if (!fs_server_1_freeresult (transp, _xdr_result, (caddr_t) &result))
		fprintf (stderr, "%s", "unable to free results");

	return;
}
Ejemplo n.º 6
0
void
nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp)
{
  union {
    am_nfs_fh		nfsproc_getattr_2_arg;
    nfssattrargs	nfsproc_setattr_2_arg;
    nfsdiropargs	nfsproc_lookup_2_arg;
    am_nfs_fh		nfsproc_readlink_2_arg;
    nfsreadargs		nfsproc_read_2_arg;
    nfswriteargs	nfsproc_write_2_arg;
    nfscreateargs	nfsproc_create_2_arg;
    nfsdiropargs	nfsproc_remove_2_arg;
    nfsrenameargs	nfsproc_rename_2_arg;
    nfslinkargs		nfsproc_link_2_arg;
    nfssymlinkargs	nfsproc_symlink_2_arg;
    nfscreateargs	nfsproc_mkdir_2_arg;
    nfsdiropargs	fsproc_rmdir_2_arg;
    nfsreaddirargs	nfsproc_readdir_2_arg;
    am_nfs_fh		nfsproc_statfs_2_arg;
  } argument;
  char *result;
  xdrproc_t xdr_argument, xdr_result;
  nfssvcproc_t local;

#ifdef HAVE_TRANSPORT_TYPE_TLI
  /*
   * On TLI systems we don't use an INET network type, but a "ticlts" (see
   * /etc/netconfig and conf/transp_tli.c:create_nfs_service).  This means
   * that packets could only come from the loopback interface, and we don't
   * need to check them and filter possibly spoofed packets.  Therefore we
   * only need to check if the UID caller is correct.
   */
# ifdef HAVE___RPC_GET_LOCAL_UID
  uid_t u;
  /* extern definition for an internal libnsl function */
  extern int __rpc_get_local_uid(SVCXPRT *transp, uid_t *uid);
  if (__rpc_get_local_uid(transp, &u) >= 0  &&  u != 0) {
    plog(XLOG_WARNING, "ignoring request from UID %ld, must be 0", (long) u);
    return;
  }
# else /* not HAVE___RPC_GET_LOCAL_UID */
  dlog("cannot verify local uid for rpc request");
# endif /* HAVE___RPC_GET_LOCAL_UID */
#else /* not HAVE_TRANPORT_TYPE_TLI */
  struct sockaddr_in *sinp;
  char dq[20], dq2[28];
  sinp = amu_svc_getcaller(rqstp->rq_xprt);
# ifdef MNT2_NFS_OPT_RESVPORT
  /* Verify that the request comes from a reserved port */
  if (sinp &&
      ntohs(sinp->sin_port) >= IPPORT_RESERVED &&
      !(gopt.flags & CFM_NFS_INSECURE_PORT)) {
    plog(XLOG_WARNING, "ignoring request from %s:%u, port not reserved",
	 inet_dquad(dq, sizeof(dq), sinp->sin_addr.s_addr),
	 ntohs(sinp->sin_port));
    return;
  }
# endif /* MNT2_NFS_OPT_RESVPORT */
  /* if the address does not match, ignore the request */
  if (sinp && (sinp->sin_addr.s_addr != myipaddr.s_addr)) {
    if (gopt.flags & CFM_NFS_ANY_INTERFACE) {
      if (!is_interface_local(sinp->sin_addr.s_addr)) {
	plog(XLOG_WARNING, "ignoring request from %s:%u, not a local interface",
	     inet_dquad(dq, sizeof(dq), sinp->sin_addr.s_addr),
	     ntohs(sinp->sin_port));
      }
    } else {
      plog(XLOG_WARNING, "ignoring request from %s:%u, expected %s",
	   inet_dquad(dq, sizeof(dq), sinp->sin_addr.s_addr),
	   ntohs(sinp->sin_port),
	   inet_dquad(dq2, sizeof(dq2), myipaddr.s_addr));
      return;
    }
  }
#endif /* not HAVE_TRANPORT_TYPE_TLI */

  current_transp = NULL;

  switch (rqstp->rq_proc) {

  case NFSPROC_NULL:
    xdr_argument = (xdrproc_t) xdr_void;
    xdr_result = (xdrproc_t) xdr_void;
    local = (nfssvcproc_t) nfsproc_null_2_svc;
    break;

  case NFSPROC_GETATTR:
    xdr_argument = (xdrproc_t) xdr_nfs_fh;
    xdr_result = (xdrproc_t) xdr_attrstat;
    local = (nfssvcproc_t) nfsproc_getattr_2_svc;
    break;

  case NFSPROC_SETATTR:
    xdr_argument = (xdrproc_t) xdr_sattrargs;
    xdr_result = (xdrproc_t) xdr_attrstat;
    local = (nfssvcproc_t) nfsproc_setattr_2_svc;
    break;

  case NFSPROC_ROOT:
    xdr_argument = (xdrproc_t) xdr_void;
    xdr_result = (xdrproc_t) xdr_void;
    local = (nfssvcproc_t) nfsproc_root_2_svc;
    break;

  case NFSPROC_LOOKUP:
    xdr_argument = (xdrproc_t) xdr_diropargs;
    xdr_result = (xdrproc_t) xdr_diropres;
    local = (nfssvcproc_t) nfsproc_lookup_2_svc;
    /*
     * Cheap way to pass transp down to amfs_auto_lookuppn so it can
     * be stored in the am_node structure and later used for
     * quick_reply().
     */
    current_transp = transp;
    break;

  case NFSPROC_READLINK:
    xdr_argument = (xdrproc_t) xdr_nfs_fh;
    xdr_result = (xdrproc_t) xdr_readlinkres;
    local = (nfssvcproc_t) nfsproc_readlink_2_svc;
    break;

  case NFSPROC_READ:
    xdr_argument = (xdrproc_t) xdr_readargs;
    xdr_result = (xdrproc_t) xdr_readres;
    local = (nfssvcproc_t) nfsproc_read_2_svc;
    break;

  case NFSPROC_WRITECACHE:
    xdr_argument = (xdrproc_t) xdr_void;
    xdr_result = (xdrproc_t) xdr_void;
    local = (nfssvcproc_t) nfsproc_writecache_2_svc;
    break;

  case NFSPROC_WRITE:
    xdr_argument = (xdrproc_t) xdr_writeargs;
    xdr_result = (xdrproc_t) xdr_attrstat;
    local = (nfssvcproc_t) nfsproc_write_2_svc;
    break;

  case NFSPROC_CREATE:
    xdr_argument = (xdrproc_t) xdr_createargs;
    xdr_result = (xdrproc_t) xdr_diropres;
    local = (nfssvcproc_t) nfsproc_create_2_svc;
    break;

  case NFSPROC_REMOVE:
    xdr_argument = (xdrproc_t) xdr_diropargs;
    xdr_result = (xdrproc_t) xdr_nfsstat;
    local = (nfssvcproc_t) nfsproc_remove_2_svc;
    break;

  case NFSPROC_RENAME:
    xdr_argument = (xdrproc_t) xdr_renameargs;
    xdr_result = (xdrproc_t) xdr_nfsstat;
    local = (nfssvcproc_t) nfsproc_rename_2_svc;
    break;

  case NFSPROC_LINK:
    xdr_argument = (xdrproc_t) xdr_linkargs;
    xdr_result = (xdrproc_t) xdr_nfsstat;
    local = (nfssvcproc_t) nfsproc_link_2_svc;
    break;

  case NFSPROC_SYMLINK:
    xdr_argument = (xdrproc_t) xdr_symlinkargs;
    xdr_result = (xdrproc_t) xdr_nfsstat;
    local = (nfssvcproc_t) nfsproc_symlink_2_svc;
    break;

  case NFSPROC_MKDIR:
    xdr_argument = (xdrproc_t) xdr_createargs;
    xdr_result = (xdrproc_t) xdr_diropres;
    local = (nfssvcproc_t) nfsproc_mkdir_2_svc;
    break;

  case NFSPROC_RMDIR:
    xdr_argument = (xdrproc_t) xdr_diropargs;
    xdr_result = (xdrproc_t) xdr_nfsstat;
    local = (nfssvcproc_t) nfsproc_rmdir_2_svc;
    break;

  case NFSPROC_READDIR:
    xdr_argument = (xdrproc_t) xdr_readdirargs;
    xdr_result = (xdrproc_t) xdr_readdirres;
    local = (nfssvcproc_t) nfsproc_readdir_2_svc;
    break;

  case NFSPROC_STATFS:
    xdr_argument = (xdrproc_t) xdr_nfs_fh;
    xdr_result = (xdrproc_t) xdr_statfsres;
    local = (nfssvcproc_t) nfsproc_statfs_2_svc;
    break;

  default:
    svcerr_noproc(transp);
    return;
  }

  memset((char *) &argument, 0, sizeof(argument));
  if (!svc_getargs(transp,
		   (XDRPROC_T_TYPE) xdr_argument,
		   (SVC_IN_ARG_TYPE) &argument)) {
    plog(XLOG_ERROR,
	 "NFS xdr decode failed for %d %d %d",
	 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc);
    svcerr_decode(transp);
    return;
  }
  result = (*local) (&argument, rqstp);

  current_transp = NULL;

  if (result != NULL && !svc_sendreply(transp,
				       (XDRPROC_T_TYPE) xdr_result,
				       result)) {
    svcerr_systemerr(transp);
  }
  if (!svc_freeargs(transp,
		    (XDRPROC_T_TYPE) xdr_argument,
		    (SVC_IN_ARG_TYPE) & argument)) {
    plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2");
    going_down(1);
  }
}
Ejemplo n.º 7
0
void
nlm_prog_3(struct svc_req *rqstp, SVCXPRT *transp)
{
	union {
		nlm_shareargs nlm_share_3_arg;
		nlm_shareargs nlm_unshare_3_arg;
		nlm_lockargs nlm_nm_lock_3_arg;
		nlm_notify nlm_free_all_3_arg;
	} argument;
	union {
		nlm_shareres nlm_share_3_res;
		nlm_shareres nlm_unshare_3_res;
		nlm_res nlm_nm_lock_3_res;
	} result;
	bool_t retval;
	xdrproc_t xdr_argument, xdr_result;
	bool_t (*local)(char *, void *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply(rqstp,
			(xdrproc_t) xdr_void, (char *)NULL);
		svc_freereq(rqstp);
		return;

	case NLM_TEST:
	case NLM_LOCK:
	case NLM_CANCEL:
	case NLM_UNLOCK:
	case NLM_GRANTED:
	case NLM_TEST_MSG:
	case NLM_LOCK_MSG:
	case NLM_CANCEL_MSG:
	case NLM_UNLOCK_MSG:
	case NLM_GRANTED_MSG:
	case NLM_TEST_RES:
	case NLM_LOCK_RES:
	case NLM_CANCEL_RES:
	case NLM_UNLOCK_RES:
	case NLM_GRANTED_RES:
		nlm_prog_1(rqstp, transp);
		return;

	case NLM_SHARE:
		xdr_argument = (xdrproc_t) xdr_nlm_shareargs;
		xdr_result = (xdrproc_t) xdr_nlm_shareres;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_share_3_svc;
		break;

	case NLM_UNSHARE:
		xdr_argument = (xdrproc_t) xdr_nlm_shareargs;
		xdr_result = (xdrproc_t) xdr_nlm_shareres;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_unshare_3_svc;
		break;

	case NLM_NM_LOCK:
		xdr_argument = (xdrproc_t) xdr_nlm_lockargs;
		xdr_result = (xdrproc_t) xdr_nlm_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_nm_lock_3_svc;
		break;

	case NLM_FREE_ALL:
		xdr_argument = (xdrproc_t) xdr_nlm_notify;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_free_all_3_svc;
		break;

	default:
		svcerr_noproc(rqstp);
		svc_freereq(rqstp);
		return;
	}
	(void) memset((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
		svcerr_decode(rqstp);
		svc_freereq(rqstp);
		return;
	}
	retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
	if (retval > 0 && !svc_sendreply(rqstp, xdr_result, (char *)&result)) {
		svcerr_systemerr(rqstp);
	}
	if (!svc_freeargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
		printf("unable to free arguments");
		//exit(1);
	}
	svc_freereq(rqstp);
	if (!nlm_prog_3_freeresult(transp, xdr_result, (caddr_t) &result))
		printf("unable to free results");

	return;
}
Ejemplo n.º 8
0
void
rstat_service(struct svc_req *rqstp, SVCXPRT *transp)
{
    char *(*local)(void *, struct svc_req *);
    xdrproc_t xdr_argument, xdr_result;
    union {
        int fill;
    } argument;
    char *result;

    switch (rqstp->rq_proc) {
    case NULLPROC:
        (void)svc_sendreply(transp, xdr_void, (char *)NULL);
        return;

    case RSTATPROC_STATS:
        xdr_argument = (xdrproc_t)xdr_void;
        xdr_result = (xdrproc_t)xdr_statstime;
        switch (rqstp->rq_vers) {
        case RSTATVERS_ORIG:
            local = (char *(*)(void *, struct svc_req *))
                    rstatproc_stats_1_svc;
            break;
        case RSTATVERS_SWTCH:
            local = (char *(*)(void *, struct svc_req *))
                    rstatproc_stats_2_svc;
            break;
        case RSTATVERS_TIME:
            local = (char *(*)(void *, struct svc_req *))
                    rstatproc_stats_3_svc;
            break;
        default:
            svcerr_progvers(transp, RSTATVERS_ORIG, RSTATVERS_TIME);
            return;
        }
        break;

    case RSTATPROC_HAVEDISK:
        xdr_argument = (xdrproc_t)xdr_void;
        xdr_result = (xdrproc_t)xdr_u_int;
        switch (rqstp->rq_vers) {
        case RSTATVERS_ORIG:
            local = (char *(*)(void *, struct svc_req *))
                    rstatproc_havedisk_1_svc;
            break;
        case RSTATVERS_SWTCH:
            local = (char *(*)(void *, struct svc_req *))
                    rstatproc_havedisk_2_svc;
            break;
        case RSTATVERS_TIME:
            local = (char *(*)(void *, struct svc_req *))
                    rstatproc_havedisk_3_svc;
            break;
        default:
            svcerr_progvers(transp, RSTATVERS_ORIG, RSTATVERS_TIME);
            return;
        }
        break;

    default:
        svcerr_noproc(transp);
        return;
    }
    bzero((char *)&argument, sizeof(argument));
    if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
        svcerr_decode(transp);
        return;
    }
    result = (*local)(&argument, rqstp);
    if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
        svcerr_systemerr(transp);
    }
    if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) {
        syslog(LOG_ERR, "unable to free arguments");
        exit(1);
    }
}
Ejemplo n.º 9
0
static void
consumer_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		topics subscribe_1_arg;
		char *partitionsfor_1_arg;
		quad_t poll_1_arg;
		position_1_argument position_1_arg;
		seek_1_argument seek_1_arg;
		seektobeginning_1_argument seektobeginning_1_arg;
		seektoend_1_argument seektoend_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case connect:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_call_result1;
		local = (char *(*)(char *, struct svc_req *)) _connect_1;
		break;

	case subscribe:
		_xdr_argument = (xdrproc_t) xdr_topics;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) _subscribe_1;
		break;

	case unsubscribe:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) _unsubscribe_1;
		break;

	case subscription:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_topics;
		local = (char *(*)(char *, struct svc_req *)) _subscription_1;
		break;

	case partitionsFor:
		_xdr_argument = (xdrproc_t) xdr_wrapstring;
		_xdr_result = (xdrproc_t) xdr_partitionInfoList;
		local = (char *(*)(char *, struct svc_req *)) _partitionsfor_1;
		break;

	case poll:
		_xdr_argument = (xdrproc_t) xdr_quad_t;
		_xdr_result = (xdrproc_t) xdr_consumerRecordList;
		local = (char *(*)(char *, struct svc_req *)) _poll_1;
		break;

	case position:
		_xdr_argument = (xdrproc_t) xdr_position_1_argument;
		_xdr_result = (xdrproc_t) xdr_quad_t;
		local = (char *(*)(char *, struct svc_req *)) _position_1;
		break;

	case seek:
		_xdr_argument = (xdrproc_t) xdr_seek_1_argument;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) _seek_1;
		break;

	case seekToBeginning:
		_xdr_argument = (xdrproc_t) xdr_seektobeginning_1_argument;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) _seektobeginning_1;
		break;

	case seekToEnd:
		_xdr_argument = (xdrproc_t) xdr_seektoend_1_argument;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) _seektoend_1;
		break;

	case close:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_void;
		local = (char *(*)(char *, struct svc_req *)) _close_1;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 10
0
//****************************************//
//***       Dispatch Function          ***//
//****************************************//
static void exm_proc(struct svc_req *rqstp, SVCXPRT * transp)
{
	char *result;
	xdrproc_t xdr_argument;
	xdrproc_t xdr_result;
	char *(*proc) (union u_argument *);

	switch (rqstp->rq_proc) {
	case PROCSIMPLEPING:
		{
			xdr_argument = (xdrproc_t) xdr_int;
			xdr_result = (xdrproc_t) xdr_int;
			proc = (char *(*)(union u_argument *))simplePing;
			break;
		}
	case INTPROCNUM:
		{
			xdr_argument = (xdrproc_t) xdr_int;
			xdr_result = (xdrproc_t) xdr_int;
			proc = (char *(*)(union u_argument *))intTestProc;
			break;
		}
	case DBLPROCNUM:
		{
			xdr_argument = (xdrproc_t) xdr_double;
			xdr_result = (xdrproc_t) xdr_double;
			proc = (char *(*)(union u_argument *))dblTestProc;
			break;
		}
	case LNGPROCNUM:
		{
			xdr_argument = (xdrproc_t) xdr_long;
			xdr_result = (xdrproc_t) xdr_long;
			proc = (char *(*)(union u_argument *))lngTestProc;
			break;
		}
	case STRPROCNUM:
		{
			xdr_argument = (xdrproc_t) xdr_wrapstring;
			xdr_result = (xdrproc_t) xdr_wrapstring;
			proc = (char *(*)(union u_argument *))strTestProc;
			break;
		}
	default:
		{
			//Proc is unavaible
			svcerr_noproc(transp);
			return;
		}
	}
	memset((char *)&argument, (int)0, sizeof(argument));
	if (svc_getargs(transp, xdr_argument, (char *)&argument) == FALSE) {
		svcerr_decode(transp);
		return;
	}

	result = (char *)(*proc) ((union u_argument *)&argument);

	if ((result != NULL)
	    && (svc_sendreply(transp, xdr_result, (char *)result) == FALSE)) {
		svcerr_systemerr(transp);
	}
	if (svc_freeargs(transp, xdr_argument, (char *)&argument) == FALSE) {
		(void)fprintf(stderr, "unable to free arguments\n");
		exit(1);
	}
}
Ejemplo n.º 11
0
/*
 * RPC boilerplate
 */
static void
keyprogram(struct svc_req *rqstp, SVCXPRT *transp)
{
	union {
		keybuf key_set_1_arg;
		cryptkeyarg key_encrypt_1_arg;
		cryptkeyarg key_decrypt_1_arg;
		netnamestr key_getcred_1_arg;
		cryptkeyarg key_encrypt_2_arg;
		cryptkeyarg key_decrypt_2_arg;
		netnamestr key_getcred_2_arg;
		cryptkeyarg2 key_encrypt_pk_2_arg;
		cryptkeyarg2 key_decrypt_pk_2_arg;
		key_netstarg key_net_put_2_arg;
		netobj  key_get_conv_2_arg;
	} argument;
	char *result;
	xdrproc_t xdr_argument, xdr_result;
	char *(*local) ();
	uid_t uid = -1;
	int check_auth;

	switch (rqstp->rq_proc) {
	case NULLPROC:
		svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
		return;

	case KEY_SET:
		xdr_argument = (xdrproc_t)xdr_keybuf;
		xdr_result = (xdrproc_t)xdr_int;
		local = (char *(*)()) key_set_1_svc_prog;
		check_auth = 1;
		break;

	case KEY_ENCRYPT:
		xdr_argument = (xdrproc_t)xdr_cryptkeyarg;
		xdr_result = (xdrproc_t)xdr_cryptkeyres;
		local = (char *(*)()) key_encrypt_1_svc_prog;
		check_auth = 1;
		break;

	case KEY_DECRYPT:
		xdr_argument = (xdrproc_t)xdr_cryptkeyarg;
		xdr_result = (xdrproc_t)xdr_cryptkeyres;
		local = (char *(*)()) key_decrypt_1_svc_prog;
		check_auth = 1;
		break;

	case KEY_GEN:
		xdr_argument = (xdrproc_t)xdr_void;
		xdr_result = (xdrproc_t)xdr_des_block;
		local = (char *(*)()) key_gen_1_svc_prog;
		check_auth = 0;
		break;

	case KEY_GETCRED:
		xdr_argument = (xdrproc_t)xdr_netnamestr;
		xdr_result = (xdrproc_t)xdr_getcredres;
		local = (char *(*)()) key_getcred_1_svc_prog;
		check_auth = 0;
		break;

	case KEY_ENCRYPT_PK:
		xdr_argument = (xdrproc_t)xdr_cryptkeyarg2;
		xdr_result = (xdrproc_t)xdr_cryptkeyres;
		local = (char *(*)()) key_encrypt_pk_2_svc_prog;
		check_auth = 1;
		break;

	case KEY_DECRYPT_PK:
		xdr_argument = (xdrproc_t)xdr_cryptkeyarg2;
		xdr_result = (xdrproc_t)xdr_cryptkeyres;
		local = (char *(*)()) key_decrypt_pk_2_svc_prog;
		check_auth = 1;
		break;


	case KEY_NET_PUT:
		xdr_argument = (xdrproc_t)xdr_key_netstarg;
		xdr_result = (xdrproc_t)xdr_keystatus;
		local = (char *(*)()) key_net_put_2_svc_prog;
		check_auth = 1;
		break;

	case KEY_NET_GET:
		xdr_argument = (xdrproc_t) xdr_void;
		xdr_result = (xdrproc_t)xdr_key_netstres;
		local = (char *(*)()) key_net_get_2_svc_prog;
		check_auth = 1;
		break;

	case KEY_GET_CONV:
		xdr_argument = (xdrproc_t) xdr_keybuf;
		xdr_result = (xdrproc_t)xdr_cryptkeyres;
		local = (char *(*)()) key_get_conv_2_svc_prog;
		check_auth = 1;
		break;

	default:
		svcerr_noproc(transp);
		return;
	}
	if (check_auth) {
		if (root_auth(transp, rqstp) == 0) {
			if (debugging) {
				fprintf(stderr,
					"not local privileged process\n");
			}
			svcerr_weakauth(transp);
			return;
		}
		if (rqstp->rq_cred.oa_flavor != AUTH_SYS) {
			if (debugging) {
				fprintf(stderr, "not unix authentication\n");
			}
			svcerr_weakauth(transp);
			return;
		}
		uid = ((struct authsys_parms *)rqstp->rq_clntcred)->aup_uid;
	}

	memset(&argument, 0, sizeof (argument));
	if (!svc_getargs(transp, xdr_argument, &argument)) {
		svcerr_decode(transp);
		return;
	}
	result = (*local) (uid, &argument);
	if (!svc_sendreply(transp, xdr_result, result)) {
		if (debugging)
			fprintf(stderr, "unable to reply\n");
		svcerr_systemerr(transp);
	}
	if (!svc_freeargs(transp, xdr_argument, &argument)) {
		if (debugging)
			fprintf(stderr, "unable to free arguments\n");
		exit(1);
	}
	return;
}
static void
asociacionprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		ponerasociacion_1_argument ponerasociacion_1_arg;
		obtenerasociacion_1_argument obtenerasociacion_1_arg;
		borrarasociacion_1_argument borrarasociacion_1_arg;
		ID enumerar_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case ponerAsociacion:
		_xdr_argument = (xdrproc_t) xdr_ponerasociacion_1_argument;
		_xdr_result = (xdrproc_t) xdr_Estado;
		local = (char *(*)(char *, struct svc_req *)) _ponerasociacion_1;
		break;

	case obtenerAsociacion:
		_xdr_argument = (xdrproc_t) xdr_obtenerasociacion_1_argument;
		_xdr_result = (xdrproc_t) xdr_ResultEntrada;
		local = (char *(*)(char *, struct svc_req *)) _obtenerasociacion_1;
		break;

	case borrarAsociacion:
		_xdr_argument = (xdrproc_t) xdr_borrarasociacion_1_argument;
		_xdr_result = (xdrproc_t) xdr_Estado;
		local = (char *(*)(char *, struct svc_req *)) _borrarasociacion_1;
		break;

	case enumerar:
		_xdr_argument = (xdrproc_t) xdr_ID;
		_xdr_result = (xdrproc_t) xdr_ResultDiccionario;
		local = (char *(*)(char *, struct svc_req *)) _enumerar_1;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 13
0
static void
im_messenger_3(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		Args_login login_3_arg;
		Session getuserroster_3_arg;
		Session getmessageshistory_3_arg;
		Session getunreadmessages_3_arg;
		Args_sendMessage sendmessage_3_arg;
		Args_addUserToRoster addusertoroster_3_arg;
		Args_deleteUserFromRoster deleteuserfromroster_3_arg;
		Args_findUser finduser_3_arg;
		Session getfriendshiprequests_3_arg;
		Args_register signup_3_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case login:
		_xdr_argument = (xdrproc_t) xdr_Args_login;
		_xdr_result = (xdrproc_t) xdr_Result_login;
		local = (char *(*)(char *, struct svc_req *)) login_3_svc;
		break;

	case getUserRoster:
		_xdr_argument = (xdrproc_t) xdr_Session;
		_xdr_result = (xdrproc_t) xdr_Result_getUserRoster;
		local = (char *(*)(char *, struct svc_req *)) getuserroster_3_svc;
		break;

	case getMessagesHistory:
		_xdr_argument = (xdrproc_t) xdr_Session;
		_xdr_result = (xdrproc_t) xdr_Result_getMessagesHistory;
		local = (char *(*)(char *, struct svc_req *)) getmessageshistory_3_svc;
		break;

	case getUnreadMessages:
		_xdr_argument = (xdrproc_t) xdr_Session;
		_xdr_result = (xdrproc_t) xdr_Result_getUnreadMessages;
		local = (char *(*)(char *, struct svc_req *)) getunreadmessages_3_svc;
		break;

	case sendMessage:
		_xdr_argument = (xdrproc_t) xdr_Args_sendMessage;
		_xdr_result = (xdrproc_t) xdr_Status;
		local = (char *(*)(char *, struct svc_req *)) sendmessage_3_svc;
		break;

	case addUserToRoster:
		_xdr_argument = (xdrproc_t) xdr_Args_addUserToRoster;
		_xdr_result = (xdrproc_t) xdr_Status;
		local = (char *(*)(char *, struct svc_req *)) addusertoroster_3_svc;
		break;

	case deleteUserFromRoster:
		_xdr_argument = (xdrproc_t) xdr_Args_deleteUserFromRoster;
		_xdr_result = (xdrproc_t) xdr_Status;
		local = (char *(*)(char *, struct svc_req *)) deleteuserfromroster_3_svc;
		break;

	case findUser:
		_xdr_argument = (xdrproc_t) xdr_Args_findUser;
		_xdr_result = (xdrproc_t) xdr_Result_findUser;
		local = (char *(*)(char *, struct svc_req *)) finduser_3_svc;
		break;

	case getFriendshipRequests:
		_xdr_argument = (xdrproc_t) xdr_Session;
		_xdr_result = (xdrproc_t) xdr_Result_getFriendshipRequests;
		local = (char *(*)(char *, struct svc_req *)) getfriendshiprequests_3_svc;
		break;

	case signup:
		_xdr_argument = (xdrproc_t) xdr_Args_register;
		_xdr_result = (xdrproc_t) xdr_Status;
		local = (char *(*)(char *, struct svc_req *)) signup_3_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 14
0
static void
count_days_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		date no_leap_years_1_arg;
		date no_of_days_1_arg;
		date get_day_1_arg;
		dates get_no_of_days_1_arg;
		dates get_no_of_weekday_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case no_leap_years:
		_xdr_argument = (xdrproc_t) xdr_date;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) no_leap_years_1_svc;
		break;

	case no_of_days:
		_xdr_argument = (xdrproc_t) xdr_date;
		_xdr_result = (xdrproc_t) xdr_long;
		local = (char *(*)(char *, struct svc_req *)) no_of_days_1_svc;
		break;

	case get_day:
		_xdr_argument = (xdrproc_t) xdr_date;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) get_day_1_svc;
		break;

	case get_no_of_days:
		_xdr_argument = (xdrproc_t) xdr_dates;
		_xdr_result = (xdrproc_t) xdr_long;
		local = (char *(*)(char *, struct svc_req *)) get_no_of_days_1_svc;
		break;

	case get_no_of_weekday:
		_xdr_argument = (xdrproc_t) xdr_dates;
		_xdr_result = (xdrproc_t) xdr_long;
		local = (char *(*)(char *, struct svc_req *)) get_no_of_weekday_1_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 15
0
/*
 * Handles incoming LDM-5 RPC requests.  This method is directly and repeatedly
 * invoked by the RPC layer after svc_run(3NSL) is invoked.
 *
 * rqstp        The RPC request.
 * transp       The server-side RPC transport.
 */
void
ldmprog_5(struct svc_req *rqstp, register SVCXPRT *transp)
{
        union {
                product hereis_5_arg;
                prod_class feedme_5_arg;
                prod_class hiya_5_arg;
                prod_info notification_5_arg;
                prod_class_t notifyme_5_arg;
                comingsoon_args comingsoon_5_arg;
                datapkt blkdata_5_arg;
        } argument;
        char *result;
        xdrproc_t xdr_argument, xdr_result;
        char *(*local)(char *, struct svc_req *);
        const char* procName;

        switch (rqstp->rq_proc) {
        case NULLPROC:
                log_debug("NULLPROC");
                (void)svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
                return;

        case HEREIS:
                xdr_argument = (xdrproc_t) xdr_product;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char *(*)(char *, struct svc_req *)) hereis_5_svc;
                procName = "HEREIS";
                break;

        case FEEDME:
                xdr_argument = (xdrproc_t) xdr_prod_class;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char *(*)(char *, struct svc_req *)) feedme_5_svc;
                procName = "FEEDME";
                break;

        case HIYA:
                xdr_argument = (xdrproc_t) xdr_prod_class;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char *(*)(char *, struct svc_req *)) hiya_5_svc;
                procName = "HIYA";
                break;

        case NOTIFICATION:
                xdr_argument = (xdrproc_t) xdr_prod_info;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char*(*)(char*, struct svc_req *)) notification_5_svc;
                procName = "NOTIFICATION";
                break;

        case NOTIFYME:
                xdr_argument = (xdrproc_t) xdr_prod_class;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char *(*)(char *, struct svc_req *)) notifyme_5_svc;
                procName = "NOTIFYME";
                break;

        case COMINGSOON:
                xdr_argument = (xdrproc_t) xdr_comingsoon_args;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char *(*)(char *, struct svc_req *)) comingsoon_5_svc;
                procName = "COMINGSOON";
                break;

        case BLKDATA:
                xdr_argument = (xdrproc_t) xdr_datapkt;
                xdr_result = (xdrproc_t) xdr_ldm_replyt;
                local = (char *(*)(char *, struct svc_req *)) blkdata_5_svc;
                procName = "BLKDATA";
                break;

        default:
                svcerr_noproc(transp);
                return;
         }

        log_debug("%s", procName);
        (void) memset((void *)&argument, 0, sizeof (argument));
        if (!svc_getargs(transp, xdr_argument, (void*) &argument)) {
                log_notice("%s: Couldn't decode RPC-request arguments",
                        procName);
                svcerr_decode(transp);
                return;
        }
        result = (*local)((char *)&argument, rqstp);
        if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
                log_notice("%s: Couldn't reply to RPC-request", procName);
                svcerr_systemerr(transp);
        }
        if (!svc_freeargs(transp, xdr_argument, (void*) &argument)) {
                log_error("unable to free arguments");
                exit(1);
        }
        return;
}
Ejemplo n.º 16
0
void
ypoldfirst(SVCXPRT *transp)
{
	bool dbmop_ok = TRUE;
	struct yprequest req;
	struct ypresponse resp;
	char *fun = "ypoldfirst";
	DBM *fdb;

	memset((void *) &req, 0, sizeof (req));
	memset((void *) &resp, 0, sizeof (resp));

	if (!svc_getargs(transp,
				(xdrproc_t)_xdr_yprequest,
				(caddr_t)&req)) {
		svcerr_decode(transp);
		return;
	}

	if (req.yp_reqtype != YPFIRST_REQTYPE) {
		resp.ypfirst_resp_status = (unsigned)YP_BADARGS;
		dbmop_ok = FALSE;
	}

	if (dbmop_ok &&
		((fdb = ypset_current_map(req.ypfirst_req_map,
						req.ypfirst_req_domain,
						&resp.ypfirst_resp_status))
						!= NULL) &&
						yp_map_access(transp,
						&resp.ypfirst_resp_status,
						fdb)) {

		resp.ypfirst_resp_keydat = dbm_firstkey(fdb);

		if (resp.ypfirst_resp_keyptr != NULL) {
			resp.ypfirst_resp_valdat =
				dbm_fetch(fdb, resp.ypfirst_resp_keydat);

			if (resp.ypfirst_resp_valptr != NULL) {
				resp.ypfirst_resp_status = YP_TRUE;
			} else {
				resp.ypfirst_resp_status = (unsigned)YP_BADDB;
			}
		} else {
			resp.ypfirst_resp_status = (unsigned)YP_NOKEY;
		}
	}

	resp.yp_resptype = YPFIRST_RESPTYPE;

	if (!svc_sendreply(transp,
				(xdrproc_t)_xdr_ypresponse,
				(caddr_t)&resp)) {
		RESPOND_ERR;
	}

	if (!svc_freeargs(transp,
				(xdrproc_t)_xdr_yprequest,
				(caddr_t)&req)) {
		FREE_ERR;
	}
}
Ejemplo n.º 17
0
static void
device_core_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		Create_LinkParms create_link_1_arg;
		Device_WriteParms device_write_1_arg;
		Device_ReadParms device_read_1_arg;
		Device_GenericParms device_readstb_1_arg;
		Device_GenericParms device_trigger_1_arg;
		Device_GenericParms device_clear_1_arg;
		Device_GenericParms device_remote_1_arg;
		Device_GenericParms device_local_1_arg;
		Device_LockParms device_lock_1_arg;
		Device_Link device_unlock_1_arg;
		Device_EnableSrqParms device_enable_srq_1_arg;
		Device_DocmdParms device_docmd_1_arg;
		Device_Link destroy_link_1_arg;
		Device_RemoteFunc create_intr_chan_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case create_link:
		_xdr_argument = (xdrproc_t) xdr_Create_LinkParms;
		_xdr_result = (xdrproc_t) xdr_Create_LinkResp;
		local = (char *(*)(char *, struct svc_req *)) create_link_1_svc;
		break;

	case device_write:
		_xdr_argument = (xdrproc_t) xdr_Device_WriteParms;
		_xdr_result = (xdrproc_t) xdr_Device_WriteResp;
		local = (char *(*)(char *, struct svc_req *)) device_write_1_svc;
		break;

	case device_read:
		_xdr_argument = (xdrproc_t) xdr_Device_ReadParms;
		_xdr_result = (xdrproc_t) xdr_Device_ReadResp;
		local = (char *(*)(char *, struct svc_req *)) device_read_1_svc;
		break;

	case device_readstb:
		_xdr_argument = (xdrproc_t) xdr_Device_GenericParms;
		_xdr_result = (xdrproc_t) xdr_Device_ReadStbResp;
		local = (char *(*)(char *, struct svc_req *)) device_readstb_1_svc;
		break;

	case device_trigger:
		_xdr_argument = (xdrproc_t) xdr_Device_GenericParms;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_trigger_1_svc;
		break;

	case device_clear:
		_xdr_argument = (xdrproc_t) xdr_Device_GenericParms;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_clear_1_svc;
		break;

	case device_remote:
		_xdr_argument = (xdrproc_t) xdr_Device_GenericParms;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_remote_1_svc;
		break;

	case device_local:
		_xdr_argument = (xdrproc_t) xdr_Device_GenericParms;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_local_1_svc;
		break;

	case device_lock:
		_xdr_argument = (xdrproc_t) xdr_Device_LockParms;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_lock_1_svc;
		break;

	case device_unlock:
		_xdr_argument = (xdrproc_t) xdr_Device_Link;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_unlock_1_svc;
		break;

	case device_enable_srq:
		_xdr_argument = (xdrproc_t) xdr_Device_EnableSrqParms;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) device_enable_srq_1_svc;
		break;

	case device_docmd:
		_xdr_argument = (xdrproc_t) xdr_Device_DocmdParms;
		_xdr_result = (xdrproc_t) xdr_Device_DocmdResp;
		local = (char *(*)(char *, struct svc_req *)) device_docmd_1_svc;
		break;

	case destroy_link:
		_xdr_argument = (xdrproc_t) xdr_Device_Link;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) destroy_link_1_svc;
		break;

	case create_intr_chan:
		_xdr_argument = (xdrproc_t) xdr_Device_RemoteFunc;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) create_intr_chan_1_svc;
		break;

	case destroy_intr_chan:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_Device_Error;
		local = (char *(*)(char *, struct svc_req *)) destroy_intr_chan_1_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 18
0
/*
 * This determines whether or not a passed domain is served by this
 * server, and returns a boolean.  Used by both old and new protocol
 * versions.
 */
void
ypdomain(SVCXPRT *transp, bool always_respond)
{
	char domain_name[YPMAXDOMAIN + 1];
	char *pdomain_name = domain_name;
	bool isserved;
	char *fun = "ypdomain";
	struct netbuf *nbuf;
	sa_family_t af;

	memset(domain_name, 0, sizeof (domain_name));

	if (!svc_getargs(transp, (xdrproc_t)xdr_ypdomain_wrap_string,
				(caddr_t)&pdomain_name)) {
		svcerr_decode(transp);
		return;
	}

	/*
	 * If the file /var/yp/securenets is present on the server, and if
	 * the hostname is present in the file, then let the client bind to
	 * the server.
	 */
	nbuf = svc_getrpccaller(transp);
	af = ((struct sockaddr_storage *)nbuf->buf)->ss_family;
	if (af != AF_INET && af != AF_INET6) {
		logprintf("Protocol incorrect\n");
		return;
	}

	if (!(check_secure_net_ti(nbuf, fun))) {
		MAP_ERR;
		return;
	}

	isserved = ypcheck_domain(domain_name);

	if (isserved || always_respond) {

		if (!svc_sendreply(transp, xdr_bool, (char *)&isserved)) {
		    RESPOND_ERR;
		}
		if (!isserved)
			logprintf("Domain %s not supported\n",
					domain_name);

	} else {
		/*
		 * This case is the one in which the domain is not
		 * supported, and in which we are not to respond in the
		 * unsupported case.  We are going to make an error happen
		 * to allow the portmapper to end his wait without the
		 * normal timeout period.  The assumption here is that
		 * the only process in the world which is using the function
		 * in its no-answer-if-nack form is the portmapper, which is
		 * doing the krock for pseudo-broadcast.  If some poor fool
		 * calls this function as a single-cast message, the nack
		 * case will look like an incomprehensible error.  Sigh...
		 * (The traditional Unix disclaimer)
		 */

		svcerr_decode(transp);
		logprintf("Domain %s not supported (broadcast)\n",
				domain_name);
	}
}
Ejemplo n.º 19
0
static void
nfs_rpc_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		file_args nfs_create_1_arg;
		file_args nfs_rm_1_arg;
		file_args nfs_cd_1_arg;
		file_args read_1_arg;
		file_write write_1_arg;
		file_args mkdir_1_arg;
		file_args rmdir_1_arg;
	} argument;
	char *result;
	xdrproc_t _xdr_argument, _xdr_result;
	char *(*local)(char *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
		return;

	case nfs_ls:
		_xdr_argument = (xdrproc_t) xdr_void;
		_xdr_result = (xdrproc_t) xdr_buf;
		local = (char *(*)(char *, struct svc_req *)) nfs_ls_1_svc;
		break;

	case nfs_create:
		_xdr_argument = (xdrproc_t) xdr_file_args;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) nfs_create_1_svc;
		break;

	case nfs_rm:
		_xdr_argument = (xdrproc_t) xdr_file_args;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) nfs_rm_1_svc;
		break;

	case nfs_cd:
		_xdr_argument = (xdrproc_t) xdr_file_args;
		_xdr_result = (xdrproc_t) xdr_buf;
		local = (char *(*)(char *, struct svc_req *)) nfs_cd_1_svc;
		break;

	case read:
		_xdr_argument = (xdrproc_t) xdr_file_args;
		_xdr_result = (xdrproc_t) xdr_buf;
		local = (char *(*)(char *, struct svc_req *)) read_1_svc;
		break;

	case write:
		_xdr_argument = (xdrproc_t) xdr_file_write;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) write_1_svc;
		break;

	case mkdir:
		_xdr_argument = (xdrproc_t) xdr_file_args;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) mkdir_1_svc;
		break;

	case rmdir:
		_xdr_argument = (xdrproc_t) xdr_file_args;
		_xdr_result = (xdrproc_t) xdr_int;
		local = (char *(*)(char *, struct svc_req *)) rmdir_1_svc;
		break;

	default:
		svcerr_noproc (transp);
		return;
	}
	memset ((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		svcerr_decode (transp);
		return;
	}
	result = (*local)((char *)&argument, rqstp);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
		svcerr_systemerr (transp);
	}
	if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
		fprintf (stderr, "%s", "unable to free arguments");
		exit (1);
	}
	return;
}
Ejemplo n.º 20
0
/*
 * 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.
 */
void
ypoldpoll(SVCXPRT *transp)
{
	struct yprequest req;
	struct ypresponse resp;
	char *map = "";
	char *domain = "";
	char *owner = "";
	uint_t error;
	char *fun = "ypoldpoll";
	DBM *fdb;

	memset((void *) &req, 0, sizeof (req));
	memset((void *) &resp, 0, sizeof (resp));

	if (!svc_getargs(transp,
				(xdrproc_t)_xdr_yprequest,
				(caddr_t)&req)) {
		svcerr_decode(transp);
		return;
	}

	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 comatibility for 2.0 NIS servers
			 */
			domain = req.yppoll_req_domain;
			map = req.yppoll_req_map;
		} else if ((fdb = ypset_current_map(req.yppoll_req_map,
				req.yppoll_req_domain,
				&error)) != NULL) {
			domain = req.yppoll_req_domain;
			map = req.yppoll_req_map;
			ypget_map_order(map, domain,
					&resp.yppoll_resp_ordernum);
			ypget_map_master(&owner, fdb);
		} else {
			switch ((int)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,
				(xdrproc_t)_xdr_ypresponse,
				(caddr_t)&resp)) {
		RESPOND_ERR;
	}

	if (!svc_freeargs(transp,
				(xdrproc_t)_xdr_yprequest,
				(caddr_t)&req)) {
		FREE_ERR;
	}
}
Ejemplo n.º 21
0
void
nlm_prog_1(struct svc_req *rqstp, SVCXPRT *transp)
{
	union {
		struct nlm_testargs nlm_test_1_arg;
		struct nlm_lockargs nlm_lock_1_arg;
		struct nlm_cancargs nlm_cancel_1_arg;
		struct nlm_unlockargs nlm_unlock_1_arg;
		struct nlm_testargs nlm_granted_1_arg;
		struct nlm_testargs nlm_test_msg_1_arg;
		struct nlm_lockargs nlm_lock_msg_1_arg;
		struct nlm_cancargs nlm_cancel_msg_1_arg;
		struct nlm_unlockargs nlm_unlock_msg_1_arg;
		struct nlm_testargs nlm_granted_msg_1_arg;
		nlm_testres nlm_test_res_1_arg;
		nlm_res nlm_lock_res_1_arg;
		nlm_res nlm_cancel_res_1_arg;
		nlm_res nlm_unlock_res_1_arg;
		nlm_res nlm_granted_res_1_arg;
	} argument;
	union {
		nlm_testres nlm_test_1_res;
		nlm_res nlm_lock_1_res;
		nlm_res nlm_cancel_1_res;
		nlm_res nlm_unlock_1_res;
		nlm_res nlm_granted_1_res;
	} result;
	bool_t retval;
	xdrproc_t xdr_argument, xdr_result;
	bool_t (*local)(char *, void *, struct svc_req *);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void) svc_sendreply(rqstp,
			(xdrproc_t) xdr_void, (char *)NULL);
		svc_freereq(rqstp);
		return;

	case NLM_TEST:
		xdr_argument = (xdrproc_t) xdr_nlm_testargs;
		xdr_result = (xdrproc_t) xdr_nlm_testres;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_test_1_svc;
		break;

	case NLM_LOCK:
		xdr_argument = (xdrproc_t) xdr_nlm_lockargs;
		xdr_result = (xdrproc_t) xdr_nlm_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_lock_1_svc;
		break;

	case NLM_CANCEL:
		xdr_argument = (xdrproc_t) xdr_nlm_cancargs;
		xdr_result = (xdrproc_t) xdr_nlm_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_cancel_1_svc;
		break;

	case NLM_UNLOCK:
		xdr_argument = (xdrproc_t) xdr_nlm_unlockargs;
		xdr_result = (xdrproc_t) xdr_nlm_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_unlock_1_svc;
		break;

	case NLM_GRANTED:
		xdr_argument = (xdrproc_t) xdr_nlm_testargs;
		xdr_result = (xdrproc_t) xdr_nlm_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_granted_1_svc;
		break;

	case NLM_TEST_MSG:
		xdr_argument = (xdrproc_t) xdr_nlm_testargs;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_test_msg_1_svc;
		break;

	case NLM_LOCK_MSG:
		xdr_argument = (xdrproc_t) xdr_nlm_lockargs;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_lock_msg_1_svc;
		break;

	case NLM_CANCEL_MSG:
		xdr_argument = (xdrproc_t) xdr_nlm_cancargs;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_cancel_msg_1_svc;
		break;

	case NLM_UNLOCK_MSG:
		xdr_argument = (xdrproc_t) xdr_nlm_unlockargs;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_unlock_msg_1_svc;
		break;

	case NLM_GRANTED_MSG:
		xdr_argument = (xdrproc_t) xdr_nlm_testargs;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_granted_msg_1_svc;
		break;

	case NLM_TEST_RES:
		xdr_argument = (xdrproc_t) xdr_nlm_testres;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_test_res_1_svc;
		break;

	case NLM_LOCK_RES:
		xdr_argument = (xdrproc_t) xdr_nlm_res;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_lock_res_1_svc;
		break;

	case NLM_CANCEL_RES:
		xdr_argument = (xdrproc_t) xdr_nlm_res;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_cancel_res_1_svc;
		break;

	case NLM_UNLOCK_RES:
		xdr_argument = (xdrproc_t) xdr_nlm_res;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_unlock_res_1_svc;
		break;

	case NLM_GRANTED_RES:
		xdr_argument = (xdrproc_t) xdr_nlm_res;
		xdr_result = (xdrproc_t) xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))nlm_granted_res_1_svc;
		break;

	default:
		svcerr_noproc(rqstp);
		svc_freereq(rqstp);
		return;
	}
	(void) memset((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
		svcerr_decode(rqstp);
		svc_freereq(rqstp);
		return;
	}
	retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
	if (retval > 0 && !svc_sendreply(rqstp, xdr_result, (char *)&result)) {
		svcerr_systemerr(rqstp);
	}
	if (!svc_freeargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
		printf("unable to free arguments");
		//exit(1);
	}
	svc_freereq(rqstp);
	if (!nlm_prog_1_freeresult(transp, xdr_result, (caddr_t) &result))
		printf("unable to free results");

	return;
}
Ejemplo n.º 22
0
/*
 * This implements the yp "match" function.
 */
void
ypmatch(SVCXPRT *transp, struct svc_req *rqstp)
{
	struct ypreq_key req;
	struct ypresp_val resp;
	char *fun = "ypmatch";
	DBM *fdb;

	memset(&req, 0, sizeof (req));
	memset(&resp, 0, sizeof (resp));
	resp.status = (unsigned)YP_NOKEY;

	if (!svc_getargs(transp, (xdrproc_t)xdr_ypreq_key, (char *)&req)) {
		svcerr_decode(transp);
		return;
	}

	/*
	 * sanity check the map name and to a DBM lookup
	 * also perform an access check...
	 */
	if ((fdb = ypset_current_map(req.map, req.domain,
					&resp.status)) != NULL &&
		yp_map_access(transp, &resp.status, fdb)) {

		/* Check with the DBM database */
		resp.valdat = dbm_fetch(fdb, req.keydat);
		if (resp.valdat.dptr != NULL) {
			resp.status = YP_TRUE;
			if (!silent)
				printf("%s: dbm: %40.40s\n",
					fun, resp.valdat.dptr);
			goto send_reply;
		}

		/*
		 * If we're being asked to match YP_SECURE or YP_INTERDOMAIN
		 * and we haven't found it in the dbm file, then we don't
		 * really want to waste any more time.  Specifically, we don't
		 * want to ask DNS
		 */
		if (req.keydat.dsize == 0 ||
		    req.keydat.dptr == NULL ||
		    req.keydat.dptr[0] == '\0' ||
	strncmp(req.keydat.dptr, yp_secure, req.keydat.dsize) == 0 ||
	strncmp(req.keydat.dptr, yp_interdomain, req.keydat.dsize) == 0) {
			goto send_reply;
		}

		/* Let's try the YP_MULTI_ hack... */
#ifdef MINUS_C_OPTION
		if (multiflag == TRUE && multihomed(req, &resp, transp, fdb))
			goto send_reply;
#else
		if (multihomed(req, &resp, transp, fdb))
			goto send_reply;
#endif

		/*
		 * Let's try DNS, but if client_setup_failure is set,
		 * we have tried DNS in the past and failed, there is
		 * no reason in forcing an infinite loop by turning
		 * off DNS in setup_resolv() only to turn it back on
		 * again here.
		 */
		if (!dnsforward && !client_setup_failure) {
			datum idkey, idval;
			idkey.dptr = yp_interdomain;
			idkey.dsize = yp_interdomain_sz;
			idval = dbm_fetch(fdb, idkey);
			if (idval.dptr)
				dnsforward = TRUE;
		}

		if (dnsforward) {
			if (!resolv_pid || !resolv_client) {
				setup_resolv(&dnsforward, &resolv_pid,
						&resolv_client, resolv_tp, 0);
				if (resolv_client == NULL)
					client_setup_failure = TRUE;
			}

			if (resolv_req(&dnsforward, &resolv_client,
						&resolv_pid, resolv_tp,
						rqstp->rq_xprt, &req,
						req.map) == TRUE)
				goto free_args;
		}
	}
	send_reply:

	if (!svc_sendreply(transp, (xdrproc_t)xdr_ypresp_val,
				(caddr_t)&resp)) {
		RESPOND_ERR;
	}

	free_args:

	if (!svc_freeargs(transp, (xdrproc_t)xdr_ypreq_key,
				(char *)&req)) {
		FREE_ERR;
	}
}
Ejemplo n.º 23
0
/*
 * The mount rpc service
 */
void
mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
{
	char rpcpath[RPCMNT_PATHLEN+1], dirpath[MAXPATHLEN];
	struct hostent *hp = NULL;
	struct exportlist *ep;
	sigset_t sighup_mask;
	int defset, hostset;
	struct fhreturn fhr;
	struct dirlist *dp;
	struct statfs fsb;
	struct stat stb;
	in_addr_t saddr;
	u_short sport;
	long bad = 0;

	sigemptyset(&sighup_mask);
	sigaddset(&sighup_mask, SIGHUP);
	saddr = transp->xp_raddr.sin_addr.s_addr;
	sport = ntohs(transp->xp_raddr.sin_port);
	switch (rqstp->rq_proc) {
	case NULLPROC:
		if (!svc_sendreply(transp, xdr_void, NULL))
			syslog(LOG_ERR, "Can't send reply");
		return;
	case RPCMNT_MOUNT:
		if (debug)
			fprintf(stderr, "Got mount request from %s\n",
			    inet_ntoa(transp->xp_raddr.sin_addr));
		if (sport >= IPPORT_RESERVED && resvport_only) {
			syslog(LOG_NOTICE,
			    "Refused mount RPC from host %s port %d",
			    inet_ntoa(transp->xp_raddr.sin_addr), sport);
			svcerr_weakauth(transp);
			return;
		}
		if (!svc_getargs(transp, xdr_dir, rpcpath)) {
			svcerr_decode(transp);
			return;
		}
		if (debug)
			fprintf(stderr, "rpcpath: %s\n", rpcpath);

		/*
		 * Get the real pathname and make sure it is a file or
		 * directory that exists.
		 */
		if (realpath(rpcpath, dirpath) == NULL) {
			bad = errno;
			if (debug)
				fprintf(stderr, "realpath failed on %s\n",
				    rpcpath);
			strlcpy(dirpath, rpcpath, sizeof(dirpath));
		} else if (stat(dirpath, &stb) < 0 ||
		    (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) ||
		    statfs(dirpath, &fsb) < 0) {
			if (debug)
				fprintf(stderr, "stat failed on %s\n", dirpath);
			bad = ENOENT;	/* We will send error reply later */
		}

		/* Check in the exports list */
		sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
		ep = ex_search(&fsb.f_fsid);
		hostset = defset = 0;
		if (ep && (chk_host(ep->ex_defdir, saddr, &defset, &hostset) ||
		    ((dp = dirp_search(ep->ex_dirl, dirpath)) &&
		    chk_host(dp, saddr, &defset, &hostset)) ||
		    (defset && scan_tree(ep->ex_defdir, saddr) == 0 &&
		    scan_tree(ep->ex_dirl, saddr) == 0))) {
			if (bad) {
				if (!svc_sendreply(transp, xdr_long,
				    (caddr_t)&bad))
					syslog(LOG_ERR, "Can't send reply");
				sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
				return;
			}
			if (hostset & DP_HOSTSET)
				fhr.fhr_flag = hostset;
			else
				fhr.fhr_flag = defset;
			fhr.fhr_vers = rqstp->rq_vers;
			/* Get the file handle */
			memset(&fhr.fhr_fh, 0, sizeof(nfsfh_t));
			if (getfh(dirpath, (fhandle_t *)&fhr.fhr_fh) < 0) {
				if (errno == ENOSYS) {
					syslog(LOG_ERR,
					    "Kernel does not support NFS exporting, "
					    "mountd aborting..");
					_exit(1);
				}
				bad = errno;
				syslog(LOG_ERR, "Can't get fh for %s", dirpath);
				if (!svc_sendreply(transp, xdr_long,
				    (caddr_t)&bad))
					syslog(LOG_ERR, "Can't send reply");
				sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
				return;
			}
			if (!svc_sendreply(transp, xdr_fhs, (caddr_t)&fhr))
				syslog(LOG_ERR, "Can't send reply");
			if (hp == NULL)
				hp = gethostbyaddr((caddr_t)&saddr,
				    sizeof(saddr), AF_INET);
			if (hp)
				add_mlist(hp->h_name, dirpath);
			else
				add_mlist(inet_ntoa(transp->xp_raddr.sin_addr),
					dirpath);
			if (debug) {
				fprintf(stderr,
				    "Mount successful for %s by %s.\n",
				    dirpath,
				    inet_ntoa(transp->xp_raddr.sin_addr));
			}
		} else
			bad = EACCES;

		if (bad && !svc_sendreply(transp, xdr_long, (caddr_t)&bad))
			syslog(LOG_ERR, "Can't send reply");
		sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
		return;
	case RPCMNT_DUMP:
		if (!svc_sendreply(transp, xdr_mlist, NULL))
			syslog(LOG_ERR, "Can't send reply");
		return;
	case RPCMNT_UMOUNT:
		if (sport >= IPPORT_RESERVED && resvport_only) {
			svcerr_weakauth(transp);
			return;
		}
		if (!svc_getargs(transp, xdr_dir, dirpath)) {
			svcerr_decode(transp);
			return;
		}
		if (!svc_sendreply(transp, xdr_void, NULL))
			syslog(LOG_ERR, "Can't send reply");
		hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET);
		if (hp)
			del_mlist(hp->h_name, dirpath);
		del_mlist(inet_ntoa(transp->xp_raddr.sin_addr), dirpath);
		return;
	case RPCMNT_UMNTALL:
		if (sport >= IPPORT_RESERVED && resvport_only) {
			svcerr_weakauth(transp);
			return;
		}
		if (!svc_sendreply(transp, xdr_void, NULL))
			syslog(LOG_ERR, "Can't send reply");
		hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET);
		if (hp)
			del_mlist(hp->h_name, NULL);
		del_mlist(inet_ntoa(transp->xp_raddr.sin_addr), NULL);
		return;
	case RPCMNT_EXPORT:
		if (!svc_sendreply(transp, xdr_explist, NULL))
			syslog(LOG_ERR, "Can't send reply");
		return;
	default:
		svcerr_noproc(transp);
		return;
	}
}
Ejemplo n.º 24
0
/*
 * This implements the "transfer map" function.  It takes the domain
 * and map names and the callback information provided by the
 * requester (yppush on some node), and execs a ypxfr process to do
 * the actual transfer.
 */
void
ypxfr(SVCXPRT *transp, int prog)
{
	struct ypreq_newxfr newreq;
	struct ypreq_xfr oldreq;
	struct ypresp_val resp;  /* not returned to the caller */
	char transid[32];
	char proto[32];
	char name[256];
	char *pdomain, *pmap;
	pid_t pid = -1;
	char *fun = "ypxfr";
	DBM *fdb;

	if (prog == YPPROC_NEWXFR) {
		memset(&newreq, 0, sizeof (newreq));
		if (!svc_getargs(transp, (xdrproc_t)xdr_ypreq_newxfr,
				(char *)&newreq)) {
			svcerr_decode(transp);
			return;
		}

#ifdef OPCOM_DEBUG
		fprintf(stderr, "newreq:\n"
			"\tmap_parms:\n"
			"\t\tdomain:    %s\n"
			"\t\tmap:       %s\n"
			"\t\tordernum:  %u\n"
			"\t\towner:     %s\n"
			"\ttransid:    %u\n"
			"\tproto:      %u\n"
			"\tname:       %s\n\n",
			newreq.map_parms.domain,
			newreq.map_parms.map,
			newreq.map_parms.ordernum,
			newreq.map_parms.owner,
			newreq.transid,
			newreq.proto,
			newreq.name);
#endif
		sprintf(transid, "%u", newreq.transid);
		sprintf(proto, "%u", newreq.proto);
		sprintf(name, "%s", newreq.ypxfr_owner);
		pdomain = newreq.ypxfr_domain;
		pmap = newreq.ypxfr_map;
	} else if (prog == YPPROC_XFR) {
		memset(&oldreq, 0, sizeof (oldreq));
		if (!svc_getargs(transp,
					(xdrproc_t)xdr_ypreq_xfr,
					(char *)&oldreq)) {
		    svcerr_decode(transp);
		    return;
		}

#ifdef OPCOM_DEBUG
		fprintf(stderr, "oldreq:\n"
			"\tmap_parms:\n"
			"\t\tdomain:    %s\n"
			"\t\tmap:       %s\n"
			"\t\tordernum:  %u\n"
			"\t\towner:     %s\n"
			"\ttransid:    %u\n"
			"\tproto:      %u\n"
			"\tport:       %u\n\n",
			oldreq.map_parms.domain,
			oldreq.map_parms.map,
			oldreq.map_parms.ordernum,
			oldreq.map_parms.owner,
			oldreq.transid,
			oldreq.proto,
			oldreq.port);
#endif

		sprintf(transid, "%u", oldreq.transid);
		sprintf(proto, "%u", oldreq.proto);
		sprintf(name, "%s", oldreq.ypxfr_owner);
		pdomain = oldreq.ypxfr_domain;
		pmap = oldreq.ypxfr_map;
	} else {
		VERS_ERR;
	}

	/* Check that the map exists and is accessible */
	if ((fdb = ypset_current_map(pmap, pdomain, &resp.status)) != NULL &&
		yp_map_access(transp, &resp.status, fdb)) {

		pid = vfork();
		if (pid == -1) {
			FORK_ERR;
		} else if (pid == 0) {
		    if (prog == YPPROC_NEWXFR || prog == YPPROC_XFR) {
#ifdef OPCOM_DEBUG
			fprintf(stderr,
				"EXECL: %s, -d, %s, -C, %s, %s, %s, %s\n",
				ypxfr_proc, pdomain,
				transid, proto, name, pmap);
#endif
			if (execl(ypxfr_proc, "ypxfr", "-d",
					pdomain, "-C", transid, proto,
					name, pmap, NULL))
			    EXEC_ERR;
		    } else {
			VERS_ERR;
		    }
		    _exit(1);
		}

	} else {
		MAP_ERR;
	}
	if (!svc_sendreply(transp, xdr_void, 0)) {
		RESPOND_ERR;
	}

	if (prog == YPPROC_NEWXFR) {
		if (!svc_freeargs(transp,
					(xdrproc_t)xdr_ypreq_newxfr,
					(char *)&newreq)) {
		    FREE_ERR;
		}
	}
}
Ejemplo n.º 25
0
void
idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
		idmap_update_batch idmap_update_1_arg;
		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
		idmap_prop_type idmap_get_prop_1_arg;
		directory_get_common_1_argument directory_get_common_1_arg;
		idmap_flush_op idmap_flush_1_arg;
	} argument;
	union {
		idmap_ids_res idmap_get_mapped_ids_1_res;
		idmap_mappings_res idmap_list_mappings_1_res;
		idmap_namerules_res idmap_list_namerules_1_res;
		idmap_update_res idmap_update_1_res;
		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
		idmap_prop_res idmap_get_prop_1_res;
		directory_results_rpc directory_get_common_1_res;
		idmap_retcode idmap_flush_1_res;
	} result;
	bool_t retval;
	xdrproc_t _xdr_argument, _xdr_result;
	bool_t (*local)(char *, void *, struct svc_req *);

	(void) mutex_lock(&_svcstate_lock);
	_rpcsvccount++;
	(void) mutex_unlock(&_svcstate_lock);
	switch (rqstp->rq_proc) {
	case IDMAP_NULL:
		_xdr_argument = (xdrproc_t)
		    xdr_void;
		_xdr_result = (xdrproc_t)
		    xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_null_1;
		break;

	case IDMAP_GET_MAPPED_IDS:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_mapping_batch;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_ids_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_get_mapped_ids_1;
		break;

	case IDMAP_LIST_MAPPINGS:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_list_mappings_1_argument;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_mappings_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_list_mappings_1;
		break;

	case IDMAP_LIST_NAMERULES:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_list_namerules_1_argument;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_namerules_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_list_namerules_1;
		break;

	case IDMAP_UPDATE:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_update_batch;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_update_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_update_1;
		break;

	case IDMAP_GET_MAPPED_ID_BY_NAME:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_mapping;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_mappings_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_get_mapped_id_by_name_1;
		break;

	case IDMAP_GET_PROP:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_prop_type;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_prop_res;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_get_prop_1;
		break;

	case DIRECTORY_GET_COMMON:
		_xdr_argument = (xdrproc_t)
		    xdr_directory_get_common_1_argument;
		_xdr_result = (xdrproc_t)
		    xdr_directory_results_rpc;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _directory_get_common_1;
		break;

	case IDMAP_FLUSH:
		_xdr_argument = (xdrproc_t)
		    xdr_idmap_flush_op;
		_xdr_result = (xdrproc_t)
		    xdr_idmap_retcode;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _idmap_flush_1;
		break;

	default:
		svcerr_noproc(transp);
		(void) mutex_lock(&_svcstate_lock);
		_rpcsvccount--;
		_rpcsvcstate = _SERVED;
		(void) mutex_unlock(&_svcstate_lock);
		return; /* CSTYLED */
	}
	(void) memset((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
		svcerr_decode(transp);
		(void) mutex_lock(&_svcstate_lock);
		_rpcsvccount--;
		_rpcsvcstate = _SERVED;
		(void) mutex_unlock(&_svcstate_lock);
		return; /* CSTYLED */
	}
	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
	if (_xdr_result && retval > 0 &&
	    !svc_sendreply(transp, _xdr_result, (char *)&result)) {
		svcerr_systemerr(transp);
	}
	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
		RPC_MSGOUT("%s",
		    "unable to free arguments");
		exit(1);
	}
	if (_xdr_result != NULL) {
		if (!idmap_prog_1_freeresult(transp, _xdr_result,
		    (caddr_t)&result))
			RPC_MSGOUT("%s",
			    "unable to free results");

	}
	(void) mutex_lock(&_svcstate_lock);
	_rpcsvccount--;
	_rpcsvcstate = _SERVED;
	(void) mutex_unlock(&_svcstate_lock);
	return; /* CSTYLED */
}
Ejemplo n.º 26
0
/*
 * This implements the "get all" function.
 */
void
ypall(SVCXPRT *transp)
{
	struct ypreq_nokey req;
	struct ypresp_val resp;  /* not returned to the caller */
	pid_t pid;
	char *fun = "ypall";
	DBM *fdb;

	req.domain = req.map = NULL;

	memset((char *)&req, 0, sizeof (req));

	if (!svc_getargs(transp,
				(xdrproc_t)xdr_ypreq_nokey,
				(char *)&req)) {
		svcerr_decode(transp);
		return;
	}

	pid = fork1();

	if (pid) {

		if (pid == -1) {
			FORK_ERR;
		}

		if (!svc_freeargs(transp,
					(xdrproc_t)xdr_ypreq_nokey,
					(char *)&req)) {
			FREE_ERR;
		}

		return;
	}

	/*
	 * access control hack:  If denied then invalidate the map name.
	 */
	ypclr_current_map();
	if ((fdb = ypset_current_map(req.map,
		req.domain, &resp.status)) != NULL &&
		!yp_map_access(transp, &resp.status, fdb)) {

		req.map[0] = '-';
	}

	/*
	 * This is the child process.  The work gets done by xdrypserv_ypall/
	 * we must clear the "current map" first so that we do not
	 * share a seek pointer with the parent server.
	 */

	if (!svc_sendreply(transp,
				(xdrproc_t)xdrypserv_ypall,
				(char *)&req)) {
		RESPOND_ERR;
	}

	if (!svc_freeargs(transp,
				(xdrproc_t)xdr_ypreq_nokey,
				(char *)&req)) {
		FREE_ERR;
	}

	/*
	 * In yptol mode we may start a cache update thread within a child
	 * process. It is thus important that child processes do not exit,
	 * killing any such threads, before the thread has completed.
	 */
	if (yptol_mode) {
		thr_join(0, NULL, NULL);
	}

	exit(0);
}
Ejemplo n.º 27
0
void
rusers_service(struct svc_req *rqstp, SVCXPRT *transp)
{
	union {
		int fill;
	} argument;
	char *result;
	bool_t (*xdr_argument)(), (*xdr_result)();
	char *(*local)();

	switch (rqstp->rq_proc) {
	case NULLPROC:
		(void)svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
		goto leave;

	case RUSERSPROC_NUM:
		xdr_argument = xdr_void;
		xdr_result = xdr_int;
                local = (char *(*)()) rusers_num;
		break;

	case RUSERSPROC_NAMES:
		xdr_argument = xdr_void;
		xdr_result = xdr_utmpidlearr;
                switch (rqstp->rq_vers) {
                case RUSERSVERS_ORIG:
                        local = (char *(*)()) rusersproc_names_1_svc;
                        break;
                case RUSERSVERS_IDLE:
                        local = (char *(*)()) rusersproc_names_2_svc;
                        break;
                default:
                        svcerr_progvers(transp, RUSERSVERS_ORIG, RUSERSVERS_IDLE);
                        goto leave;
                        /*NOTREACHED*/
                }
		break;

	case RUSERSPROC_ALLNAMES:
		xdr_argument = xdr_void;
		xdr_result = xdr_utmpidlearr;
                switch (rqstp->rq_vers) {
                case RUSERSVERS_ORIG:
                        local = (char *(*)()) rusersproc_allnames_1_svc;
                        break;
                case RUSERSVERS_IDLE:
                        local = (char *(*)()) rusersproc_allnames_2_svc;
                        break;
                default:
                        svcerr_progvers(transp, RUSERSVERS_ORIG, RUSERSVERS_IDLE);
                        goto leave;
                        /*NOTREACHED*/
                }
		break;

	default:
		svcerr_noproc(transp);
		goto leave;
	}
	bzero((char *)&argument, sizeof(argument));
	if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (caddr_t)&argument)) {
		svcerr_decode(transp);
		goto leave;
	}
	result = (*local)(&argument, rqstp);
	if (result != NULL &&
	    !svc_sendreply(transp, (xdrproc_t)xdr_result, result)) {
		svcerr_systemerr(transp);
	}
	if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (caddr_t)&argument)) {
		syslog(LOG_ERR, "unable to free arguments");
		exit(1);
	}
leave:
        if (from_inetd)
                exit(0);
}
Ejemplo n.º 28
0
/* V1 dispatch routines */
void
ypoldmatch(SVCXPRT *transp, struct svc_req *rqstp)
{
	bool dbmop_ok = TRUE;
	struct yprequest req;
	struct ypreq_key nrq;
	struct ypresponse resp;
	char *fun = "ypoldmatch";
	DBM *fdb;

	memset((void *) &req, 0, sizeof (req));
	memset((void *) &resp, 0, sizeof (resp));

	if (!svc_getargs(transp,
				(xdrproc_t)_xdr_yprequest,
				(caddr_t)&req)) {
		svcerr_decode(transp);
		return;
	}

	if (req.yp_reqtype != YPMATCH_REQTYPE) {
		resp.ypmatch_resp_status = (unsigned)YP_BADARGS;
		dbmop_ok = FALSE;
	}

	if (dbmop_ok &&
		(((fdb = ypset_current_map(req.ypmatch_req_map,
						req.ypmatch_req_domain,
						&resp.ypmatch_resp_status))
						!= NULL) &&
						yp_map_access(transp,
						&resp.ypmatch_resp_status,
						fdb))) {

		/* Check with the DBM database */
		resp.ypmatch_resp_valdat = dbm_fetch(fdb,
						req.ypmatch_req_keydat);

		if (resp.ypmatch_resp_valptr != NULL) {
			resp.ypmatch_resp_status = YP_TRUE;
			if (!silent)
				printf("%s: dbm: %s\n",
					fun, resp.ypmatch_resp_valptr);
			goto send_oldreply;
		}

		/*
		 * If we're being asked to match YP_SECURE or YP_INTERDOMAIN
		 * and we haven't found it in the dbm file, then we don't
		 * really want to waste any more time.  Specifically, we don't
		 * want to ask DNS
		 */
		if (req.ypmatch_req_keysize == 0 ||
		    req.ypmatch_req_keyptr == NULL ||
		    req.ypmatch_req_keyptr[0] == '\0' ||
		    strncmp(req.ypmatch_req_keyptr, "YP_SECURE", 9) == 0 ||
		    strncmp(req.ypmatch_req_keyptr, "YP_INTERDOMAIN", 14) == 0)

		    goto send_oldreply;

		/* Let's try the YP_MULTI_ hack... */
#ifdef MINUS_C_OPTION
		if (multiflag == TRUE && omultihomed(req, &resp, transp, fdb))
			goto send_oldreply;
#else
		if (omultihomed(req, &resp, transp, fdb))
			goto send_oldreply;
#endif

		/* Let's try DNS */
		if (!dnsforward) {
			USE_YP_INTERDOMAIN
			datum idkey, idval;
			idkey.dptr = yp_interdomain;
			idkey.dsize = yp_interdomain_sz;
			idval = dbm_fetch(fdb, idkey);
			if (idval.dptr)
				dnsforward = TRUE;
		}

		if (dnsforward) {
		    if (!resolv_pid)
			setup_resolv(&dnsforward, &resolv_pid, &resolv_client,
					resolv_tp, 0);

		    if (req.yp_reqtype == YPREQ_KEY) {
			nrq = req.yp_reqbody.yp_req_keytype;

			resolv_req(&dnsforward, &resolv_client, &resolv_pid,
					resolv_tp, rqstp->rq_xprt,
					&nrq, nrq.map);
		    }
		    return;
		}
	}

	send_oldreply:

	if (!svc_sendreply(transp,
				(xdrproc_t)_xdr_ypresponse,
				(caddr_t)&resp)) {
		RESPOND_ERR;
	}

	if (!svc_freeargs(transp,
				(xdrproc_t)_xdr_yprequest,
				(char *)&req)) {
		FREE_ERR;
	}
}
Ejemplo n.º 29
0
/*
 * Called by svc_getreqset. There is a separate server handle for
 * every transport that it waits on.
 */
void
rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
{
	union {
		rpcb rpcbproc_set_4_arg;
		rpcb rpcbproc_unset_4_arg;
		rpcb rpcbproc_getaddr_4_local_arg;
		char *rpcbproc_uaddr2taddr_4_arg;
		struct netbuf rpcbproc_taddr2uaddr_4_arg;
	} argument;
	char *result;
	xdrproc_t xdr_argument, xdr_result;
	void *(*local) __P((void *, struct svc_req *, SVCXPRT *, rpcvers_t));
	rpcprog_t setprog = 0;

	rpcbs_procinfo(RPCBVERS_4_STAT, rqstp->rq_proc);

	switch (rqstp->rq_proc) {
	case NULLPROC:
		/*
		 * Null proc call
		 */
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_NULL\n");
#endif
		check_access(transp, rqstp->rq_proc, 0, RPCBVERS4);
		(void) svc_sendreply(transp, (xdrproc_t) xdr_void,
					(char *)NULL);
		return;

	case RPCBPROC_SET:
		/*
		 * Check to see whether the message came from
		 * loopback transports (for security reasons)
		 */
		xdr_argument = (xdrproc_t)xdr_rpcb;
		xdr_result = (xdrproc_t)xdr_bool;
		local = rpcbproc_set_com;
		break;

	case RPCBPROC_UNSET:
		/*
		 * Check to see whether the message came from
		 * loopback transports (for security reasons)
		 */
		xdr_argument = (xdrproc_t)xdr_rpcb;
		xdr_result = (xdrproc_t)xdr_bool;
		local = rpcbproc_unset_com;
		break;

	case RPCBPROC_GETADDR:
		xdr_argument = (xdrproc_t)xdr_rpcb;
		xdr_result = (xdrproc_t)xdr_wrapstring;
		local = rpcbproc_getaddr_4_local;
		break;

	case RPCBPROC_GETVERSADDR:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_GETVERSADDR\n");
#endif
		xdr_argument = (xdrproc_t)xdr_rpcb;
		xdr_result = (xdrproc_t)xdr_wrapstring;
		local = rpcbproc_getversaddr_4_local;
		break;

	case RPCBPROC_DUMP:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_DUMP\n");
#endif
		xdr_argument = (xdrproc_t)xdr_void;
		xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
		local = rpcbproc_dump_4_local;
		break;

	case RPCBPROC_INDIRECT:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_INDIRECT\n");
#endif
		rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
		return;

/*	case RPCBPROC_CALLIT: */
	case RPCBPROC_BCAST:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_BCAST\n");
#endif
		rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
		return;

	case RPCBPROC_GETTIME:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_GETTIME\n");
#endif
		xdr_argument = (xdrproc_t)xdr_void;
		xdr_result = (xdrproc_t)xdr_u_long;
		local = rpcbproc_gettime_com;
		break;

	case RPCBPROC_UADDR2TADDR:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
#endif
		xdr_argument = (xdrproc_t)xdr_wrapstring;
		xdr_result = (xdrproc_t)xdr_netbuf;
		local = rpcbproc_uaddr2taddr_com;
		break;

	case RPCBPROC_TADDR2UADDR:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
#endif
		xdr_argument = (xdrproc_t)xdr_netbuf;
		xdr_result = (xdrproc_t)xdr_wrapstring;
		local = rpcbproc_taddr2uaddr_com;
		break;

	case RPCBPROC_GETADDRLIST:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_GETADDRLIST\n");
#endif
		xdr_argument = (xdrproc_t)xdr_rpcb;
		xdr_result = (xdrproc_t)xdr_rpcb_entry_list_ptr;
		local = rpcbproc_getaddrlist_4_local;
		break;

	case RPCBPROC_GETSTAT:
#ifdef RPCBIND_DEBUG
		if (debugging)
			fprintf(stderr, "RPCBPROC_GETSTAT\n");
#endif
		xdr_argument = (xdrproc_t)xdr_void;
		xdr_result = (xdrproc_t)xdr_rpcb_stat_byvers;
		local = rpcbproc_getstat;
		break;

	default:
		svcerr_noproc(transp);
		return;
	}
	memset((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
		(char *)&argument)) {
		svcerr_decode(transp);
		if (debugging)
			(void) fprintf(stderr, "rpcbind: could not decode\n");
		return;
	}

	if (rqstp->rq_proc == RPCBPROC_SET
	 || rqstp->rq_proc == RPCBPROC_UNSET
	 || rqstp->rq_proc == RPCBPROC_GETADDR)
		setprog = argument.rpcbproc_set_4_arg.r_prog;

	if (!check_access(transp, rqstp->rq_proc, setprog, RPCBVERS4)) {
		svcerr_weakauth(transp);
		goto done;
	}
	result = (*local)(&argument, rqstp, transp, RPCBVERS4);
	if (result != NULL && !svc_sendreply(transp, (xdrproc_t) xdr_result,
						result)) {
		svcerr_systemerr(transp);
		if (debugging) {
			(void) fprintf(stderr, "rpcbind: svc_sendreply\n");
			if (doabort) {
				rpcbind_abort();
			}
		}
	}
done:
	if (!svc_freeargs(transp, (xdrproc_t) xdr_argument,
				(char *)&argument)) {
		if (debugging) {
			(void) fprintf(stderr, "unable to free arguments\n");
			if (doabort) {
				rpcbind_abort();
			}
		}
	}
	return;
}
Ejemplo n.º 30
0
enum auth_stat gssrpc__svcauth_gssapi(
     register struct svc_req *rqst,
     register struct rpc_msg *msg,
     bool_t *no_dispatch)
{
     XDR xdrs;
     auth_gssapi_creds creds;
     auth_gssapi_init_arg call_arg;
     auth_gssapi_init_res call_res;
     gss_buffer_desc output_token, in_buf, out_buf;
     gss_cred_id_t server_creds;
     struct gss_channel_bindings_struct bindings, *bindp;
     OM_uint32 gssstat, minor_stat, time_rec;
     struct opaque_auth *cred, *verf;
     svc_auth_gssapi_data *client_data;
     int i;
     enum auth_stat ret;
     OM_uint32 ret_flags;
     uint32_t seq_num;

     PRINTF(("svcauth_gssapi: starting\n"));
     
     /* clean up expired entries */
     clean_client();

     /* use AUTH_NONE until there is a client_handle */
     rqst->rq_xprt->xp_auth = &svc_auth_none;
     
     memset((char *) &call_res, 0, sizeof(call_res));
     creds.client_handle.length = 0;
     creds.client_handle.value = NULL;
     
     cred = &msg->rm_call.cb_cred;
     verf = &msg->rm_call.cb_verf;
     
     if (cred->oa_length == 0) {
	  PRINTF(("svcauth_gssapi: empty creds, failing\n"));
	  LOG_MISCERR("empty client credentials");
	  ret = AUTH_BADCRED;
	  goto error;
     }

     PRINTF(("svcauth_gssapi: decoding credentials\n"));
     xdrmem_create(&xdrs, cred->oa_base, cred->oa_length, XDR_DECODE); 
     memset((char *) &creds, 0, sizeof(creds));
     if (! xdr_authgssapi_creds(&xdrs, &creds)) {
	  PRINTF(("svcauth_gssapi: failed decoding creds\n"));
	  LOG_MISCERR("protocol error in client credentials");
	  xdr_free(xdr_authgssapi_creds, &creds);
	  XDR_DESTROY(&xdrs);
	  ret = AUTH_BADCRED;
	  goto error;
     }
     XDR_DESTROY(&xdrs);

     PRINTF(("svcauth_gssapi: got credentials, version %d, client_handle len %d\n",
	     creds.version, (int) creds.client_handle.length));

     if (creds.version != 2) {
 	  PRINTF(("svcauth_gssapi: bad credential version\n"));
 	  LOG_MISCERR("unsupported client credentials version");
 	  ret = AUTH_BADCRED;
 	  goto error;
     }

#ifdef DEBUG_GSSAPI
     if (svc_debug_gssapi) {
	  if (creds.auth_msg && rqst->rq_proc == AUTH_GSSAPI_EXIT) {
	       PRINTF(("svcauth_gssapi: GSSAPI_EXIT, cleaning up\n"));
	       svc_sendreply(rqst->rq_xprt, xdr_void, NULL);
	       xdr_free(xdr_authgssapi_creds, &creds);
	       cleanup();
	       exit(0);
	  }
     }
#endif
	  
     /*
      * If this is an auth_msg and proc is GSSAPI_INIT, then create a
      * client handle for this client.  Otherwise, look up the
      * existing handle.
      */
     if (creds.auth_msg && rqst->rq_proc == AUTH_GSSAPI_INIT) {
	  if (creds.client_handle.length != 0) {
	       PRINTF(("svcauth_gssapi: non-empty handle on GSSAPI_INIT\n"));
	       LOG_MISCERR("protocol error in client handle");
	       ret = AUTH_FAILED;
	       goto error;
	  }
	       
	  PRINTF(("svcauth_gssapi: GSSAPI_INIT, creating client.\n"));
	  
	  client_data = create_client();
	  if (client_data == NULL) {
	       PRINTF(("svcauth_gssapi: create_client failed\n"));
	       LOG_MISCERR("internal error creating client record");
	       ret = AUTH_FAILED;
	       goto error;
	  }
     } else {
	  if (creds.client_handle.length == 0) {
	       PRINTF(("svcauth_gssapi: expected non-empty creds\n"));
	       LOG_MISCERR("protocol error in client credentials");
	       ret = AUTH_FAILED;
	       goto error;
	  }
	  
	  PRINTF(("svcauth_gssapi: incoming client_handle %d, len %d\n", 
		  *((uint32_t *) creds.client_handle.value),
		  (int) creds.client_handle.length));

	  client_data = get_client(&creds.client_handle);
	  if (client_data == NULL) {
	       PRINTF(("svcauth_gssapi: client_handle lookup failed\n"));
	       LOG_MISCERR("invalid client handle received");
	       ret = AUTH_BADCRED;
	       goto error;
	  }
	  PRINTF(("svcauth_gssapi: client_handle lookup succeeded\n"));
     }

     /* any response we send will use client_handle, so set it now */
     call_res.client_handle.length = sizeof(client_data->key);
     call_res.client_handle.value = (char *) &client_data->key;
     
     /* mark this call as using AUTH_GSSAPI via client_data's SVCAUTH */
     rqst->rq_xprt->xp_auth = &client_data->svcauth;

     if (client_data->established == FALSE) {
	  PRINTF(("svcauth_gssapi: context is not established\n"));

	  if (creds.auth_msg == FALSE) {
	       PRINTF(("svcauth_gssapi: expected auth_msg TRUE\n"));
	       LOG_MISCERR("protocol error on incomplete connection");
	       ret = AUTH_REJECTEDCRED;
	       goto error;
	  }

	  /*
	   * If the context is not established, then only GSSAPI_INIT
	   * and _CONTINUE requests are valid.
	   */
	  if (rqst->rq_proc != AUTH_GSSAPI_INIT && rqst->rq_proc !=
	      AUTH_GSSAPI_CONTINUE_INIT) {
	       PRINTF(("svcauth_gssapi: unacceptable procedure %d\n",
		       rqst->rq_proc));
	       LOG_MISCERR("protocol error on incomplete connection");
	       ret = AUTH_FAILED;
	       goto error;
	  }

	  /* call is for us, deserialize arguments */
	  memset(&call_arg, 0, sizeof(call_arg));
	  if (! svc_getargs(rqst->rq_xprt, xdr_authgssapi_init_arg,
			    &call_arg)) {
	       PRINTF(("svcauth_gssapi: cannot decode args\n"));
	       LOG_MISCERR("protocol error in procedure arguments");
	       ret = AUTH_BADCRED;
	       goto error;
	  }

	  /*
	   * Process the call arg version number.
	   * 
	   * Set the krb5_gss backwards-compatibility mode based on client
	   * version.  This controls whether the AP_REP message is
	   * encrypted with the session key (version 2+, correct) or the
	   * session subkey (version 1, incorrect).  This function can
	   * never fail, so we don't bother checking its return value.
	   */
	  switch (call_arg.version) {
	  case 1:
	  case 2:
	       LOG_MISCERR("Warning: Accepted old RPC protocol request");
	       call_res.version = 1;
	       break;
	  case 3:
	  case 4:
	       /* 3 and 4 are essentially the same, don't bother warning */
	       call_res.version = call_arg.version;
	       break;
	  default:
	       PRINTF(("svcauth_gssapi: bad GSSAPI_INIT version\n"));
	       LOG_MISCERR("unsupported GSSAPI_INIT version");
	       ret = AUTH_BADCRED;
	       goto error;
	  }

#ifdef GSS_BACKWARD_HACK
	  krb5_gss_set_backward_mode(&minor_stat, call_arg.version == 1);
#endif

	  if (call_arg.version >= 3) {
	       memset(&bindings, 0, sizeof(bindings));
	       bindings.application_data.length = 0;
	       bindings.initiator_addrtype = GSS_C_AF_INET;
	       bindings.initiator_address.length = 4;
	       bindings.initiator_address.value =
		    &svc_getcaller(rqst->rq_xprt)->sin_addr.s_addr;

	       if (rqst->rq_xprt->xp_laddrlen > 0) {
		    bindings.acceptor_addrtype = GSS_C_AF_INET;
		    bindings.acceptor_address.length = 4;
		    bindings.acceptor_address.value =
			 &rqst->rq_xprt->xp_laddr.sin_addr.s_addr;
	       } else {
		    LOG_MISCERR("cannot get local address");
		    ret = AUTH_FAILED;
		    goto error;
	       }


	       bindp = &bindings;
	  } else {
	       bindp = GSS_C_NO_CHANNEL_BINDINGS;
	  }

	  /*
	   * If the client's server_creds is already set, use it.
	   * Otherwise, try each credential in server_creds_list until
	   * one of them succeedes, then set the client server_creds
	   * to that.  If all fail, the client's server_creds isn't
	   * set (which is fine, because the client will be gc'ed
	   * anyway).
	   *
	   * If accept_sec_context returns something other than
	   * success and GSS_S_FAILURE, then assume different
	   * credentials won't help and stop looping.
	   * 
	   * Note that there are really two cases here: (1) the client
	   * has a server_creds already, and (2) it does not.  They
	   * are both written in the same loop so that there is only
	   * one textual call to gss_accept_sec_context; in fact, in
	   * case (1), the loop is executed exactly once.
	   */
	  for (i = 0; i < server_creds_count; i++) {
	       if (client_data->server_creds != NULL) {
		    PRINTF(("svcauth_gssapi: using's clients server_creds\n"));
		    server_creds = client_data->server_creds;
	       } else {
		    PRINTF(("svcauth_gssapi: trying creds %d\n", i));
		    server_creds = server_creds_list[i];
	       }
	       
	       /* Free previous output_token from loop */
	       if(i != 0) gss_release_buffer(&minor_stat, &output_token);

	       call_res.gss_major =
		    gss_accept_sec_context(&call_res.gss_minor,
					   &client_data->context,
					   server_creds,
					   &call_arg.token,
					   bindp,
					   &client_data->client_name,
					   NULL,
					   &output_token,
					   &ret_flags,
					   &time_rec,
					   NULL);

	       if (server_creds == client_data->server_creds)
		    break;

	       PRINTF(("accept_sec_context returned 0x%x 0x%x wrong-princ=%#x\n",
		       call_res.gss_major, call_res.gss_minor, (int) KRB5KRB_AP_WRONG_PRINC));
	       if (call_res.gss_major == GSS_S_COMPLETE ||
		   call_res.gss_major == GSS_S_CONTINUE_NEEDED) {
		    /* server_creds was right, set it! */
		    PRINTF(("svcauth_gssapi: creds are correct, storing\n"));
		    client_data->server_creds = server_creds;
		    client_data->server_name = server_name_list[i];
		    break;
	       } else if (call_res.gss_major != GSS_S_FAILURE
#ifdef GSSAPI_KRB5
			  /*
			   * hard-coded because there is no other way
			   * to prevent all GSS_S_FAILURES from
			   * returning a "wrong principal in request"
			   * error
			   */
			  || ((krb5_error_code) call_res.gss_minor !=
			      (krb5_error_code) KRB5KRB_AP_WRONG_PRINC)
#endif
			  ) {
		    break;
	       }
	  }
	  
	  gssstat = call_res.gss_major;
	  minor_stat = call_res.gss_minor;

	  /* done with call args */
	  xdr_free(xdr_authgssapi_init_arg, &call_arg);

	  PRINTF(("svcauth_gssapi: accept_sec_context returned %#x %#x\n",
		  call_res.gss_major, call_res.gss_minor));
	  if (call_res.gss_major != GSS_S_COMPLETE &&
	      call_res.gss_major != GSS_S_CONTINUE_NEEDED) {
	       AUTH_GSSAPI_DISPLAY_STATUS(("accepting context",
					   call_res.gss_major,
					   call_res.gss_minor));

	       if (log_badauth != NULL)
		    (*log_badauth)(call_res.gss_major,
				   call_res.gss_minor,
				   &rqst->rq_xprt->xp_raddr,
				   log_badauth_data);
	       
	       gss_release_buffer(&minor_stat, &output_token);
	       svc_sendreply(rqst->rq_xprt, xdr_authgssapi_init_res,
			     (caddr_t) &call_res);
	       *no_dispatch = TRUE;
	       ret = AUTH_OK;
	       goto error;
	  }
	      
	  if (output_token.length != 0) {
	       PRINTF(("svcauth_gssapi: got new output token\n"));
	       GSS_COPY_BUFFER(call_res.token, output_token);
	  }

	  if (gssstat == GSS_S_COMPLETE) {
	       client_data->seq_num = rand();
	       client_expire(client_data,
			     (time_rec == GSS_C_INDEFINITE ?
			      INDEF_EXPIRE : time_rec) + time(0));

	       PRINTF(("svcauth_gssapi: context established, isn %d\n", 
		       client_data->seq_num));

	       if (auth_gssapi_seal_seq(client_data->context,
					client_data->seq_num,
					&call_res.signed_isn) ==
		   FALSE) {
		    ret = AUTH_FAILED;
		    LOG_MISCERR("internal error sealing sequence number");
		    gss_release_buffer(&minor_stat, &output_token);
		    goto error;
	       }
	  }

	  PRINTF(("svcauth_gssapi: sending reply\n"));
	  svc_sendreply(rqst->rq_xprt, xdr_authgssapi_init_res,
			(caddr_t) &call_res);
	  *no_dispatch = TRUE;

	  /*
	   * If appropriate, set established to TRUE *after* sending
	   * response (otherwise, the client will receive the final
	   * token encrypted)
	   */
	  if (gssstat == GSS_S_COMPLETE) {
	       gss_release_buffer(&minor_stat, &call_res.signed_isn);
	       client_data->established = TRUE;
	  }
	  gss_release_buffer(&minor_stat, &output_token);
     } else {
	  PRINTF(("svcauth_gssapi: context is established\n"));

	  /* check the verifier */
	  PRINTF(("svcauth_gssapi: checking verifier, len %d\n",
		  verf->oa_length));
	  
	  in_buf.length = verf->oa_length;
	  in_buf.value = verf->oa_base;
	  
	  if (auth_gssapi_unseal_seq(client_data->context, &in_buf,
				     &seq_num) == FALSE) {
	       ret = AUTH_BADVERF;
	       LOG_MISCERR("internal error unsealing sequence number");
	       goto error;
	  }
	  
	  if (seq_num != client_data->seq_num + 1) {
	       PRINTF(("svcauth_gssapi: expected isn %d, got %d\n",
		       client_data->seq_num + 1, seq_num));
	       if (log_badverf != NULL)
		    (*log_badverf)(client_data->client_name,
				   client_data->server_name,
				   rqst, msg, log_badverf_data);
	       
	       ret = AUTH_REJECTEDVERF;
	       goto error;
	  }
	  client_data->seq_num++;
	  
	  PRINTF(("svcauth_gssapi: seq_num %d okay\n", seq_num));

	  /* free previous response verifier, if any */
	  if (client_data->prev_verf.length != 0) {
	       gss_release_buffer(&minor_stat, &client_data->prev_verf);
	       client_data->prev_verf.length = 0;
	  }
	  
	  /* prepare response verifier */
	  seq_num = client_data->seq_num + 1;
	  if (auth_gssapi_seal_seq(client_data->context, seq_num,
				   &out_buf) == FALSE) {
	       ret = AUTH_FAILED;
	       LOG_MISCERR("internal error sealing sequence number");
	       goto error;
	  }
	  
	  client_data->seq_num++;
	  
	  PRINTF(("svcauth_gssapi; response seq_num %d\n", seq_num));
	  
	  rqst->rq_xprt->xp_verf.oa_flavor = AUTH_GSSAPI;
	  rqst->rq_xprt->xp_verf.oa_base = out_buf.value; 
	  rqst->rq_xprt->xp_verf.oa_length = out_buf.length;

	  /* save verifier so it can be freed next time */
	  client_data->prev_verf.value = out_buf.value; 
	  client_data->prev_verf.length = out_buf.length;

	  /*
	   * Message is authentic.  If auth_msg if true, process the
	   * call; otherwise, return AUTH_OK so it will be dispatched
	   * to the application server.
	   */

	  if (creds.auth_msg == TRUE) {
	       /*
		* If process_token fails, then the token probably came
		* from an attacker.  No response (error or otherwise)
		* should be returned to the client, since it won't be
		* accepting one.
		*/

	       switch (rqst->rq_proc) {
	       case AUTH_GSSAPI_MSG:
		    PRINTF(("svcauth_gssapi: GSSAPI_MSG, getting args\n"));
		    memset(&call_arg, 0, sizeof(call_arg));
		    if (! svc_getargs(rqst->rq_xprt, xdr_authgssapi_init_arg,
				      &call_arg)) {
			 PRINTF(("svcauth_gssapi: cannot decode args\n"));
			 LOG_MISCERR("protocol error in call arguments");
			 xdr_free(xdr_authgssapi_init_arg, &call_arg);
			 ret = AUTH_BADCRED;
			 goto error;
		    }

		    PRINTF(("svcauth_gssapi: processing token\n"));
		    gssstat = gss_process_context_token(&minor_stat,
							client_data->context,
							&call_arg.token);

		    /* done with call args */
		    xdr_free(xdr_authgssapi_init_arg, &call_arg);
		    
		    if (gssstat != GSS_S_COMPLETE) {
			 AUTH_GSSAPI_DISPLAY_STATUS(("processing token",
						     gssstat, minor_stat));
			 ret = AUTH_FAILED;
			 goto error;
		    }

		    svc_sendreply(rqst->rq_xprt, xdr_void, NULL);
		    *no_dispatch = TRUE;
		    break;

	       case AUTH_GSSAPI_DESTROY:
		    PRINTF(("svcauth_gssapi: GSSAPI_DESTROY\n"));
		    
		    PRINTF(("svcauth_gssapi: sending reply\n"));
		    svc_sendreply(rqst->rq_xprt, xdr_void, NULL);
		    *no_dispatch = TRUE;

		    destroy_client(client_data);
		    rqst->rq_xprt->xp_auth = NULL;
		    break;

	       default:
		    PRINTF(("svcauth_gssapi: unacceptable procedure %d\n",
			    rqst->rq_proc));
		    LOG_MISCERR("invalid call procedure number");
		    ret = AUTH_FAILED;
		    goto error;
	       }
	  } else {
	       /* set credentials for app server; comment in svc.c */
	       /* seems to imply this is incorrect, but I don't see */
	       /* any problem with it... */
	       rqst->rq_clntcred = (char *)client_data->client_name;
	       rqst->rq_svccred = (char *)client_data->context;
	  }
     }

     if (creds.client_handle.length != 0) {
	  PRINTF(("svcauth_gssapi: freeing client_handle len %d\n",
		  (int) creds.client_handle.length));
	  xdr_free(xdr_authgssapi_creds, &creds);
     }
     
     PRINTF(("\n"));
     return AUTH_OK;

error:
     if (creds.client_handle.length != 0) {
	  PRINTF(("svcauth_gssapi: freeing client_handle len %d\n",
		  (int) creds.client_handle.length));
	  xdr_free(xdr_authgssapi_creds, &creds);
     }
     
     PRINTF(("\n"));
     return ret;
}