📄 ckufio.c
字号:
#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 /* is68k */#ifdef COHERENT#ifdef _I386#include <fcntl.h>#else#include <sys/fcntl.h>#endif /* _I386 */#endif /* COHERENT */extern int inserver; /* I am IKSD */int guest = 0; /* Anonymous user */#ifdef IKSDextern int isguest;extern char * 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 */static int askpasswd = 0; /* Have OK user, must ask for passwd */#endif /* CK_LOGIN */#ifdef CKROOTstatic char ckroot[CKMAXPATH+1] = { NUL, NUL };static int ckrootset = 0;int ckrooterr = 0;#endif /* CKROOT */_PROTOTYP( VOID ignorsigs, (void) );_PROTOTYP( VOID restorsigs, (void) );/* Change argument to "(const char *)" if this causes trouble. Or... if it causes trouble, then maybe it was already declared in a header file after all, so you can remove this prototype.*/#ifndef NDGPWNAM /* If not defined No Declare getpwnam... */#ifndef _POSIX_SOURCE#ifndef NEXT#ifndef SVR4/* POSIX <pwd.h> already gave prototypes for these. */#ifdef IRIX40_PROTOTYP( struct passwd * getpwnam, (const char *) );#else#ifdef IRIX51_PROTOTYP( struct passwd * getpwnam, (const char *) );#else#ifdef M_UNIX_PROTOTYP( struct passwd * getpwnam, (const char *) );#else#ifdef HPUX9_PROTOTYP( struct passwd * getpwnam, (const char *) );#else#ifdef HPUX10_PROTOTYP( struct passwd * getpwnam, (const char *) );#else#ifdef DCGPWNAM_PROTOTYP( struct passwd * getpwnam, (const char *) );#else_PROTOTYP( struct passwd * getpwnam, (char *) );#endif /* DCGPWNAM */#endif /* HPUX10 */#endif /* HPUX9 */#endif /* M_UNIX */#endif /* IRIX51 */#endif /* IRIX40 */#ifndef SUNOS4#ifndef HPUX9#ifndef HPUX10#ifndef _SCO_DS_PROTOTYP( struct passwd * getpwuid, (PWID_T) );#endif /* _SCO_DS */#endif /* HPUX10 */#endif /* HPUX9 */#endif /* SUNOS4 */_PROTOTYP( struct passwd * getpwent, (void) );#endif /* SVR4 */#endif /* NEXT */#endif /* _POSIX_SOURCE */#endif /* NDGPWNAM */#ifdef CK_SHADOW /* Shadow Passwords... */#include <shadow.h>#endif /* CK_SHADOW */#ifdef CK_PAM /* PAM... */#include <security/pam_appl.h>#ifndef PAM_SERVICE_TYPE /* Defines which PAM service we are */#define PAM_SERVICE_TYPE "kermit"#endif /* PAM_SERVICE_TYPE */#ifdef SOLARIS#define PAM_CONST #else /* SOLARIS */#define PAM_CONST CONST#endif static char * pam_pw = NULL;int#ifdef CK_ANSICpam_cb(int num_msg, PAM_CONST struct pam_message **msg, struct pam_response **resp, void *appdata_ptr )#else /* CK_ANSIC */pam_cb(num_msg, msg, resp, appdata_ptr) int num_msg; PAM_CONST struct pam_message **msg; struct pam_response **resp; void *appdata_ptr;#endif /* CK_ANSIC */{ int i; debug(F111,"pam_cb","num_msg",num_msg); for (i = 0; i < num_msg; i++) { char message[PAM_MAX_MSG_SIZE]; /* Issue prompt and get response */ debug(F111,"pam_cb","Message",i); debug(F111,"pam_cb",msg[i]->msg,msg[i]->msg_style); if (msg[i]->msg_style == PAM_ERROR_MSG) { debug(F111,"pam_cb","PAM ERROR",0); fprintf(stdout,"%s\n", msg[i]->msg); return(0); } else if (msg[i]->msg_style == PAM_TEXT_INFO) { debug(F111,"pam_cb","PAM TEXT INFO",0); fprintf(stdout,"%s\n", msg[i]->msg); return(0); } else if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF) { debug(F111,"pam_cb","Reading response, no echo",0); /* Ugly hack. We check to see if a password has been pushed */ /* into zvpasswd(). This would be true if the password was */ /* received by REMOTE LOGIN. */ if (pam_pw) { ckstrncpy(message,pam_pw,PAM_MAX_MSG_SIZE); } else readpass((char *)msg[i]->msg,message,PAM_MAX_MSG_SIZE); } else if (msg[i]->msg_style == PAM_PROMPT_ECHO_ON) { debug(F111,"pam_cb","Reading response, with echo",0); readtext((char *)msg[i]->msg,message,PAM_MAX_MSG_SIZE); } else { debug(F111,"pam_cb","unknown style",0); return(0); } /* Allocate space for this message's response structure */ resp[i] = (struct pam_response *) malloc(sizeof (struct pam_response)); if (!resp[i]) { int j; debug(F110,"pam_cb","malloc failure",0); for (j = 0; j < i; j++) { free(resp[j]->resp); free(resp[j]); } return(0); } /* Allocate a buffer for the response */ resp[i]->resp = (char *) malloc((int)strlen(message) + 1); if (!resp[i]->resp) { int j; debug(F110,"pam_cb","malloc failure",0); for (j = 0; j < i; j++) { free(resp[j]->resp); free(resp[j]); } free(resp[i]); return(0); } /* Return the results back to PAM */ strcpy(resp[i]->resp, message); /* safe (prechecked) */ resp[i]->resp_retcode = 0; } debug(F110,"pam_cb","Exiting",0); return(0);}#endif /* CK_PAM *//* Define macros for getting file type */#ifdef OXOS/* Olivetti X/OS 2.3 has S_ISREG and S_ISDIR defined incorrectly, so we force their redefinition.*/#undef S_ISREG#undef S_ISDIR#endif /* OXOS */#ifdef UTSV /* Same deal for Amdahl UTSV */#undef S_ISREG#undef S_ISDIR#endif /* UTSV */#ifdef UNISYS52 /* And for UNISYS UTS V 5.2 */#undef S_ISREG#undef S_ISDIR#endif /* UNISYS52 */#ifdef ICLSVR3 /* And for old ICL versions */#undef S_ISREG#undef S_ISDIR#endif /* ICLSVR3 */#ifdef ISDIRBUG /* Also allow this from command line */#ifdef S_ISREG#undef S_ISREG#endif /* S_ISREG */#ifdef S_ISDIR#undef S_ISDIR#endif /* S_ISDIR */#endif /* ISDIRBUG */#ifndef _IFMT#ifdef S_IFMT#define _IFMT S_IFMT#else#define _IFMT 0170000#endif /* S_IFMT */#endif /* _IFMT */#ifndef S_ISREG#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)#endif /* S_ISREG */#ifndef S_ISDIR#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)#endif /* S_ISDIR *//* The following mainly for NeXTSTEP... */#ifndef S_IWUSR#define S_IWUSR 0000200#endif /* S_IWUSR */#ifndef S_IRGRP#define S_IRGRP 0000040#endif /* S_IRGRP */#ifndef S_IWGRP#define S_IWGRP 0000020#endif /* S_IWGRP */#ifndef S_IXGRP#define S_IXGRP 0000010#endif /* S_IXGRP */#ifndef S_IROTH#define S_IROTH 0000004#endif /* S_IROTH */#ifndef S_IWOTH#define S_IWOTH 0000002#endif /* S_IWOTH */#ifndef S_IXOTH#define S_IXOTH 0000001#endif /* S_IXOTH *//* Define maximum length for a file name if not already defined. NOTE: This applies to a path segment (directory or file name), not the entire path string, which can be CKMAXPATH bytes long.*/#ifdef QNX#ifdef _MAX_FNAME#define MAXNAMLEN _MAX_FNAME#else#define MAXNAMLEN 48#endif /* _MAX_FNAME */#else#ifndef MAXNAMLEN#ifdef sun#define MAXNAMLEN 255#else#ifdef FILENAME_MAX#define MAXNAMLEN FILENAME_MAX#else#ifdef NAME_MAX#define MAXNAMLEN NAME_MAX#else#ifdef _POSIX_NAME_MAX#define MAXNAMLEN _POSIX_NAME_MAX#else#ifdef _D_NAME_MAX#define MAXNAMLEN _D_NAME_MAX#else#ifdef DIRSIZ#define MAXNAMLEN DIRSIZ#else#define MAXNAMLEN 14#endif /* DIRSIZ */#endif /* _D_NAME_MAX */#endif /* _POSIX_NAME_MAX */#endif /* NAME_MAX */#endif /* FILENAME_MAX */#endif /* sun */#endif /* MAXNAMLEN */#endif /* QNX */#ifdef COMMENT/* As of 2001-11-03 this is handled in ckcdeb.h *//* Longest pathname ... *//* Beware: MAXPATHLEN is one of UNIX's dirty little secrets. Where is it defined? Who knows... <param.h>, <mod.h>, <unistd.h>, <limits.h>, ... There is not necessarily even a definition for it anywhere, or it might have another name. If you get it wrong, bad things happen with getcwd() and/or getwd(). If you allocate a buffer that is too short, getwd() might write over memory and getcwd() will fail with ERANGE. The definitions of these functions (e.g. in SVID or POSIX.1) do not tell you how to determine the maximum path length in order to allocate a buffer that is the right size.*/#ifdef BSD44#include <sys/param.h> /* For MAXPATHLEN */#endif /* BSD44 */#ifdef COHERENT#include <sys/param.h> /* for MAXPATHLEN, needed for -DDIRENT */#endif /* COHERENT */#endif /* COMMENT */#ifdef MAXPATHLEN#ifdef MAXPATH#undef MAXPATH#endif /* MAXPATH */#define MAXPATH MAXPATHLEN#else#ifdef PATH_MAX#define MAXPATH PATH_MAX#else#ifdef _POSIX_PATH_MAX#define MAXPATH _POSIX_PATH_MAX#else#ifdef BSD42#define MAXPATH 1024#else#ifdef SVR4#define MAXPATH 1024#else#define MAXPATH 255#endif /* SVR4 */#endif /* BSD42 */#endif /* _POSIX_PATH_MAX */#endif /* PATH_MAX */#endif /* MAXPATHLEN *//* Maximum number of filenames for wildcard expansion */#ifndef MAXWLD/* Already defined in ckcdeb.h so the following is superfluous. *//* Don't expect changing them to have any effect. */#ifdef CK_SMALL#define MAXWLD 50#else#ifdef BIGBUFOK#define MAXWLD 102400#else#define MAXWLD 8192#endif /* BIGBUFOK */#endif /* CK_SMALL */#endif /* MAXWLD */static int maxnames = MAXWLD;/* Define the size of the string space for filename expansion. */#ifndef DYNAMIC#ifdef PROVX1#define SSPACE 500#else#ifdef BSD29#define SSPACE 500#else#ifdef pdp11#define SSPACE 500#else#ifdef aegis#define SSPACE 10000 /* Size of string-generating buffer */#else /* Default static buffer size */#ifdef BIGBUFOK#define SSPACE 65000 /* Size of string-generating buffer */#else#define SSPACE 2000 /* size of string-generating buffer */#endif /* BIGBUFOK */#endif /* aegis */#endif /* pdp11 */#endif /* BSD29 */#endif /* PROVX1 */static char sspace[SSPACE]; /* Buffer for generating filenames */#else /* is DYNAMIC */#ifdef BIGBUFOK#define SSPACE 500000#else#define SSPACE 10000#endif /* BIGBUFOK */char *sspace = (char *)0;#endif /* DYNAMIC */static int ssplen = SSPACE; /* Length of string space buffer */#ifdef DCLFDOPEN/* fdopen() needs declaring because it's not declared in <stdio.h> */_PROTOTYP( FILE * fdopen, (int, char *) );#endif /* DCLFDOPEN */#ifdef DCLPOPEN/* popen() needs declaring because it's not declared in <stdio.h> */_PROTOTYP( FILE * popen, (char *, char *) );#endif /* DCLPOPEN */extern int nopush;/* More internal function prototypes *//* * The path structure is used to represent the name to match. * Each slash-separated segment of the name is kept in one * such structure, and they are linked together, to make * traversing the name easier. */struct path { char npart[MAXNAMLEN+4]; /* name part of path segment */ struct path *fwd; /* forward ptr */};#ifndef NOPUSH_PROTOTYP( int shxpand, (char *, char *[], int ) );#endif /* NOPUSH */_PROTOTYP( static int fgen, (char *, char *[], int ) );_PROTOTYP( static VOID traverse, (struct path *, char *, char *) );_PROTOTYP( static VOID addresult, (char *, int) );#ifdef COMMENT/* Replaced by ckmatch() */_PROTOTYP( static int match, (char *, char *) );#endif /* COMMENT */_PROTOTYP( char * whoami, (void) );_PROTOTYP( UID_T real_uid, (void) );_PROTOTYP( static struct path *splitpath, (char *p) );_PROTOTYP( char * zdtstr, (time_t) );_PROTOTYP( time_t zstrdt, (char *, int) );/* Some systems define these symbols in include files, others don't... */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -