📄 ckufio.c
字号:
#ifndef R_OK#define R_OK 4 /* For access */#endif /* R_OK */#ifndef W_OK#define W_OK 2#endif /* W_OK */#ifndef X_OK#define X_OK 1#endif /* X_OK */#ifndef O_RDONLY#define O_RDONLY 000#endif /* O_RDONLY *//* syslog and wtmp items for Internet Kermit Service */extern char * clienthost; /* From ckcmai.c. */static char fullname[CKMAXPATH+1];static char tmp2[CKMAXPATH+1];extern int ckxlogging;#ifdef CKXPRINTF /* Our printf macro conflicts with */#undef printf /* use of "printf" in syslog.h */#endif /* CKXPRINTF */#ifdef CKSYSLOG#ifdef RTAIX#include <sys/syslog.h>#else /* RTAIX */#include <syslog.h>#endif /* RTAIX */#endif /* CKSYSLOG */#ifdef CKXPRINTF#define printf ckxprintf#endif /* CKXPRINTF */int ckxanon = 1; /* Anonymous login ok */int ckxperms = 0040; /* Anonymous file permissions */int ckxpriv = 1; /* Priv'd login ok */#ifndef XFERFILE#define XFERFILE "/var/log/iksd.log"#endif /* XFERFILE *//* wtmp logging for IKSD... */#ifndef CKWTMP /* wtmp logging not selected */int ckxwtmp = 0; /* Know this at runtime */#else /* wtmp file details */int ckxwtmp = 1;#ifdef UTMPBUG /* Unfortunately... *//* Some versions of Linux have a <utmp.h> file that contains "enum utlogin { local, telnet, rlogin, screen, ... };" This clobbers any program that uses any of these words as variable names, function names, macro names, etc. (Other versions of Linux have this declaration within #if 0 ... #endif.) There is nothing we can do about this other than to not include the stupid file. But we need stuff from it, so...*/#include <features.h>#include <sys/types.h>#define UT_LINESIZE 32#define UT_NAMESIZE 32#define UT_HOSTSIZE 256struct timeval { time_t tv_sec; time_t tv_usec;};struct exit_status { short int e_termination; /* Process termination status. */ short int e_exit; /* Process exit status. */};struct utmp { short int ut_type; /* Type of login */ pid_t ut_pid; /* Pid of login process */ char ut_line[UT_LINESIZE]; /* NUL-terminated devicename of tty */ char ut_id[4]; /* Inittab id */ char ut_user[UT_NAMESIZE]; /* Username (not NUL terminated) */ char ut_host[UT_HOSTSIZE]; /* Hostname for remote login */ struct exit_status ut_exit; /* Exit status */ long ut_session; /* Session ID, used for windowing */ struct timeval ut_tv; /* Time entry was made */ int32_t ut_addr_v6[4]; /* Internet address of remote host */ char pad[20]; /* Reserved */};#define ut_time ut_tv.tv_sec /* Why should Linux be like anything else? */#define ut_name ut_user /* ... */extern voidlogwtmp __P ((__const char *__ut_line, __const char *__ut_name, __const char *__ut_host));#else /* Not UTMPBUG */#ifndef HAVEUTMPX /* Who has <utmpx.h> */#ifdef SOLARIS#define HAVEUTMPX#else#ifdef IRIX60#define HAVEUTMPX#else#ifdef CK_SCOV5#define HAVEUTMPX#else#ifdef HPUX100#define HAVEUTMPX#else#ifdef UNIXWARE#define HAVEUTMPX#endif /* UNIXWARE */#endif /* HPUX100 */#endif /* CK_SCOV5 */#endif /* IRIX60 */#endif /* SOLARIS */#endif /* HAVEUTMPX */#ifdef HAVEUTMPX#include <utmpx.h>#else#ifdef OSF50/* Because the time_t in the utmp struct is 64 bits but time() wants 32 */#define __V40_OBJ_COMPAT 1#endif /* OSF50 */#include <utmp.h>#ifdef OSF50#undef __V40_OBJ_COMPAT#endif /* OSF50 */#endif /* HAVEUTMPX */#endif /* UTMPBUG */#ifndef WTMPFILE#ifdef QNX#define WTMPFILE "/usr/adm/wtmp.1"#else#ifdef LINUX#define WTMPFILE "/var/log/wtmp"#else#define WTMPFILE "/usr/adm/wtmp"#endif /* QNX */#endif /* LINUX */#endif /* WTMPFILE */char * wtmpfile = NULL;static int wtmpfd = 0;static char cksysline[32] = { NUL, NUL };#ifndef HAVEUTHOST /* Does utmp include ut_host[]? */#ifdef HAVEUTMPX /* utmpx always does */#define HAVEUTHOST#else#ifdef LINUX /* Linux does */#define HAVEUTHOST#else#ifdef SUNOS4 /* SunOS does */#define HAVEUTHOST#else#ifdef AIX41 /* AIX 4.1 and later do */#define HAVEUTHOST#endif /* AIX41 */#endif /* SUNOS4 */#endif /* LINUX */#endif /* HAVEUTMPX */#endif /* HAVEUTHOST */#ifdef UW200PID_T _vfork() { /* To satisfy a library foulup */ return(fork()); /* in Unixware 2.0.x */}#endif /* UW200 */VOID#ifdef CK_ANSIClogwtmp(const char * line, const char * name, const char * host)#elselogwtmp(line, name, host) char *line, *name, *host;#endif /* CK_ANSIC *//* logwtmp */ {#ifdef HAVEUTMPX struct utmpx ut; /* Needed for ut_host[] */#else struct utmp ut;#endif /* HAVEUTMPX */ struct stat buf; /* time_t time(); */ if (!ckxwtmp) return; if (!wtmpfile) makestr(&wtmpfile,WTMPFILE); if (!line) line = ""; if (!name) name = ""; if (!host) host = ""; if (!wtmpfd && (wtmpfd = open(wtmpfile, O_WRONLY|O_APPEND, 0)) < 0) { ckxwtmp = 0; debug(F110,"WTMP open failed",line,0); return; } if (!fstat(wtmpfd, &buf)) { ckstrncpy(ut.ut_line, line, sizeof(ut.ut_line)); ckstrncpy(ut.ut_name, name, sizeof(ut.ut_name));#ifdef HAVEUTHOST /* Not portable */ ckstrncpy(ut.ut_host, host, sizeof(ut.ut_host));#endif /* HAVEUTHOST */#ifdef HAVEUTMPX time(&ut.ut_tv.tv_sec);#else#ifdef LINUX/* In light of the following comment perhaps the previous line should *//* be "#ifndef COMMENT". */ { /* * On 64-bit platforms sizeof(time_t) and sizeof(ut.ut_time) * are not the same and attempt to use an address of * ut.ut_time as an argument to time() call may cause * "unaligned access" trap. */ time_t zz; time(&zz); ut.ut_time = zz; }#else time(&ut.ut_time);#endif /* LINUX */#endif /* HAVEUTMPX */ if (write(wtmpfd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp)) {#ifndef NOFTRUNCATE#ifndef COHERENT ftruncate(wtmpfd, buf.st_size); /* Error, undo any partial write */#else chsize(wtmpfd, buf.st_size); /* Error, undo any partial write */#endif /* COHERENT */#endif /* NOFTRUNCATE */ debug(F110,"WTMP write error",line,0); } else { debug(F110,"WTMP record OK",line,0); return; } }}#endif /* CKWTMP */#ifdef CKSYSLOG/* C K S Y S L O G -- C-Kermit system logging function, For use by other modules. This module can, but doesn't have to, use it. Call with: n = SYSLG_xx values defined in ckcdeb.h s1, s2, s3: strings.*/VOIDcksyslog(n, m, s1, s2, s3) int n, m; char * s1, * s2, * s3; { int level; if (!ckxlogging) /* syslogging */ return; if (!s1) s1 = ""; /* Fix null args */ if (!s2) s2 = ""; if (!s3) s3 = ""; switch (n) { /* Translate Kermit level */ case SYSLG_DB: /* to syslog level */ level = LOG_DEBUG; break; default: level = m ? LOG_INFO : LOG_ERR; } debug(F110,"cksyslog s1",s1,0); debug(F110,"cksyslog s2",s2,0); debug(F110,"cksyslog s3",s3,0); errno = 0; syslog(level, "%s: %s %s", s1, s2, s3); /* Write syslog record */ debug(F101,"cksyslog errno","",errno);}#endif /* CKSYSLOG *//* Declarations */int maxnam = MAXNAMLEN; /* Available to the outside */int maxpath = MAXPATH;int ck_znewn = -1;#ifdef UNIXchar startupdir[MAXPATH+1];#endif /* UNIX */int pexitstat = -2; /* Process exit status */FILE *fp[ZNFILS] = { /* File pointers */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};/* Flags for each file indicating whether it was opened with popen() */int ispipe[ZNFILS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };/* Buffers and pointers used in buffered file input and output. */#ifdef DYNAMICextern char *zinbuffer, *zoutbuffer;#elseextern char zinbuffer[], zoutbuffer[];#endif /* DYNAMIC */extern char *zinptr, *zoutptr;extern int zincnt, zoutcnt;extern int wildxpand;static long iflen = -1L; /* Input file length */static PID_T pid = 0; /* pid of child fork */static int fcount = 0; /* Number of files in wild group */static int nxpand = 0; /* Copy of fcount */static char nambuf[CKMAXPATH+4]; /* Buffer for a pathname */#ifndef NOFRILLS#define ZMBUFLEN 200static char zmbuf[ZMBUFLEN]; /* For mail, remote print strings */#endif /* NOFRILLS */char **mtchs = NULL; /* Matches found for filename */char **mtchptr = NULL; /* Pointer to current match *//* Z K S E L F -- Kill Self: log out own job, if possible. *//* Note, should get current pid, but if your system doesn't have *//* getppid(), then just kill(0,9)... */#ifndef SVR3#ifndef POSIX#ifndef OSFPC/* Already declared in unistd.h for SVR3 and POSIX */#ifdef CK_ANSICextern PID_T getppid(void);#else#ifndef PS2AIX10#ifndef COHERENTextern PID_T getppid();#endif /* COHERENT */#endif /* PS2AIX10 */#endif /* CK_ANSIC */#endif /* OSFPC */#endif /* POSIX */#endif /* SVR3 */intzkself() { /* For "bye", but no guarantee! */#ifdef PROVX1 return(kill(0,9));#else#ifdef V7 return(kill(0,9));#else#ifdef TOWER1 return(kill(0,9));#else#ifdef FT18 return(kill(0,9));#else#ifdef aegis return(kill(0,9));#else#ifdef COHERENT return(kill((PID_T)getpid(),1));#else#ifdef PID_T exit(kill((PID_T)getppid(),1)); return(0);#else exit(kill(getppid(),1)); return(0);#endif#endif#endif#endif#endif#endif#endif}static VOIDgetfullname(name) char * name; { char *p = (char *)fullname; int len = 0; fullname[0] = '\0'; /* If necessary we could also chase down symlinks here... */#ifdef COMMENT /* This works but is incompatible with wuftpd */ if (isguest && anonroot) { ckstrncpy(fullname,anonroot,CKMAXPATH); len = strlen(fullname); if (len > 0) if (fullname[len-1] == '/') len--; } p += len;#endif /* COMMENT */ zfnqfp(name, CKMAXPATH - len, p); while (*p) { if (*p < '!') *p = '_'; p++; }}/* D O I K L O G -- Open Kermit-specific ftp-like transfer log. */VOID /* Called in ckcmai.c */doiklog() { if (iklogopen) /* Already open? */ return; if (xferlog) { /* Open iksd log if requested */ if (!xferfile) /* If no pathname given */ makestr(&xferfile,XFERFILE); /* use this default */ if (*xferfile) { xferlog = open(xferfile, O_WRONLY | O_APPEND | O_CREAT, 0660); debug(F101,"doiklog open","",xferlog); if (xferlog < 0) {#ifdef CKSYSLOG syslog(LOG_ERR, "xferlog open failure %s: %m", xferfile);#endif /* CKSYSLOG */ debug(F101,"doiklog open errno","",errno); xferlog = 0; } else iklogopen = 1; } else xferlog = 0;#ifdef CKSYSLOG if (xferlog && ckxlogging) syslog(LOG_INFO, "xferlog: %s open ok", xferfile);#endif /* CKSYSLOG */ }}/* Z O P E N I -- Open an existing file for input. *//* Returns 1 on success, 0 on failure */intzopeni(n,name) int n; char *name; { int x; debug(F111,"zopeni",name,n); if ((x = chkfn(n)) != 0) { debug(F111,"zopeni chkfn",ckitoa(n),x); return(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -