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

📄 imiscd.c

📁 ftam等标准协议服务器和客户端的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* imiscd.c - miscellaneous network service -- responder */#ifndef	lintstatic char *rcsid = "$Header: /f/iso/imisc/RCS/imiscd.c,v 5.0 88/07/21 14:42:08 mrose Rel $";#endif/*  * $Header: /f/iso/imisc/RCS/imiscd.c,v 5.0 88/07/21 14:42:08 mrose Rel $ * * * $Log$ *//* *				  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 <ctype.h>#include <stdio.h>#include "ryresponder.h"	/* for generic idempotent responders */#include "IMISC-ops.h"          /* IMISC operation definitions */#include "IMISC-types.h"	/* IMISC type definitions */#include <utmp.h>#ifdef	SYS5struct utmp *getutent ();#include <sys/times.h>#endif#include <sys/stat.h>/*    DATA */static char *myservice = "isode miscellany";/* should be something else */static int execuid = 1;static int execgid = 1;					/* OPERATIONS */int	op_utcTime (), op_genTime (), op_timeOfDay (), op_users (),	op_charGen (), op_pwdGen (), op_exec (), op_tellUser (), op_data ();static struct dispatch dispatches[] = {    "utcTime", operation_IMISC_utcTime, op_utcTime,    "genTime", operation_IMISC_genTime, op_genTime,    "timeOfDay", operation_IMISC_timeOfDay, op_timeOfDay,    "users", operation_IMISC_users, op_users,    "chargen", operation_IMISC_charGen, op_charGen,    "pwdGen", operation_IMISC_pwdGen, op_pwdGen,    "qotd", operation_IMISC_qotd, op_exec,    "finger", operation_IMISC_finger, op_exec,    "tellUser", operation_IMISC_tellUser, op_tellUser,    "ping", operation_IMISC_ping, op_data,    "sink", operation_IMISC_sink, op_data,    "echo", operation_IMISC_echo, op_data,    NULL};					/* TYPES */struct type_IMISC_IA5List *str2ia5list ();extern int  errno;char	*getlocalhost();long	time ();char   *ctime ();/*    MAIN *//* ARGSUSED */main (argc, argv, envp)int	argc;char  **argv,      **envp;{    ryresponder (argc, argv, getlocalhost(), myservice, dispatches,	    table_IMISC_Operations, NULLIFP, NULLIFP);    exit (0);			/* NOTREACHED */}/*    OPERATIONS *//* ARGSUSED */static int  op_utcTime (sd, ryo, rox, in, roi)int	sd;struct RyOperation *ryo;struct RoSAPinvoke *rox;caddr_t	in;struct RoSAPindication *roi;{    long    clock;    char   *cp;    register struct tm *tm;    struct UTCtime  uts;    register struct UTCtime *ut = &uts;    register struct type_IMISC_UTCResult *ur;    if (rox -> rox_nolinked == 0) {	advise (NULLCP, LOG_INFO,		"RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",		sd, ryo -> ryo_name, rox -> rox_linkid);	return ureject (sd, ROS_IP_LINKED, rox, roi);    }    if (debug)	advise (NULLCP, LOG_DEBUG, "RO-INVOKE.INDICATION/%d: %s",		sd, ryo -> ryo_name);    if (time (&clock) == NOTOK || (tm = gmtime (&clock)) == NULL)	return error (sd, error_IMISC_unableToDetermineTime, (caddr_t) NULL,		    rox, roi);    tm2ut (tm, ut);    if ((cp = utct2str (ut)) == NULLCP	    || (ur = str2qb (cp, strlen (cp), 1)) == NULL)	return error (sd, error_IMISC_congested, (caddr_t) NULL, rox, roi);    if (RyDsResult (sd, rox -> rox_id, (caddr_t) ur, ROS_NOPRIO, roi) == NOTOK)	ros_adios (&roi -> roi_preject, "RESULT");    free_IMISC_UTCResult (ur);    return OK;}/*  *//* ARGSUSED */static int  op_genTime (sd, ryo, rox, in, roi)int	sd;struct RyOperation *ryo;struct RoSAPinvoke *rox;caddr_t	in;struct RoSAPindication *roi;{    long    clock;    char   *cp;#if	defined(BSD42) || defined (HPUX)    struct timeval  tvs;#endif    register struct tm *tm;    struct UTCtime  uts;    register struct UTCtime *ut = &uts;    register struct type_IMISC_GenResult *gr;    if (rox -> rox_nolinked == 0) {	advise (NULLCP, LOG_INFO,		"RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",		sd, ryo -> ryo_name, rox -> rox_linkid);	return ureject (sd, ROS_IP_LINKED, rox, roi);    }    if (debug)	advise (NULLCP, LOG_DEBUG, "RO-INVOKE.INDICATION/%d: %s",		sd, ryo -> ryo_name);#if	defined(BSD42) || defined (HPUX)    if (gettimeofday (&tvs, (struct timezone *) 0) == NOTOK)	return error (sd, error_IMISC_unableToDetermineTime, (caddr_t) NULL,		    rox, roi);    clock = tvs.tv_sec;#else    if (time (&clock) == NOTOK)	return error (sd, error_IMISC_unableToDetermineTime, (caddr_t) NULL,		    rox, roi);#endif    if ((tm = gmtime (&clock)) == NULL)	return error (sd, error_IMISC_unableToDetermineTime, (caddr_t) NULL,		    rox, roi);    tm2ut (tm, ut);#ifdef	BSD42    ut -> ut_flags |= UT_USEC;    ut -> ut_usec = tvs.tv_usec;#endif    if ((cp = gent2str (ut)) == NULLCP	    || (gr = str2qb (cp, strlen (cp), 1)) == NULL)	return error (sd, error_IMISC_congested, (caddr_t) NULL, rox, roi);    if (RyDsResult (sd, rox -> rox_id, (caddr_t) gr, ROS_NOPRIO, roi) == NOTOK)	ros_adios (&roi -> roi_preject, "RESULT");    free_IMISC_GenResult (gr);    return OK;}/*  *//* Return the number of seconds since 00:00 (midnight) 1 January 1900 GMT *//* ARGSUSED */static int  op_timeOfDay (sd, ryo, rox, in, roi)int	sd;struct RyOperation *ryo;struct RoSAPinvoke *rox;caddr_t	in;struct RoSAPindication *roi;{    long	clock;    struct type_IMISC_TimeResult trs;    register struct type_IMISC_TimeResult *tr = &trs;    if (rox -> rox_nolinked == 0) {	advise (NULLCP, LOG_INFO,		"RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",		sd, ryo -> ryo_name, rox -> rox_linkid);	return ureject (sd, ROS_IP_LINKED, rox, roi);    }    if (debug)	advise (NULLCP, LOG_DEBUG, "RO-INVOKE.INDICATION/%d: %s",		sd, ryo -> ryo_name);    if (time (&clock) == NOTOK)	return error (sd, error_IMISC_unableToDetermineTime, (caddr_t) NULL,		    rox, roi);    tr -> parm = clock + 2208988800;    if (RyDsResult (sd, rox -> rox_id, (caddr_t) tr, ROS_NOPRIO, roi) == NOTOK)	ros_adios (&roi -> roi_preject, "RESULT");    return OK;}/*  */#ifdef	sun#define	BSD42#undef	SYS5#endif#ifdef	BSD42#define	HMAX	(sizeof (ut -> ut_host))#endif#define	LMAX	(sizeof (ut -> ut_line))#define	NMAX	(sizeof (ut -> ut_name))/* ARGSUSED */static int  op_users (sd, ryo, rox, in, roi)int	sd;struct RyOperation *ryo;struct RoSAPinvoke *rox;caddr_t	in;struct RoSAPindication *roi;{#ifndef	SYS5    int	    ud;#endif    register char  *dp;    char    buffer[BUFSIZ];    struct utmp uts;    register struct utmp   *ut = &uts;    struct type_IMISC_IA5List *ia5;    register struct type_IMISC_IA5List **ia5p;    if (rox -> rox_nolinked == 0) {	advise (NULLCP, LOG_INFO,		"RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",		sd, ryo -> ryo_name, rox -> rox_linkid);	return ureject (sd, ROS_IP_LINKED, rox, roi);    }    if (debug)	advise (NULLCP, LOG_DEBUG, "RO-INVOKE.INDICATION/%d: %s",		sd, ryo -> ryo_name);    ia5 = NULL;    ia5p = &ia5;#ifndef	SYS5    if ((ud = open ("/etc/utmp", 0)) == NOTOK) {	int	result;	(void) sprintf (buffer, "/etc/utmp: %s", sys_errname (errno));	if ((*ia5p = str2ia5list (buffer)) == NULL)	    goto congested;	ia5p = &((*ia5p) -> next);	result = error (sd, error_IMISC_unableToOpenFile, (caddr_t) ia5, rox,		    roi);	free_IMISC_IA5List (ia5);	return result;    }    while (read (ud, (char *) ut, sizeof *ut) == sizeof *ut) {	if (ut -> ut_name[0] == NULL)	    continue;	if ((dp = ctime (&ut -> ut_time)) == NULL)	    goto congested;	(void) sprintf (buffer, "%-*.*s %-*.*s %.12s",		NMAX, NMAX, ut -> ut_name, LMAX, LMAX, ut -> ut_line, dp + 4);#ifdef	BSD42	if (ut -> ut_host[0])	    (void) sprintf (buffer + strlen (buffer), "\t(%.*s)",		    HMAX, ut -> ut_host);#endif	if ((*ia5p = str2ia5list (buffer)) == NULL)	    goto congested;	ia5p = &((*ia5p) -> next);    }    (void) close (ud);#else    setutent ();    while (ut = getutent ()) {	if (ut -> ut_type != USER_PROCESS)	    continue;	if ((dp = ctime (&ut -> ut_time)) == NULL)	    goto congested;	(void) sprintf (buffer, "%-*.*s %-*.*s %.12s",		NMAX, NMAX, ut -> ut_name, LMAX, LMAX, ut -> ut_line,		dp + 4);	if ((*ia5p = str2ia5list (buffer)) == NULL)	    goto congested;	ia5p = &((*ia5p) -> next);    }    endutent ();#endif    if (RyDsResult (sd, rox -> rox_id, (caddr_t) ia5, ROS_NOPRIO, roi)	    == NOTOK)	ros_adios (&roi -> roi_preject, "RESULT");    free_IMISC_IA5List (ia5);    return OK;congested: ;    free_IMISC_IA5List (ia5);    return error (sd, error_IMISC_congested, (caddr_t) NULL, rox, roi);}/*  */#define	NBYTES	512#define	LINSIZ	72/* ARGSUSED */static int  op_charGen (sd, ryo, rox, in, roi)int	sd;struct RyOperation *ryo;struct RoSAPinvoke *rox;caddr_t	in;struct RoSAPindication *roi;{    register int    i,                    j;    register char  *dp,                   *de,                   *rs,                   *rp,                   *re;    char    line[LINSIZ + 1],            ring[BUFSIZ];    struct type_IMISC_IA5List *ia5;    register struct type_IMISC_IA5List **ia5p;    if (rox -> rox_nolinked == 0) {	advise (NULLCP, LOG_INFO,		"RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",		sd, ryo -> ryo_name, rox -> rox_linkid);	return ureject (sd, ROS_IP_LINKED, rox, roi);    }    if (debug)	advise (NULLCP, LOG_DEBUG, "RO-INVOKE.INDICATION/%d: %s",		sd, ryo -> ryo_name);    re = ring;    for (i = 0; i < 0x80; i++)	if (isprint (i))	    *re++ = i;    ia5 = NULL;    ia5p = &ia5;    for (rs = ring, i = NBYTES; i > 0; rs++, i -= j) {	if (rs >= re)	    rs = ring;	j = i > LINSIZ ? LINSIZ : i;	for (de = (dp = line) + j, rp = rs; dp < de; dp++, rp++) {	    if (rp >= re)		rp = ring;	    *dp = *rp;	}	*dp = NULL;	if ((*ia5p = str2ia5list (line)) == NULL)	    goto congested;	ia5p = &((*ia5p) -> next);    }    if (RyDsResult (sd, rox -> rox_id, (caddr_t) ia5, ROS_NOPRIO, roi)	    == NOTOK)	ros_adios (&roi -> roi_preject, "RESULT");    free_IMISC_IA5List (ia5);    return OK;congested: ;    free_IMISC_IA5List (ia5);    return error (sd, error_IMISC_congested, (caddr_t) NULL, rox, roi);}/*  */#define	NPASS	6/* ARGSUSED */static int  op_pwdGen (sd, ryo, rox, in, roi)int	sd;struct RyOperation *ryo;struct RoSAPinvoke *rox;caddr_t	in;struct RoSAPindication *roi;{    register int    i;    char    buffer[BUFSIZ];    struct type_IMISC_IA5List *ia5;    register struct type_IMISC_IA5List **ia5p;    if (rox -> rox_nolinked == 0) {	advise (NULLCP, LOG_INFO,		"RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",		sd, ryo -> ryo_name, rox -> rox_linkid);	return ureject (sd, ROS_IP_LINKED, rox, roi);    }    if (debug)	advise (NULLCP, LOG_DEBUG, "RO-INVOKE.INDICATION/%d: %s",		sd, ryo -> ryo_name);    ia5 = NULL;    ia5p = &ia5;    for (i = NPASS; i > 0; i--) {	if (pwdgen (buffer) == NOTOK)	    goto congested;	if ((*ia5p = str2ia5list (buffer)) == NULL)	    goto congested;	ia5p = &((*ia5p) -> next);    }    if (RyDsResult (sd, rox -> rox_id, (caddr_t) ia5, ROS_NOPRIO, roi)	    == NOTOK)	ros_adios (&roi -> roi_preject, "RESULT");    free_IMISC_IA5List (ia5);    return OK;congested: ;    free_IMISC_IA5List (ia5);    return error (sd, error_IMISC_congested, (caddr_t) NULL, rox, roi);}/*  *//* Based on an f77 algorithm supplied by Frank Wancho <Wancho@SIMTEL20>,   which was based on a basic algorithm by Paul D. Merillat and Arthur A. Key.   Strings returned are built by alternating vowels and consonants.   However, there are "Digraphs", and these are presorted according to   END, MIDDLE, and START positions.   Not going into combinatorial analysis (with 7 characters the "possible"   combinations exceed 20 million). */#define	TOT	54636577static struct pair {    char   *p_form;    int     p_value;} pairs[] = {	"cvcvcvce", 0,	"vcvcvcvc", 10827189,	"cpcpce", 13725209,	"dvcpce", 14036249,	"vcvcpce", 14327369,	"cvcpme", 15296369,	"dvcvcvc", 15746954,	"cpcvcvc", 16617618,	"cvmvcvc", 17547858,	"cvcpcvc", 23616474,	"cvcvmvc", 24546714,	"dpcvce", 30618378,	"dvmvce", 30908898,	"cpmvce", 32807107,	"vmvcvce", 34838173,	"vcpcvce", 41163763,	"vcvmvce", 42132163,	"vmvmvc", 48449078,	"vmpcvc", 51995642,	"vmvcpc", 52539386,	"vcvmpc", 52962661,	"vmpme", 53385611,	"dvmpc", 53648987,	"cpmpc", 53776002,	"cvcvcpc", 53912072,	NULL, TOT};	     static char *Mx;static char *Nx =		/* XXX */    "BBBCBFBKBLBMBNBPBTBVCCCDCFCMCPDBDCDDDFDGDKDLDMDNDPDTDVDWDZFBFCFDFGFKFMFNF\PFZGBGDGFGJGMGNGPGTGVKBKDKFKMKNKPKTKVKZLBLCLFLGLMLNLRLVLZMBMCMDMFMGMJMKMLMMMNM\RMTMVMZNBNCNFNOSZTBTCTDTFTGTJTKTLTMTNTPTVVCVGVLVPNJNLNPNRPCPDPFPGPKPMPNPVPZRBR\CRDRFRGRJRLSBSDSFSGSJSRSV";static char *Cx =		/* consonants */    "BCDFGHJKLMNPRSTVWZ";static char *Vx =		/* vowels */    "AEIOU";static char *Dx =		/* consonant pairs */    "BRCHCLCRDRFLFRGLGRKLKRPHPLPRQUSCSHSKSLSMSNSPSTSWTHTRTW";static char *Lx =		/* end-consonant pairs */    "BSCKCSCTDSFSFTGSHSKSLLLDLKLPLSLTMPMSNDNKNNNSNTPPPSPTRKRMRNRPRSSSTSVSWS";static char *Px =		/* vowel pairs */

⌨️ 快捷键说明

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