⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xnsremote.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *rcsid = "$Header: xnsremote.c,v 1.3 87/04/01 08:23:53 ed Exp $";#endif lint/* * Copyright (c) 1986, 1987 Xerox Corporation. *//* $Log:	xnsremote.c,v $ * Revision 1.3  87/04/01  08:23:53  ed * Changed for new MakeSecondaryCreds call. *  * Revision 1.2  87/03/25  10:55:53  ed * Don't reset usefiling in login. *  * Revision 1.1  87/03/17  16:29:19  ed * Initial revision *  *  */#include <stdio.h>#include <sys/time.h>#include <sys/param.h>#include <sys/stat.h>#include <netns/ns.h>#include <netns/sp.h>#include <xnscourier/FilingSubset1.h>#include <xnscourier/Filing4.h>#include <xnscourier/except.h>#undef __Clearinghouse2			/* Filing4.h defs this */#include <xnscourier/CH.h>#include <xnscourier/filetypes.h>#ifdef PRINTOPTION#ifndef XNSPRINT#define XNSPRINT	"/usr/new/xnsprint"#endif XNSPRINT#ifndef MAHA#define MAHA		"/usr/new/maha"#endif MAHA#endif PRINTOPTION#define ROOT_DIRECTORY "/"CourierConnection *connected;Clearinghouse3_ObjectName hostobjname;Authentication3_Verifier verifier;/* the following 3 items make up the current session */FilingSubset1_Session session;	/* the current session */Clearinghouse3_ObjectName username;FilingSubset1_Handle rootHandle;char cur_dir[512]= 0;char cur_pathname[512]= 0;char cur_name[512]= 0;static FilingSubset1_ControlSequence nullControls = {0,0};static FilingSubset1_ScopeSequence nullScope = {0,0};/* global data used to communicate with BDT procedures */extern GetAttributeSequences(), 	listproc(), retrieveproc();char *AttrToString();Boolean AttrToBoolean();LongCardinal AttrToLongCardinal();Cardinal AttrToCardinal();static (*ProcEachSeq)();static FILE *fout= stdout;Boolean files_found= FALSE;Boolean filing_subset= TRUE;Boolean usefiling= TRUE;Boolean verbose= FALSE;LongCardinal typevalue= 0;char *service, *pager;extern int errno;char thru_options[512];struct name_entry {	char *pathname;	LongCardinal type;} ;static struct name_entry *name_list= 0;static int name_count= 0;static int name_size= 0;#define MAX_NAMES	10main(argc, argv)int argc;char *argv[];{	char *file, *rightbrkt;	char oldservice[100];	char *index(), *getenv();	int i;	CourierConnection *hookup();	int opt;	extern int optind;	extern char *optarg;#ifdef PRINTOPTION	static char *options= "fvP:";	static char *usage= "Usage: %s [-f] [-v] [-P printer] file1 ... filen\n";#else PRINTOPTION	static char *options= "fvs";	static char *usage= "Usage: %s [-f] [-v] [-s] file1 ... filen\n";#endif PRINTOPTION	if ( argc < 1 ) {		fprintf(stderr, usage, argv[0]);		exit(1);	}#ifndef PRINTOPTION	pager= getenv("PAGER");#endif PRINTOPTION	strcpy(thru_options, "");	while ((opt= getopt(argc, argv, options)) != EOF) 		switch (opt) {			case 'v':				verbose++;				break;			case 'f':				usefiling= 0;				break;#ifdef PRINTOPTION			case 'P' :				strcat(thru_options, " -P ");				strcat(thru_options, optarg);				break;#else PRINTOPTION			case 's' :				pager= '\0';	/* override pager */				break;#endif PRINTOPTION			default:				fprintf(stderr, "Invalid command option -%c\n", opt);				exit(1);		}	for ( ; optind < argc ; optind++ ) {		if ( getserviceandfile(argv[optind], &service, &file) == 0 ) {			fprintf(stderr, "Invalid name %s\n", argv[optind]);			exit(1);		}		DURING {			if ( strcmp(oldservice, service) != 0 ) {				if ( (connected= hookup(service)) == (CourierConnection *)0 ) {					fprintf(stderr, "\nCan't connect to %s\n", service);					continue;				}				login(0,0);				strcpy(oldservice, service);			}			getfile(file);		} HANDLER {			FilingErrMsg(Exception.Code, Exception.Message);#ifndef PRINTOPTION			if ( fout != stdout )				pclose(fout);#endif PRINTOPTION		} END_HANDLER;	}	return(0);}getserviceandfile(name, srvcptr, fileptr)char *name;char **srvcptr, **fileptr;{	char *sptr, *fptr;	char *index(), *rindex();	/*	 * look for Xerox forms first:	 *	[host]filename	 */	if ( (sptr= index(name, '[')) != 0 ) {		if ( (fptr= index(sptr, ']')) != 0 ) {			*fptr= '\0';			*srvcptr= sptr + 1;			*fileptr= fptr + 1;			return(1);		} else			return(0);	}	/*	 *	(host)filename	 */	if ( (sptr= index(name, '(')) != 0 ) {		if ( (fptr= index(sptr, ')')) != 0 ) {			*fptr= '\0';			*srvcptr= sptr + 1;			*fileptr= fptr + 1;			return(1);		} else			return(0);	}	/*	 * look for XNS style with trailing : delimiter	 * (assumes no : in file name, use alternate spec instead)	 *	object:domain:organization:filename	 *		domain & organization are optional	 */	if ( (fptr= rindex(name, ':')) != 0 ) {		*fptr= '\0';		*srvcptr= name;		*fileptr= fptr + 1;		return(1);	} else		return(0);}copyhandle(dest,src)	FilingSubset1_Handle dest,src;{	if (dest == (Unspecified *) 0) {		fprintf(stderr,"Oops.  dest is null in copyhandle\n");		exit(1);	}	dest[0] = src[0];	dest[1] = src[1];}getfilehandle(filename, handle)	char *filename;	FilingSubset1_Handle handle;{	FilingSubset1_Attribute pathattr[1];	FilingSubset1_AttributeSequence attrseq;	FilingSubset1_OpenResults openresult;	Filing4_OpenResults openresult2;	if (filename == (char *)0 || *filename == '\000' || (strcmp(filename, "/") == 0) ) {		if ( filing_subset )			copyhandle(handle,FilingSubset1_nullHandle);		else			copyhandle(handle,rootHandle);		return;	}	attrseq.length = 1;	attrseq.sequence = pathattr;	pathattr[0].type = FilingSubset1_pathname;	copyhandle(handle, FilingSubset1_nullHandle);#ifdef XEROXFSCOMPATIBILITY	if ( filename[0] == '/')		StringToAttr(filename+1, &pathattr[0]);	else		StringToAttr(filename, &pathattr[0]);#else XEROXFSCOMPATIBILITY	StringToAttr(filename, &pathattr[0]);#endif XEROXFSCOMPATIBILITY	alarm(0);	if ( filing_subset ) {		openresult = FilingSubset1_Open(connected, NULL, attrseq,					  handle, nullControls,					  session);		copyhandle(handle, openresult.file);	} else {		openresult2 = Filing4_Open(connected, NULL, attrseq,					  handle, nullControls,					  session);		copyhandle(handle, openresult2.file);	} }getdirhandle(filename, handle)	char *filename;	FilingSubset1_Handle handle;{	FilingSubset1_Attribute pathattr[1];	FilingSubset1_AttributeSequence attrseq;	FilingSubset1_OpenResults openresult;	Filing4_OpenResults openresult2;	char *rindex();	char *slash;	if (filename == (char *)0 || *filename == '\000' || (strcmp(filename, "/") == 0) ) {		strcpy(cur_pathname, "/");		strcpy(cur_name, "/");		if ( filing_subset )			copyhandle(handle,FilingSubset1_nullHandle);		else			copyhandle(handle,rootHandle);		return;	} else if ( filename[0] == '/' ) {		strcpy(cur_pathname, filename);	} else {		strcpy(cur_pathname, cur_dir);		if ( strcmp(cur_pathname, "/") != 0 )			strcat(cur_pathname, "/");		strcat(cur_pathname, filename); 	}	if ( (slash= rindex(cur_pathname,'/')) == NULL )		strcpy(cur_name, cur_pathname);	else		strcpy(cur_name, slash+1);	if ( filing_subset ) {		copyhandle(handle, FilingSubset1_nullHandle);	} else {		if ( slash == cur_pathname) {			copyhandle(handle, rootHandle);			return;		}		attrseq.length = 1;		attrseq.sequence = pathattr;		pathattr[0].type = FilingSubset1_pathname;		copyhandle(handle, FilingSubset1_nullHandle);		*slash= '\0';		/* separate pathname from name */#ifdef XEROXFSCOMPATIBILITY		if ( cur_pathname[0] == '/' )			StringToAttr(cur_pathname+1, &pathattr[0]);		else			StringToAttr(cur_pathname, &pathattr[0]);#else XEROXFSCOMPATIBILITY		StringToAttr(cur_pathname, &pathattr[0]);#endif XEROXFSCOMPATIBILITY		*slash= '/';		/* and put back */		alarm(0);		if ( filing_subset ) {			openresult = FilingSubset1_Open(connected, NULL, attrseq,						  handle, nullControls,						  session);			copyhandle(handle, openresult.file);		} else {			openresult2 = Filing4_Open(connected, NULL, attrseq,						  handle, nullControls,						  session);			copyhandle(handle, openresult2.file);		}	}}freefilehandle(handle)	FilingSubset1_Handle handle;{	if (handle[0] == FilingSubset1_nullHandle[0] &&	    handle[1] == FilingSubset1_nullHandle[1])		return;		/* don't free nullHandle */	if (handle[0] == rootHandle[0] &&	    handle[1] == rootHandle[1])		return;		/* don't free root directory */	alarm(0);	if ( filing_subset )		FilingSubset1_Close(connected, NULL, handle, session);	else		Filing4_Close(connected, NULL, handle, session);}CourierConnection *hookup(name)	char *name;{	register struct ns_addr *hostaddr;	extern struct ns_addr *getXNSaddr();	Clearinghouse3_ObjectName defaultobjname;	static char hnamebuf[128];	CourierConnection *cconn;	CH_NameDefault(&defaultobjname);	hostobjname = CH_StringToName(name, &defaultobjname);	if ((hostaddr = CH_LookupAddrDN( hostobjname, 0, hnamebuf, 128))) {		/* should check here to be sure host is a file service */		hostaddr->x_port = htons(5); /* ?? */		cconn = CourierOpen(hostaddr);		/* reset objname to flush wildcards */

⌨️ 快捷键说明

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