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

📄 uuxqt.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
     checkref(envp[subscript++]);
   }

/*--------------------------------------------------------------------*/
/*               user id/nodename of original requestor               */
/*--------------------------------------------------------------------*/

   if ( requestor != NULL )
   {
      sprintf(buffer,"%s=%s",UU_USER, requestor);
      envp[subscript] =  strdup(buffer);
      checkref(envp[subscript++]);
   }

   envp[subscript] =  NULL;   // Terminate the list

/*--------------------------------------------------------------------*/
/*               Now put the data into our environment                */
/*--------------------------------------------------------------------*/

   while( subscript-- > 0)
   {
      if (putenv( envp[subscript] ))
      {
         printmsg(0,"Unable to set environment \"%s\"",envp[subscript]);
         panic();
      }
   } /* while */

   return envp;
} /* create_environment */

/*--------------------------------------------------------------------*/
/*    d e l e t e  _ e n v i r o n m e n t                            */
/*                                                                    */
/*    Delete variables inserted by create_enviroment                  */
/*                                                                    */
/*    Our environment goes away when we are done executing we; just   */
/*    clean up the environment because we are freeing the storage     */
/*--------------------------------------------------------------------*/

static void delete_environment( char **envp )
{
   int subscript = 0;

   while ( envp[subscript] != NULL )
   {
      char *equal = strchr(envp[subscript]  , '=' );
      *++equal = '\0';        // Terminate the string
      if (putenv( envp[subscript] ))
      {
         printmsg(0,"Unable to reset environment \"%s\"",envp[subscript]);
         panic();
      }
      free( envp[subscript++] );
   }

   free( envp );
} /* delete_environment */


/*--------------------------------------------------------------------*/
/*    d o _ c o p y                                                   */
/*                                                                    */
/*    Send a file to remote node via uucp                             */
/*--------------------------------------------------------------------*/

static boolean do_copy(char *localfile,
                       const char *rmtsystem,
                       const char *remotefile,
                       const char *requestor,
                       const boolean success )
{
      if (rmtsystem == NULL) {
          copylocal(localfile, remotefile);
      } else {
          char    tmfile[FILENAME_MAX];  // Unix style name for c file
          char    idfile[FILENAME_MAX];  // Unix style name for data file copy
          char    work[FILENAME_MAX]; // temp area for filename hacking
          char    icfilename[FILENAME_MAX];  // our hacked c file path
          char    idfilename[FILENAME_MAX];  // our hacked d file path

          struct  stat    statbuf;

          long    int     sequence;
          static  char    subseq = 'A';
          char   *sequence_s;
          FILE   *cfile;


          sequence = getseq();
          sequence_s = JobNumber( sequence );

          sprintf(tmfile, spool_fmt, 'C', rmtsystem, 'Z', sequence_s);
          importpath(work, tmfile, rmtsystem);
          mkfilename(icfilename, E_spooldir, work);

          if (stat((char *) localfile, &statbuf) != 0)  {
              printerr( localfile );
              return FALSE;
          }

          sprintf(idfile , dataf_fmt, 'D', E_nodename, sequence_s,
                  (char) subseq++ );
          importpath(work, idfile, rmtsystem);
          mkfilename(idfilename, E_spooldir, work);

          if (!copylocal(localfile, idfilename))  {
             printmsg(0, "Copy \"%s\" to \"%s\" failed", localfile, idfilename);
             return FALSE;
          }

          if ((cfile = FOPEN(icfilename, "a",TEXT_MODE)) == NULL)  {
             printerr( icfilename );
             printf("cannot append to %s\n", icfilename);
             return FALSE;
          }

          fprintf(cfile, send_cmd, localfile, remotefile,
                   "uucp" , success ? "n" : " ", idfile,
                    success ? requestor : " ");

          fclose(cfile);
    };

    return TRUE;
} /* do_copy */

/*--------------------------------------------------------------------*/
/*    R e p o r t R e s u l t s                                       */
/*                                                                    */
/*    report results of command execution as specified by flags in    */
/*    X.* file.                                                       */
/*--------------------------------------------------------------------*/

static void ReportResults(const int status,
                          const char *input,
                                char *output,
                          const char *command,
                          const char *job_id,
                          const time_t jtime,
                          const char *requestor,
                          const char *outnode,
                          const char *outname,
                          const boolean xflag[],
                          const char *statfil,
                          const char *machine,
                          const char *user)
{
     char address[MAXADDR];
     char subject[80];
     FILE *mailtmp = NULL;
     char *tempmail;


     if (!(xflag[X_FAILED] | xflag[X_SUCCESS] |
           xflag[X_INPUT]  | xflag[X_STATFIL]))
     {  /* default actions */
         unlink(output);
         return;
     }

     tempmail = mktempname(NULL, "TMP");

     if ((mailtmp = FOPEN(tempmail, "w+", BINARY_MODE)) == NULL) {
         printerr(tempmail);
         return;
     }

     sprintf(subject, "\"[uucp job %s (%s)]\"", job_id, dater(jtime, NULL) );

     fprintf(mailtmp,"remote execution\n");
     fprintf(mailtmp,"%s\n", command);

#ifdef BETA_TEST
     strcpy(address,"postmaster");
#else
     if (equal(machine, E_nodename))
        strcpy(address, requestor);
     else
        sprintf(address,"%s!%s", machine, requestor);
#endif

     if (xflag[E_NORMAL])
     {                        // command succeded, process appropriate flags

       fprintf(mailtmp,"exited normally\n");

       if (xflag[X_OUTPUT])
           do_copy(output, outnode, outname, requestor, xflag[X_SUCCESS]);
       else
           unlink(output);

       fclose(mailtmp);

       if (xflag[X_SUCCESS]) {
          if (xflag[X_STATFIL]) {
              do_copy(tempmail, outnode, statfil, requestor, xflag[X_SUCCESS]);
          } else {
              MailStatus(tempmail, address, subject);
          }
       };

   } else {            /* command failed, process appropriate flags   */
     if (xflag[E_NOACC])
         fprintf(mailtmp,"file access denied to %s!%s", machine, user);
     else if (xflag[E_NOEXE])
        fprintf(mailtmp,"execution permission denied to %s!%s\n",
                machine, requestor);
     else if (xflag[E_SIGNAL])
        fprintf(mailtmp,"terminated by signal\n");
     else if (xflag[E_STATUS])
        fprintf(mailtmp,"exited with status %d\n", status);
     else /* xflag->e & E_FAILED */
        fprintf(mailtmp,"failed completely\n");


     if (xflag[E_STATUS]) {
       if ((xflag[X_FAILED]) && !(xflag[X_INPUT])) {
           fprintf(mailtmp,"===== error output not available =====\n");
       } else if ((xflag[X_FAILED]) && (xflag[X_INPUT])) {
           fprintf(mailtmp,"===== stdin was ");

           if (xflag[S_CORRUPT])
               fprintf(mailtmp,"unreadable =====\n");
           else if (xflag[S_EMPTY])
               fprintf(mailtmp,"empty =====\n");
           else if (xflag[S_NOREAD])
               fprintf(mailtmp,"denied read permission =====\n");
           else {
               fprintf(mailtmp,"=====\n");
               AppendData( input, mailtmp);
           };
           unlink(input);

           fprintf(mailtmp,"===== stderr is unavailable =====\n");
       }
     }

     fclose(mailtmp);

     if (xflag[X_STATFIL]) {
         do_copy(tempmail, outnode, statfil, requestor, xflag[X_SUCCESS]);
     } else {
         MailStatus(tempmail, address, subject);
     }

   }

   if (xflag[X_OUTPUT])
       unlink(output);

   unlink(tempmail);
   return;
} /* ReportResults */

/*--------------------------------------------------------------------*/
/* A p p e n d D a t a                                                */
/*                                                                    */
/* Append data to output file                                         */
/*--------------------------------------------------------------------*/

static boolean AppendData( const char *input, FILE* dataout)
{
   FILE    *datain;
   char     buf[BUFSIZ];
   boolean  status = TRUE;

/*--------------------------------------------------------------------*/
/*                      Verify the input opened                       */
/*--------------------------------------------------------------------*/

   if (input == NULL)
      return FALSE;
   else
      datain = FOPEN(input, "r",TEXT_MODE);

   if (datain == NULL) {
      printerr(input);
      printmsg(0,"Unable to open input file \"%s\"", input);
      return FALSE;
   } /* datain */

/*--------------------------------------------------------------------*/
/*                       Loop to copy the data                        */
/*--------------------------------------------------------------------*/

   while (fgets(buf, BUFSIZ, datain) != 0)
   {
      if (fputs(buf, dataout) == EOF)     // I/O error?
      {
         printmsg(0,"AppendData: I/O error on output file");
         printerr("dataout");
         fclose(datain);
         return FALSE;
      } /* if */
   } /* while */

/*--------------------------------------------------------------------*/
/*                      Close up shop and return                      */
/*--------------------------------------------------------------------*/

   if (ferror(datain))        // Clean end of file on input?
   {
      printerr(input);
      clearerr(datain);
      status = FALSE;
   }

   fclose(datain);
   return status;

} /* AppendData */

/*--------------------------------------------------------------------*/
/*    M a i l S t a t u s                                             */
/*                                                                    */
/*    Send text in a mailbag file to address(es) specified by line.   */
/*--------------------------------------------------------------------*/

static boolean MailStatus(char *tempfile,
                          char *address,
                          char *subject)
{
   boolean status;
   char **envp;
   char buf[BUFSIZ];

/*--------------------------------------------------------------------*/
/*                            Invoke RMAIL                            */
/*--------------------------------------------------------------------*/

   envp = create_environment( "uucp", NULL );

   strcpy(buf, "-w -f " );
   strcat(buf, tempfile );
   if ( subject != NULL )
   {
      strcat(buf, " -s " );
      strcat(buf, subject );
   }
   strcat( buf, " " );
   strcat( buf, address );

   status = execute( RMAIL, buf, NULL, NULL, TRUE, FALSE );

   delete_environment( envp );

/*--------------------------------------------------------------------*/
/*                       Report errors, if any                        */
/*--------------------------------------------------------------------*/

   if ( status < 0 )
   {
      printerr( RMAIL );
      printmsg(0,"Unable to execute rmail; status not delivered.");
   }
   else if ( status > 0 )
      printmsg(0, "Rmail returned error;\
 status delivery may be incomplete.");

/*--------------------------------------------------------------------*/
/*                          Return to caller                          */
/*--------------------------------------------------------------------*/

   return (status == 0 );

} /*MailStatus*/

⌨️ 快捷键说明

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