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

📄 xnsrestore.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *rcsid = "$Header: xnsrestore.c,v 1.1 87/03/17 16:27:26 ed Exp $";#endif lint/* * Copyright (c) 1986, 1987 Xerox Corporation. *//* $Log:	xnsrestore.c,v $ * Revision 1.1  87/03/17  16:27:26  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/Filing4.h>#include <xnscourier/except.h>#include <xnscourier/CH.h>#include <xnscourier/filetypes.h>#define XNS_TIME_DIFFERENCE	2177452800	/* [(1970-1901) years * 365 days/year + 17 leap days */						/* * 24 hours/day * 60 minutes/hour * 60 seconds/minute */#define ROOT_DIRECTORY "/"CourierConnection *connected;Clearinghouse2_ObjectName hostobjname;Authentication2_Verifier verifier;/* the following 3 items make up the current session */Filing4_Session session;	/* the current session */Clearinghouse2_ObjectName username;Filing4_Handle rootHandle;char cur_dir[512]= 0;char cur_pathname[512]= 0;char cur_name[512]= 0;static Filing4_ControlSequence nullControls = {0,0};/* global data used to communicate with BDT procedures */extern GetAttributeSequences(), 	listproc(), isdirproc(), storeproc();char *AttrToString();Boolean AttrToBoolean();LongCardinal AttrToLongCardinal();Cardinal AttrToCardinal();static (*ProcEachSeq)();static FILE *fin= NULL;FILE *lfile= NULL;Boolean files_found= FALSE;Boolean verbose= FALSE;Boolean is_a_directory= FALSE;char *logfile= 0;char *ctime();long time();char *service;extern int errno;main(argc, argv)int argc;char *argv[];{	char *remotefile;	char *localfile;	int i;	CourierConnection *hookup();	int opt;	extern int optind;	extern char *optarg;	static char *options= "vl:";	static char *usage= "Usage: %s [-v] [-l log-file] local-file remote-file\n";	if ( argc < 3 ) {		fprintf(stderr, usage, argv[0]);		exit(1);	}	while ((opt= getopt(argc, argv, options)) != EOF) 		switch (opt) {			case 'l' :				logfile= optarg;				break;			case 'v' :				verbose++;				break;			default:				fprintf(stderr, "Invalid command option -%c\n", opt);				exit(1);		}	localfile= argv[optind];	optind++;	if ( getserviceandfile(argv[optind], &service, &remotefile) == 0 ) {		fprintf(stderr, "Invalid name %s\n", argv[optind]);		exit(1);	}	DURING {		if ( (connected= hookup(service)) == (CourierConnection *)0 ) {				fprintf(stderr, "\nCan't connect to %s\n", service);				exit(1);		}		login(0,0);		deserializefile(localfile, remotefile);	} HANDLER {		FilingErrMsg(Exception.Code, Exception.Message);	} 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)	Filing4_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;	Filing4_Handle handle;{	Filing4_Attribute pathattr[1];	Filing4_AttributeSequence attrseq;	Filing4_OpenResults openresult;	Filing4_OpenResults openresult2;	if (filename == (char *)0 || *filename == '\000' || (strcmp(filename, "/") == 0) ) {		copyhandle(handle,rootHandle);		return;	}	attrseq.length = 1;	attrseq.sequence = pathattr;	pathattr[0].type = Filing4_pathname;	copyhandle(handle, Filing4_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);	openresult2 = Filing4_Open(connected, NULL, attrseq,				  handle, nullControls,				  session);	copyhandle(handle, openresult2.file);}getdirhandle(filename, handle)	char *filename;	Filing4_Handle handle;{	Filing4_Attribute pathattr[1];	Filing4_AttributeSequence attrseq;	Filing4_OpenResults openresult;	Filing4_OpenResults openresult2;	char *rindex();	char *slash;	if (filename == (char *)0 || *filename == '\000' || (strcmp(filename, "/") == 0) ) {		strcpy(cur_pathname, "/");		strcpy(cur_name, "/");		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 ( slash == cur_pathname) {		copyhandle(handle, rootHandle);		return;	}	attrseq.length = 1;	attrseq.sequence = pathattr;	pathattr[0].type = Filing4_pathname;	copyhandle(handle, Filing4_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);	openresult2 = Filing4_Open(connected, NULL, attrseq,				  handle, nullControls, session);	copyhandle(handle, openresult2.file);}freefilehandle(handle)	Filing4_Handle handle;{	if (handle[0] == Filing4_nullHandle[0] &&	    handle[1] == Filing4_nullHandle[1])		return;		/* don't free nullHandle */	if (handle[0] == rootHandle[0] &&	    handle[1] == rootHandle[1])		return;		/* don't free root directory */	alarm(0);	Filing4_Close(connected, NULL, handle, session);}CourierConnection *hookup(name)	char *name;{	register struct ns_addr *hostaddr;	extern struct ns_addr *getXNSaddr();	Clearinghouse2_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 */		/* clear_Clearinghouse2_ThreePartName(&hostobjname); */		hostobjname = CH_StringToName(hnamebuf, &defaultobjname);	}	return(cconn);}login(name,pwd)	char *pwd;	char *name;{	Filing4_Credentials credentials;	Filing4_LogonResults logonresult;

⌨️ 快捷键说明

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