Ejemplo n.º 1
0
void iosFdShow (void)
    {
    char *stin;
    char *stout;
    char *sterr;
    FD_ENTRY *pFdEntry;
    int fd;
    int xfd;

    printf ("%3s %-20s %3s\n", "fd", "name", "drv");

    for (fd = 0; fd < maxFiles; fd++)
	{
	pFdEntry = &fdTable [fd];
	if (pFdEntry->inuse)
	    {
	    xfd = STD_FIX(fd);

	    stin  = (xfd == ioGlobalStdGet (STD_IN))  ? "in"  : "";
	    stout = (xfd == ioGlobalStdGet (STD_OUT)) ? "out" : "";
	    sterr = (xfd == ioGlobalStdGet (STD_ERR)) ? "err" : "";

	    printf ("%3d %-20s %3d %s %s %s\n",
		    xfd,
		    (pFdEntry->name == NULL) ? "(unknown)" : pFdEntry->name,
		    pFdEntry->pDevHdr->drvNum, stin, stout, sterr);
	    }
	}
    }
Ejemplo n.º 2
0
STATUS shellParserControl
    (
    UINT32 remoteEvent,	/* Starting or stopping a connection? */
    UINT32 sessionId, 	/* Unique identifier for each session */
    UINT32 slaveFd      /* File descriptor for character i/o  */
    )
    {

    if ((taskNameToId ("tShell")) == ERROR)   /* Shell not started yet. */
        return (ERROR);

    if (remoteEvent == REMOTE_START)
        {
        /* Handle a new telnet or rlogin session. */

        if (remoteId != 0)    /* Failed request - only one session allowed. */
            return (ERROR); 

        if (!shellLock (TRUE)) 	/* Shell is not available. */
            {
	    fdprintf (slaveFd, "The shell is currently in use.\n");
            return (ERROR);
            }

        /* Let the user try to login */
	if (shellLogin (slaveFd) != OK)
	    { 
 	    shellLock (FALSE);
            return (ERROR);
            }

        /* setup the slave device to act like a terminal */

        (void) ioctl (slaveFd, FIOOPTIONS, OPT_TERMINAL);

        shellLogoutInstall ((FUNCPTR) telnetdExit, sessionId);

        /* get the shell's standard I/O fd's so we can restore them later */

        shellInFd  = ioGlobalStdGet (STD_IN);
        shellOutFd = ioGlobalStdGet (STD_OUT);
        shellErrFd = ioGlobalStdGet (STD_ERR);

        /* set shell's standard I/O to new device; add extra logging device */

        shellOrigStdSet (STD_IN, slaveFd);
        shellOrigStdSet (STD_OUT, slaveFd);
        shellOrigStdSet (STD_ERR, slaveFd);

        logFdAdd (slaveFd);
        logFdFromRlogin = slaveFd;      /* store new fd for logFdSet() */

        /* Store the session identifier. */

        remoteId = sessionId;

        /* notify the shell we have started a remote session */
        
        shellIsRemoteConnectedSet (TRUE);

        printErr ("\ntelnetd: This system *IN USE* via telnet.\n");

        /* Prevent network denial of service attacks by waiting a second */

        taskDelay (sysClkRateGet() / 2); 
       
        /* Restart the shell to access the redirected file descriptors. */

        excJobAdd (shellRestart, TRUE, 0, 0, 0, 0, 0);

        return (OK);
        }
    else if (remoteEvent == REMOTE_STOP)
        {
        /*
         * End an active telnet or rlogin session. This event occurs
         * after the server closes the socket.
         */

        if (remoteId != sessionId)    /* Unknown remote session. */
            return (ERROR);

        shellLogoutInstall ((FUNCPTR) NULL, 0);  /* remove logout function */

        if (logFdFromRlogin != NONE)
            {
            logFdDelete (logFdFromRlogin);       /* cancel extra log device */
            logFdFromRlogin = NONE;              /* reset fd */
            }

        shellOrigStdSet (STD_IN,  shellInFd);    /* restore shell's stnd I/O */
        shellOrigStdSet (STD_OUT, shellOutFd);
        shellOrigStdSet (STD_ERR, shellErrFd);

        shellLock (FALSE);                       /* unlock shell */

        /*
         * For typical remote sessions, restoring the standard I/O
         * descriptors is enough to reconnect the shell to the console
         * because closing the pty device will cause the shell to unblock
         * from its read() and use the restored descriptors. However,
         * problems can occur upon logout if the remote user has disabled
         * the line editor and/or put the pty device in raw mode, so the
         * shell is restarted in all cases.
         */

        remoteId = 0;    /* Allow a new session. */

       /* notify the shell we have ended a remote session */
        
        shellIsRemoteConnectedSet (FALSE);

        excJobAdd (shellRestart, FALSE, 0, 0, 0, 0, 0);

        return (OK);
        }

    return (ERROR);    /* Ignore unknown control operations. */
    }
Ejemplo n.º 3
0
/*******************************************************************************
*
* remShellTelnetConn - connect shell to telnet
*
* This routine is called by the telnet demon to connect the shell with the 
* remote telnet user.
* Remote telnet requests will cause `stdin', `stdout', and `stderr' to be stolen
* away from the console.  When the remote user disconnects, `stdin', `stdout',
* and `stderr' are restored, and the shell is restarted.
*
* RETURNS: OK or ERROR.
*/
STATUS remShellTelnetConn
    (
    int              interpConnArg,	/* argument for interpConn () */
    int              slaveFd,
    int              exitArg,		/*  */
    int *            disconnArg,
    char *           msg
    )
    {
    /* wait for shell to exist */

    while (taskNameToId (telnetShellName) == ERROR)
        taskDelay (sysClkRateGet ());

    /* check to see if there's already an active connection */

    if (activeFlag)
        {
        strcpy(msg, "\r\nSorry, this system is engaged.\r\n");

        return ERROR;
        }

    if (!shellLock (TRUE))
	{
	strcpy(msg, "\r\nSorry, shell is locked.\r\n");

	printErr ("telnetd: someone tried to login into.\n");
        return ERROR;
	}

    printErr ("\ntelnetd: This system *IN USE* via telnet.\n");

    shellLogoutInstall ((FUNCPTR) telnetdExit, exitArg);
    activeFlag    = TRUE;

    /* get the shell's standard I/O fd's so we can restore them later */

    shellInFd  = ioGlobalStdGet (STD_IN);
    shellOutFd = ioGlobalStdGet (STD_OUT);
    shellErrFd = ioGlobalStdGet (STD_ERR);

#ifndef BROADCOM_DEBUG
#if VX_VERSION == 55 || VX_VERSION == 542
    /* set shell's standard I/O to pty device; add extra logging device */

    shellOrigStdSet (STD_IN, slaveFd);
    shellOrigStdSet (STD_OUT, slaveFd);
    shellOrigStdSet (STD_ERR, slaveFd);

    logFdAdd (slaveFd);
    logFdFromRlogin = slaveFd;      /* store pty fd for logFdSet() */
#endif
#endif	/* BROADCOM_DEBUG */

    /* the shell is currently stuck in a read from the console, so we
     * restart it */

#ifndef BROADCOM_DEBUG
#if (_WRS_VXWORKS_MAJOR >= 6) 
    excJobAdd((VOIDFUNCPTR)shellRestart,
                  (int)CURRENT_SHELL_SESSION , 0, 0, 0, 0, 0);
#else
    excJobAdd (shellRestart, TRUE, 0, 0, 0, 0, 0);
#endif
#else
    sp (copyStreams, slaveFd, slaveFd,0,0,0,0,0,0,0); /* !!! */
#endif	/* BROADCOM_DEBUG */

    (void) ioctl (slaveFd, FIOFLUSH, 0 /*XXX*/);

    return OK;
    } /* remShellTelnetConn */
Ejemplo n.º 4
0
Archivo: iosShow.c Proyecto: phoboz/vmx
void iosFdShow(
    void
    )
{
    int i, fd;
    FD_ENTRY *pFd;
    char inStr[3], outStr[3], errStr[3];
    char name[80];

    printf("%3s %-20s %3s\n", "fd", "name", "drv");

    for (i = 0; i < iosMaxFd; i++)
    {
        pFd = &iosFdTable[i];
        if (pFd->used == TRUE)
        {
            fd = STD_FIX(i);

            /* Get filedescriptor names */
            if (fd == ioGlobalStdGet(STDIN_FILENO))
            {
                strcpy(inStr, "in");
            }
            else
            {
                strcpy(inStr, "");
            }

            if (fd == ioGlobalStdGet(STDOUT_FILENO))
            {
                strcpy(outStr, "out");
            }
            else
            {
                strcpy(outStr, "");
            }

            if (fd == ioGlobalStdGet(STDERR_FILENO))
            {
                strcpy(errStr, "err");
            }
            else
            {
                strcpy(errStr, "");
            }

            if (pFd->name == NULL)
            {
                strcpy(name, "(unknown)");
            }
            else
            {
                strcpy(name, pFd->name);
            }

            printf(
                "%3d %-20s %3d %s %s %s\n",
                fd,
                name,
                pFd->pDevHeader->drvNumber,
                inStr,
                outStr,
                errStr
                );
        }
    }
}
Ejemplo n.º 5
0
/*****************************************************************************
* 函 数 名     :  cshell_direction
*
* 功能描述  : 改变cshell的方向
*
* 输入参数  :  cshell_mode_tpye mode :
*                           CSHELL_MODE_UART : 切换到UART
*                           CSHELL_MODE_USB   : 切换到USB
* 输出参数  :  无
*
* 返 回 值     :  无
*
* 修改记录  :
*****************************************************************************/
int cshell_direction(cshell_mode_tpye mode)
{
    int key = 0;
    int fd = 0;
    SHELL_ID ShellID;
    char ttyFg[16] = {0x00};
    char ttyBg[16] = {0x00};
    SHELL_IO_CHAN *ptr_shell = &shell_io_channel;
	SRAM_SMALL_SECTIONS * sram = (SRAM_SMALL_SECTIONS * )SRAM_SMALL_SECTIONS_ADDR;

    if ((cshell_mode_tpye)(ptr_shell->shell_mode) == mode)
    {
		cshell_print_error("C:no need to redirect cshell!\n");
        return OK;
    }

    if (CSHELL_MODE_UART == mode)
    {
        /* coverity[secure_coding] */
        sprintf(ttyFg, "/tyCo/0");
        /* coverity[secure_coding] */
        sprintf(ttyBg, "/tyCo/3");
    }
    else if (CSHELL_MODE_USB == mode)
    {
        /* coverity[secure_coding] */
        sprintf(ttyFg, "/tyCo/3");
        /* coverity[secure_coding] */
        sprintf(ttyBg, "/tyCo/0");
    }
    else
    {
		cshell_print_error("C:redirect parm error[%d]!\n", mode);
        return ERROR;
    }
	if (CSHELL_MODE_UART == mode)
		intEnable((int)sram->UART_INFORMATION[1].interrupt_num);
    else
    {
        /* 禁止串口中断,M核心采用UART */
   	    intDisable((int)sram->UART_INFORMATION[1].interrupt_num);
    }

    key = intLock();
    //taskLock();

    /* 关闭Shell当前使用的串口 */
    fd = ioGlobalStdGet(STD_IN);
    (void)ioctl (fd, FIOSETOPTIONS, OPT_RAW);
    close(fd);

    ShellID = shellFromTaskGet(shellConsoleTaskId);
    shellTerminate(ShellID);/* [false alarm]:误报 */

    if (0 != (fd = open(ttyFg, O_RDWR, 0)))/* [false alarm]:误报 */
    {
        /* 切换成功 */
        ptr_shell->shell_mode = mode;
    }
    else
    {
        /* 切换失败 */
        fd = open(ttyBg, O_RDWR, 0);
        if (0 == fd)
        {
            //taskUnlock();
            intUnlock(key);
            return ERROR;
        }
    }

    /* coverity[noescape] */
    (void)ioctl (fd, FIOSETOPTIONS, OPT_TERMINAL);

    /* coverity[noescape] */
    ioGlobalStdSet (STD_OUT, fd);
    /* coverity[noescape] */
    ioGlobalStdSet (STD_IN,  fd);
    /* coverity[noescape] */
    ioGlobalStdSet (STD_ERR, fd);

    //taskUnlock();
    intUnlock(key);

    usrShell();

    return OK;
}