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

📄 uuxqt.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
      printmsg(0,"No command supplied for X.* file %s, skipped", fname);
      reject = TRUE;
   }

/*--------------------------------------------------------------------*/
/*           We have the data for this command; process it            */
/*--------------------------------------------------------------------*/

   if ( ! (skip || reject ))
   {
      if ( user == NULL )
      {
         user = strdup("uucp");    // User if none given
         checkref(user);
      }

      if (requestor == NULL)
      {
         requestor = strdup(user);
         checkref(requestor);
      }

      if (input == NULL)
         input = strdup("/dev/nul");

      if (output == NULL)
         output = mktempname(NULL, "OUT");

      printmsg(equaln(command,RMAIL,5) ? 2 : 0,
               "uuxqt: executing \"%s\" for user \"%s\" at  \"%s\"",
                   command, user, machine);

/*--------------------------------------------------------------------*/
/*             Create the environment and run the command             */
/*--------------------------------------------------------------------*/

      envp = create_environment("uucp", requestor);
      status = shell(command, input, output, remote, xflag );
      delete_environment(envp);

      ReportResults( status, input, output, command, job_id,
                     jtime, requestor, outnode, outname, xflag,
                     statfil, machine, user);

/*--------------------------------------------------------------------*/
/*                  Clean up files after the command                  */
/*--------------------------------------------------------------------*/

      if ( status > -2 )
      {
         unlink(fname);       // Already a local file name

         if (equaln(input,"D.",2))
         {
             importpath(hostfile, input, remote);
             unlink(hostfile);
         }

         if (xflag[X_OUTPUT])
         {
             importpath(hostfile, output, remote);
             unlink(hostfile);
         }

      } /* if ( status > -2 ) */

   }
   else if (reject && !skip)
        unlink(fname);       // Already a local file name

/*--------------------------------------------------------------------*/
/*              Free various temporary character strings              */
/*--------------------------------------------------------------------*/

   if (command    != NULL) free(command);
   if (input      != NULL) free(input);
   if (job_id     != NULL) free(job_id);
   if (outnode    != NULL) free(outnode);
   if (output     != NULL) free(output);
   if (requestor  != NULL) free(requestor);
   if (statfil    != NULL) free(statfil);
   if (user       != NULL) free(user);

} /* process */

/*--------------------------------------------------------------------*/
/*    s h e l l                                                       */
/*                                                                    */
/*    Simulate a Unix command                                         */
/*--------------------------------------------------------------------*/

static int shell(char *command,
                 const char *inname,
                 const char *outname,
                 const char *remotename,
                 boolean xflag[])
{
   int    result = 0;
   char   inlocal[FILENAME_MAX];
   char   outlocal[FILENAME_MAX];
   char   buf[255];

   char   *cmdname;
   char   *parameters;

   if (xflag[X_USEEXEC])
      printmsg(2, "exec(2) not supported, executing using spawn");

/*--------------------------------------------------------------------*/
/*         Determine the command name and parameters, if any          */
/*--------------------------------------------------------------------*/

   cmdname = strtok( command, WHITESPACE );
   parameters = strtok( NULL, "\r\n" );

   if ( parameters != NULL )
   {
      while (isspace( *parameters ) || iscntrl( *parameters ))
         parameters++;

      if ( !strlen( parameters ))
         parameters = NULL;

   } /* if ( parameters != NULL ) */

/*--------------------------------------------------------------------*/
/*    Verify we support the command, and get it's real name, if so    */
/*--------------------------------------------------------------------*/

   if ( (!equal(remotename, E_nodename)) && (!ValidateCommand( cmdname )) )
   {
      printmsg(0,"Command \"%s\" not allowed at this site", cmdname);
      xflag[E_NOEXE] = TRUE;
      return 99;
   }

/*--------------------------------------------------------------------*/
/*                     Open files for processing                      */
/*--------------------------------------------------------------------*/

   if (inname != NULL)
      importpath(inlocal, inname, remotename);

   if ( outname != NULL )
      importpath(outlocal, outname, remotename);

/*--------------------------------------------------------------------*/
/*               We support the command; execute it                   */
/*--------------------------------------------------------------------*/

   fflush(logfile);

/*--------------------------------------------------------------------*/
/*               RNEWS may be special, handle it if so                */
/*--------------------------------------------------------------------*/

   if (equal(cmdname,RNEWS) &&
       bflag[F_WINDOWS] &&
       ( inname != NULL ))       // rnews w/input?
   {
      strcpy( buf, "-f " );
      strcat( buf, inlocal );
      parameters = buf;          // We explicitly ignore all parameters
                                 // on the RNEWS command

      result = execute( RNEWS,
                        buf,
                        NULL,
                        outname == NULL ? NULL : outlocal,
                        TRUE,
                        FALSE );
   }

/*--------------------------------------------------------------------*/
/*        RMAIL is special, we need to break up the parameters        */
/*--------------------------------------------------------------------*/

   else if (equal(cmdname,RMAIL) && ( inname != NULL )) // rmail w/input?
   {
      parameters = strtok( parameters, WHITESPACE );

      while (( parameters != NULL ) && (result != -1 ))
      {

         boolean firstPass = TRUE;
         int left = 0;

#if defined(__OS2__) || defined(WIN32)
         int rlen =  254 ;
#elif defined(__TURBOC__)
         int rlen =  126 ;
#else
         int rlen = (_osmode == DOS_MODE) ? 126 :  254;
#endif

#ifdef _Windows
         if ( bflag[F_WINDOWS] )
         {
            strcpy( buf, "-f ");
            strcat( buf, inlocal);
            strcat( buf, " ");
         }
         else
            *buf = '\0';
#else
         *buf = '\0';
#endif
         rlen -= strlen( buf ) + strlen( RMAIL ) + 1;

/*--------------------------------------------------------------------*/
/*                   Copy addresses into the buffer                   */
/*--------------------------------------------------------------------*/

         left = rlen - strlen( parameters );

         while ((parameters != NULL) && (left > 0))
         {
            char *next = strtok( NULL, "");

            if ( *parameters == '-')   // Option flag for mail?
               printmsg(0,"Disallowed option %s ignored",parameters);
            else {                     // Not option, add to param list
               strcat( buf, " ");
               strcat( buf, parameters );
               rlen -= strlen( parameters ) + 1;
               firstPass = FALSE;
            }

/*--------------------------------------------------------------------*/
/*                       Step to next parameter                       */
/*--------------------------------------------------------------------*/

            if ( next == NULL )
               parameters = NULL;
            else
               parameters = strtok( next, WHITESPACE );

         } /* while ( parameters != NULL ) */

         if (firstPass)       // Did we process at least one addr?
         {                    // No --> Serious problem!
            printmsg(0,
                     "Address \"%s\" too long (%d chars)!  %d available, short fall would be %d",
                      parameters,
                      strlen(parameters),
                      rlen,
                      left );

            panic();
         } /* if (*buf = '\0') */

      } /* while */

/*--------------------------------------------------------------------*/
/*               Execute one command line of addresses                */
/*--------------------------------------------------------------------*/

      result = execute( RMAIL,
                        buf,
                        bflag[F_WINDOWS] ? NULL : inlocal,
                        outname == NULL ? NULL : outlocal,
                        TRUE,
                        FALSE );

      if ( result != 0 )    // Did command execution fail?
      {
         printmsg(0,"shell: command \"%s %s\" returned error code %d",
               cmdname, buf, result);
         panic();
      }

   } /* if (equal(cmdname,RMAIL) && ( inname != NULL )) */
   else
      result = execute( command,
                        parameters,
                        inlocal,
                        outlocal,
                        TRUE,
                        FALSE );

/*--------------------------------------------------------------------*/
/*                    Determine result of command                     */
/*--------------------------------------------------------------------*/

   if ( result == 0 )
      xflag[E_NORMAL] = TRUE;
   else if ( result > 0 )
      xflag[E_STATUS] = TRUE;

   fflush(logfile);

   return result;

} /* shell */

/*--------------------------------------------------------------------*/
/*    u s a g e                                                       */
/*                                                                    */
/*    Report how to run this program                                  */
/*--------------------------------------------------------------------*/

static void usage( void )
{
   fputs("Usage:\tuuxqt\t[-xDEBUG] [-sSYSTEM]", stderr);
   exit(1);
} /* usage */

/*--------------------------------------------------------------------*/
/*    c o p y l o c a l                                               */
/*                                                                    */
/*    Copy Local Files                                                */
/*--------------------------------------------------------------------*/

static boolean copylocal(const char *from, const char *to)
{
      int  fd_from, fd_to;
      int  nr;
      int  nw = -1;
      char buf[BUFSIZ];            // faster if we alloc a big buffer

      /* This would be even faster if we determined that both files
         were on the same device, dos >= 3.0, and used the dos move
         function */

      if ((fd_from = open(from, O_RDONLY | O_BINARY)) == -1)
         return FALSE;        // failed

      /* what if the to is a directory? */
      /* possible with local source & dest uucp */

      if ((fd_to = open(to, O_CREAT | O_BINARY | O_WRONLY, S_IWRITE | S_IREAD)) == -1) {
         close(fd_from);
         return FALSE;        // failed
         /* NOTE - this assumes all the required directories exist!  */
      }

      while  ((nr = read(fd_from, buf, sizeof buf)) > 0 &&
         (nw = write(fd_to, buf, nr)) == nr)
         ;

      close(fd_to);
      close(fd_from);

      if (nr != 0 || nw == -1)
         return FALSE;        // failed in copy
      return TRUE;
} /* copylocal */

/*--------------------------------------------------------------------*/
/*    c r e a t e _ e n v i r o n m e n t                             */
/*                                                                    */
/*    Create the environment array for subprocesses                   */
/*--------------------------------------------------------------------*/

char **create_environment(const char *logname,
                          const char *requestor)
{
   char buffer[MAXADDR + 20];
   int subscript = 0;
   char **envp = (char **) malloc(sizeof(char *) * 3);

   checkref(envp);

/*--------------------------------------------------------------------*/
/*              "Current" user id processing the request              */
/*--------------------------------------------------------------------*/

   if ( logname != NULL )
   {
     sprintf(buffer,"%s=%s", LOGNAME, logname);
     envp[subscript] = strdup(buffer);

⌨️ 快捷键说明

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