📄 ckufio.c
字号:
/* C K U F I O -- Kermit file system support for UNIX, Aegis, and Plan 9 */#define CK_NONBLOCK /* See zoutdump() */#ifdef aegischar *ckzv = "Aegis File support, 7.0.156, 30 Dec 1999";#else#ifdef Plan9char *ckzv = "Plan 9 File support, 7.0.156, 30 Dec 1999";#elsechar *ckzv = "UNIX File support, 7.0.156, 30 Dec 1999";#endif /* Plan9 */#endif /* aegis *//* Author: Frank da Cruz <fdc@columbia.edu>, Columbia University Academic Information Systems, New York City, and others noted in the comments below. Note: CUCCA = Previous name of Columbia University Academic Information Systems. Copyright (C) 1985, 2000, Trustees of Columbia University in the City of New York. All rights reserved. See the C-Kermit COPYING.TXT file or the copyright text in the ckcmai.c module for disclaimer and permissions.*//* NOTE TO CONTRIBUTORS: This file, and all the other C-Kermit files, must be compatible with C preprocessors that support only #ifdef, #else, #endif, #define, and #undef. Please do not use #if, logical operators, or other preprocessor features in any of the portable C-Kermit modules. You can, of course, use these constructions in platform-specific modules where you know they are supported.*//* Include Files */#ifdef MINIX2#define _MINIX#endif /* MINIX2 */#include "ckcsym.h"#include "ckcdeb.h"#include "ckcasc.h"#ifndef NOCSETS#include "ckcxla.h"#endif /* NOCSETS */#ifdef OSF13#ifdef CK_ANSIC#ifdef _NO_PROTO#undef _NO_PROTO#endif /* _NO_PROTO */#endif /* CK_ANSIC */#endif /* OSF13 */#include <errno.h>#include <signal.h>#ifdef MINIX2#undef MINIX#undef CKSYSLOG#include <limits.h>#include <time.h>#define NOFILEH#endif /* MINIX2 */#ifdef MINIX#include <limits.h>#include <sys/types.h>#include <time.h>#else#ifdef POSIX#include <limits.h>#else#ifdef SVR3#include <limits.h>#endif /* SVR3 */#endif /* POSIX */#endif /* MINIX *//* Directory Separator macros, to allow this module to work with both UNIX and OS/2: Because of ambiguity with the command line editor escape \ character, the directory separator is currently left as / for OS/2 too, because the OS/2 kernel also accepts / as directory separator. But this is subject to change in future versions to conform to the normal OS/2 style.*/#define DIRSEP '/'#define ISDIRSEP(c) ((c)=='/')#ifdef SDIRENT#define DIRENT#endif /* SDIRENT */#ifdef XNDIR#include <sys/ndir.h>#else /* !XNDIR */#ifdef NDIR#include <ndir.h>#else /* !NDIR, !XNDIR */#ifdef RTU#include "/usr/lib/ndir.h"#else /* !RTU, !NDIR, !XNDIR */#ifdef DIRENT#ifdef SDIRENT#include <sys/dirent.h>#else#include <dirent.h>#endif /* SDIRENT */#else#include <sys/dir.h>#endif /* DIRENT */#endif /* RTU */#endif /* NDIR */#endif /* XNDIR */#ifdef UNIX /* Pointer arg to wait() allowed */#define CK_CHILD /* Assume this is safe in all UNIX */#endif /* UNIX */extern int binary, recursive, stathack;#ifdef CK_CTRLZextern int eofmethod;#endif /* CK_CTRLZ */#include <pwd.h> /* Password file for shell name */#ifdef CK_SRP#include <t_pwd.h> /* SRP Password file */#endif /* CK_SRP */#ifdef HPUX10_TRUSTED#include <hpsecurity.h>#include <prot.h>#endif /* HPUX10_TRUSTED */#ifdef POSIX#define UTIMEH#else#ifdef HPUX9#define UTIMEH#endif /* HPUX9 */#endif /* POSIX */#ifdef SYSUTIMEH /* <sys/utime.h> if requested, */#include <sys/utime.h> /* for extra fields required by */#else /* 88Open spec. */#ifdef UTIMEH /* or <utime.h> if requested */#include <utime.h> /* (SVR4, POSIX) */#define SYSUTIMEH /* Use this for both cases. */#endif /* UTIMEH */#endif /* SYSUTIMEH */#ifndef NOTIMESTAMP#ifdef POSIX#ifndef AS400#define TIMESTAMP#endif /* AS400 */#endif /* POSIX */#ifdef BSD44 /* BSD 4.4 */#ifndef TIMESTAMP#define TIMESTAMP /* Can do file dates */#endif /* TIMESTAMP */#include <sys/time.h>#include <sys/timeb.h>#else /* Not BSD44 */#ifdef BSD4 /* BSD 4.3 and below */#define TIMESTAMP /* Can do file dates */#include <time.h> /* Need this */#include <sys/timeb.h> /* Need this if really BSD */#else /* Not BSD 4.3 and below */#ifdef SVORPOSIX /* System V or POSIX */#ifndef TIMESTAMP#define TIMESTAMP#endif /* TIMESTAMP */#include <time.h>/* void tzset(); (the "void" type upsets some compilers) */#ifndef IRIX60#ifndef ultrix#ifndef CONVEX9/* ConvexOS 9.0, supposedly POSIX, has extern char *timezone(int,int) */#ifndef Plan9extern long timezone;#endif /* Plan9 */#endif /* CONVEX9 */#endif /* ultrix */#endif /* IRIX60 */#endif /* SVORPOSIX */#endif /* BSD4 */#endif /* BSD44 */#ifdef COHERENT#include <time.h>#endif /* COHERENT *//* Is `y' a leap year? */#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)/* Number of leap years from 1970 to `y' (not including `y' itself). */#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)#endif /* NOTIMESTAMP */#ifdef CIE#include <stat.h> /* File status */#else#include <sys/stat.h>#endif /* CIE *//* Macro to alleviate isdir() calls internal to this module */static struct stat STATBUF;#define xisdir(a) ((stat(a,&STATBUF)==-1)?0:(S_ISDIR(STATBUF.st_mode)?1:0))extern char uidbuf[];extern int xferlog;extern char * xferfile;static int iklogopen = 0;static time_t timenow;static char iksdmsg[CKMAXPATH+512];extern int local;extern int server, en_mkd, en_cwd;/* Functions (n is one of the predefined file numbers from ckcker.h): zopeni(n,name) -- Opens an existing file for input. zopeno(n,name,attr,fcb) -- Opens a new file for output. zclose(n) -- Closes a file. zchin(n,&c) -- Gets the next character from an input file. zsinl(n,&s,x) -- Read a line from file n, max len x, into address s. zsout(n,s) -- Write a null-terminated string to output file, buffered. zsoutl(n,s) -- Like zsout, but appends a line terminator. zsoutx(n,s,x) -- Write x characters to output file, unbuffered. zchout(n,c) -- Add a character to an output file, unbuffered. zchki(name) -- Check if named file exists and is readable, return size. zchko(name) -- Check if named file can be created. zchkspa(name,n) -- Check if n bytes available to create new file, name. znewn(name,s) -- Make a new unique file name based on the given name. zdelet(name) -- Delete the named file. zxpand(string) -- Expands the given wildcard string into a list of files. znext(string) -- Returns the next file from the list in "string". zxrewind() -- Rewind zxpand list. zxcmd(n,cmd) -- Execute the command in a lower fork on file number n. zclosf() -- Close input file associated with zxcmd()'s lower fork. zrtol(n1,n2) -- Convert remote filename into local form. zltor(n1,n2) -- Convert local filename into remote form. zchdir(dirnam) -- Change working directory. zhome() -- Return pointer to home directory name string. zkself() -- Kill self, log out own job. zsattr(struct zattr *) -- Return attributes for file which is being sent. zstime(f, struct zattr *, x) - Set file creation date from attribute packet. zrename(old, new) -- Rename a file. zcopy(source,destination) -- Copy a file. zmkdir(path) -- Create the directory path if possible zfnqfp(fname,len,fullpath) - Determine full path for file name. zgetfs(name) -- return file size regardless of accessibility zchkpid(pid) -- tell if PID is valid and active*//* Kermit-specific includes *//* Definitions here supersede those from system include files. ckcdeb.h is included above.*/#include "ckcker.h" /* Kermit definitions */#include "ckucmd.h" /* For keyword tables */#include "ckuver.h" /* Version herald */char *ckzsys = HERALD;/* File access checking ... There are two calls to access() in this module. If this program is installed setuid or setgid on a Berkeley-based UNIX system that does NOT incorporate the saved-original-effective-uid/gid feature, then, when we have swapped the effective and original uid/gid, access() fails because it uses what it thinks are the REAL ids, but we have swapped them. This occurs on systems where ANYBSD is defined, NOSETREU is NOT defined, and SAVEDUID is NOT defined. So, in theory, we should take care of this situation like so: ifdef ANYBSD ifndef NOSETREU ifndef SAVEDUID define SW_ACC_ID endif endif endif But we can't test such a general scheme everywhere, so let's only do this when we know we have to...*/#ifdef NEXT /* NeXTSTEP 1.0-3.0 */#define SW_ACC_ID#endif /* NEXT *//* Support for tilde-expansion in file and directory names */#ifdef POSIX#define NAMEENV "LOGNAME"#endif /* POSIX */#ifdef BSD4#define NAMEENV "USER"#endif /* BSD4 */#ifdef ATTSV#define NAMEENV "LOGNAME"#endif /* ATTSV *//* Berkeley Unix Version 4.x *//* 4.1bsd support from Charles E Brooks, EDN-VAX */#ifdef BSD4#ifdef MAXNAMLEN#define BSD42#endif /* MAXNAMLEN */#endif /* BSD4 *//* Definitions of some system commands */char *DELCMD = "rm -f "; /* For file deletion */char *CPYCMD = "cp "; /* For file copy */char *RENCMD = "mv "; /* For file rename */char *PWDCMD = "pwd "; /* For saying where I am */#ifdef COMMENT#ifdef HPUX10char *DIRCMD = "/usr/bin/ls -l "; /* For directory listing */char *DIRCM2 = "/usr/bin/ls -l "; /* For directory listing, no args */#elsechar *DIRCMD = "/bin/ls -l "; /* For directory listing */char *DIRCM2 = "/bin/ls -l "; /* For directory listing, no args */#endif /* HPUX10 */#elsechar *DIRCMD = "ls -l "; /* For directory listing */char *DIRCM2 = "ls -l "; /* For directory listing, no args */#endif /* COMMENT */char *TYPCMD = "cat "; /* For typing a file */#ifdef DGUX540char *MAILCMD = "mailx"; /* For sending mail */#else#ifdef UNIXchar *MAILCMD = "Mail";#elsechar *MAILCMD = "";#endif /* UNIX */#endif /* DGUX40 */#ifdef UNIX#ifdef ANYBSD /* BSD uses lpr to spool */#ifdef DGUX540 /* And DG/UX */char * PRINTCMD = "lp";#elsechar * PRINTCMD = "lpr";#endif /* DGUX540 */#else /* Sys V uses lp */#ifdef TRS16 /* except for Tandy-16/6000... */char * PRINTCMD = "lpr";#elsechar * PRINTCMD = "lp";#endif /* TRS16 */#endif /* ANYBSD */#else /* Not UNIX */#define PRINTCMD ""#endif /* UNIX */#ifdef FT18 /* Fortune For:Pro 1.8 */#undef BSD4#endif /* FT18 */#ifdef BSD4char *SPACMD = "pwd ; df ."; /* Space in current directory */#else#ifdef FT18char *SPACMD = "pwd ; du ; df .";#elsechar *SPACMD = "df ";#endif /* FT18 */#endif /* BSD4 */char *SPACM2 = "df "; /* For space in specified directory */#ifdef FT18#define BSD4#endif /* FT18 */#ifdef BSD4char *WHOCMD = "finger ";#elsechar *WHOCMD = "who ";#endif /* BSD4 *//* More system-dependent includes, which depend on symbols defined *//* in the Kermit-specific includes. Oh what a tangled web we weave... */#ifdef COHERENT /* <sys/file.h> */#define NOFILEH#endif /* COHERENT */#ifdef MINIX#define NOFILEH#endif /* MINIX */#ifdef aegis#define NOFILEH#endif /* aegis */#ifdef unos#define NOFILEH#endif /* unos */#ifndef NOFILEH#include <sys/file.h>#endif /* NOFILEH */#ifndef is68k /* Whether to include <fcntl.h> */#ifndef BSD41 /* All but a couple UNIXes have it. */#ifndef FT18#ifndef COHERENT#include <fcntl.h>#endif /* COHERENT */#endif /* FT18 */#endif /* BSD41 */#endif /* not is68k */#ifdef COHERENT#ifdef _I386#include <fcntl.h>#else#include <sys/fcntl.h>#endif /* _I386 */#endif /* COHERENT */#ifdef IKSDextern int isguest;extern int inserver;extern char * homdir, * anonroot;#endif /* IKSD */#ifdef CK_LOGIN#define GUESTPASS 256static char guestpass[GUESTPASS] = { NUL, NUL }; /* Anonymous "password" */static int logged_in = 0; /* Set when user is logged in */int guest = 0; /* Anonymous user */static int askpasswd = 0; /* Have OK user, must ask for passwd */#endif /* CK_LOGIN */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -