tailor.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 276 行

C
276
字号
/* * RFA - Remote File Access * * Access and Management for a partial file system tree that exists * at two sites either as master files or slave files * * tailor.c - read rfatailor and .rfarc file * * Contributed by Oliver Wenzel, GMD Berlin, 1990 * * $Header: /xtel/isode/isode/others/rfa/RCS/tailor.c,v 9.0 1992/06/16 12:47:25 isode Rel $ * * $Log: tailor.c,v $ * Revision 9.0  1992/06/16  12:47:25  isode * Release 8.0 * */#ifndef       lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/rfa/RCS/tailor.c,v 9.0 1992/06/16 12:47:25 isode Rel $";#endif/* *                              NOTICE * *    Acquisition, use, and distribution of this module and related *    materials are subject to the restrictions of a license agreement. *    Consult the Preface in the User's Manual for the full terms of *    this agreement. * */#include <stdio.h>#include <ctype.h>#include "general.h" #include "logger.h"#include "rfa.h"#include "rfainfo.h"extern char *fsBase;extern char *user, *host, *passwd, *strdup();extern char *realpath();extern LLog *pgm_log;int default_transfer = RI_TR_REQ;int doChown = 0;int doChgrp = 1;int doChmod = 1;int doClearSUID = 1;int doRmWidows = 0;int doRfaExec = 1;int timeSlave = 0;int compLimit = COMPRESSLIMIT;char *passwd = "rfa";char *user = "rfa";char *host = "localhost";int backup = 0;#define VERROR(v)	{ sprintf(errp,"\n\tinvalid tailor value '%s'",(v));\			  errp += strlen(errp); \			  err++; }char *cut(s)    char *s;{    register char *s1;     for (; *s && isspace(*s); s++)        ;    for (; *s && (*s == '"'); s++)        ;    for (s1 = s + strlen(s) - 1; (s1 != s) && isspace(*s1); s1--)        ;    for (; *s1 && (*s1 == '"'); s1--)        ;    if (*s1)        *(s1+1) = '\0';    return s;}      int tailor(fn)    char *fn;{    FILE *f;    char buf[BUFSIZ];    char *errp, *v, *o, *index();    int err = 0;    if ((f = fopen(fn, "r")) == NULL)  	return OK;    errp = rfaErrStr;    while (fgets(buf, BUFSIZ, f)) {	for (v = buf; isspace(*v); v++)	    ;	if (*v == '\0')	    continue;	if (*buf == '#')	    continue;	if ((v = index(buf,'=')) == NULL) {	    sprintf(rfaErrStr, "\n\tinvalid tailor string '%s'", cut(buf));	    fclose(f);	    return NOTOK_LOCAL_ERROR;    	}	*v = '\0';	v = cut(v+1);	o = cut(buf);	/*--- USER ---*/	if (!strcasecmp(o, "user")) {	    user = strdup(v);	} else 	/*--- PASSWORD ---*/	if (!strcasecmp(o, "password")) {	    passwd = strdup(v);	} else	/*--- HOST ---*/	if (!strcasecmp(o, "host")) {	    host = strdup(v);	} else 	/*--- ROOT ---*/	if (!strcasecmp(o, "root")) {	    char buf[BUFSIZ];	    if (realpath(v, buf) == NULLCP) {		sprintf(errp,"\n\tinvalid local root '%s'", cut(v));		errp += strlen(errp);		err++;	    }	    fsBase = strdup(buf);	} else 	/*--- COMPRESS ---*/	if (!strcasecmp(o, "compress")) {	    if((compLimit = atoi(v)) == 0)		VERROR(v);	} else 	/*--- BACKUP ---*/	if (!strcasecmp(o, "backup")) {	    if (!strcasecmp(v, "on"))		backup = 1;	    else 		if (!strcasecmp(v, "off"))		    backup = 0;		else		    VERROR(v);	} else 	/*--- CHGRP ---*/	if (!strcasecmp(o, "chgrp")) {	    if (!strcasecmp(v, "on"))		doChgrp = 1;	    else 		if (!strcasecmp(v, "off"))		    doChgrp = 0;		else		    VERROR(v);	} else 	/*--- TIME ---*/	if (!strcasecmp(o, "time")) {	    if (!strcasecmp(v, "slave"))		timeSlave = 1;	    else 		if (!strcasecmp(v, "master"))		    timeSlave = 0;		else		    VERROR(v);	} else 	/*--- CHOWN ---*/	if (!strcasecmp(o, "chown")) {	    if (!strcasecmp(v, "on")) {		if (geteuid() != 0) {		    sprintf(errp,			"\n\tWARNING: must run as root for <chown> option");		    errp += strlen(errp);		    doChown = 0;		} else		    doChown = 1;	    } else 		if (!strcasecmp(v, "off"))		    doChown = 0;		else		    VERROR(v);	} else 	/*--- CHMOD ---*/	if (!strcasecmp(o, "chmod")) {	    if (!strcasecmp(v, "on"))		doChmod = 1;	    else 		if (!strcasecmp(v, "off"))		    doChmod = 0;		else		    VERROR(v);	} else 		/*--- STRIP SUID ---*/	if (!strcasecmp(o, "clearsuid")) {	    if (!strcasecmp(v, "on"))		doClearSUID = 1;	    else 		if (!strcasecmp(v, "off"))		    doClearSUID = 0;		else		    VERROR(v);	} else 	/*--- REMOVE SLAVES ---*/	if (!strcasecmp(o, "rmslaves")) {	    if (!strcasecmp(v, "on"))		doRmWidows = 1;	    else 		if (!strcasecmp(v, "off"))		    doRmWidows = 0;		else		    VERROR(v);	} else 	/*--- LOGDEBUG ---*/	if (!strcasecmp(o, "debuglog"))  {	    if (!strcasecmp(v, "on"))		pgm_log->ll_events |= LLOG_DEBUG | LLOG_TRACE | LLOG_NOTICE;	    else 		if (!strcasecmp(v, "off"))		    pgm_log->ll_events = LLOG_EXCEPTIONS | LLOG_FATAL;		else		    VERROR(v);	} else 	/*--- RFA EXEC ---*/	if (!strcasecmp(o, "rfaexec"))  {	    if (!strcasecmp(v, "on"))		doRfaExec = 1;	    else 		if (!strcasecmp(v, "off"))		    doRfaExec = 0;		else		    VERROR(v);	} else 	/*--- TRANSFER ---*/	if (!strcasecmp(o, "transfer"))  {	    if (!strcasecmp(v, "request"))		default_transfer = RI_TR_REQ;	    else 		if (!strcasecmp(v, "auto"))		    default_transfer = RI_TR_AUTO;		else		    VERROR(v);	} else  {	    sprintf(errp, "\n\tinvalid tailor option '%s'",o);	    errp += strlen(errp);	    err++;	}    }    fclose(f);    if (err)	return NOTOK;    return OK;}

⌨️ 快捷键说明

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