コード例 #1
0
ファイル: verify.c プロジェクト: Zatara7/CS311-Assignment-4
int verify_files( FILE *master, FILE *student ) {
  unsigned int mismatched, total;

  // Check if we are reading from an actual student file or from the program
  // output.
  if ( !student ) {
    student = stdin;
  }

  mismatched = 0;
  total = 0;

  // Read through all lines of master and student in compare them while keeping
  // track of both the number of mismatches and total number of comparisons.
  
  // Reading from stdin
  if ( student == stdin ) {
    while ( !feof( master ) ) {
      fgets(line_master, MAX_LINE_LEN, master);
      fgets(line_student, MAX_LINE_LEN, student);
      mismatched += verify_line( line_master, line_student );
      total++;
    }
  }
  // Reading from files.
  else {
    // Make sure next line read isn't NULL
    while ( fgets(line_master, MAX_LINE_LEN, master) && 
        fgets(line_student, MAX_LINE_LEN, student) ) {
      mismatched += verify_line( line_master, line_student );
      total++;
    }
  }

  // Print out the mismatches and a status of whether the verification was
  // successful or not.
  printf("Number correct / Total compared: %d/%d\n", total-mismatched, total);
  if ( mismatched ) {
    printf( ANSI_COLOR_RED      "Failed.\n"     ANSI_COLOR_RESET);
  }
  else {
    printf( ANSI_COLOR_GREEN    "Success.\n"    ANSI_COLOR_RESET);
  }

  return ( mismatched );
}
コード例 #2
0
ファイル: analyzer.c プロジェクト: resfilter/aldl-analyzer
void parse_line(char *line) {
  /* verify line integrity */
  if(verify_line(line) == 0) return;

  /* BRANCHING TO PER-LINE ANALYZERS HERE --------- */
  log_blm(line);
  log_knock(line);
  log_afr(line);
}
コード例 #3
0
ファイル: git-evtag.c プロジェクト: tyll/git-evtag
static gboolean
git_evtag_builtin_verify (struct EvTag *self, int argc, char **argv, GCancellable *cancellable, GError **error)
{
  gboolean ret = FALSE;
  int r;
  gboolean verified = FALSE;
  GOptionContext *optcontext;
  git_oid tag_oid;
  git_object *obj = NULL;
  char *long_tagname = NULL;
  git_tag *tag;
  const char *tagname;
  const char *message;
  git_oid specified_oid;
  const char *nl;
  guint64 elapsed_ns;
  const char *expected_checksum;
  char commit_oid_hexstr[GIT_OID_HEXSZ+1];
  char tag_oid_hexstr[GIT_OID_HEXSZ+1];
  char *git_verify_tag_argv[] = {"git", "verify-tag", NULL, NULL };
  
  optcontext = g_option_context_new ("TAGNAME - Verify a signed tag");

  if (!option_context_parse (optcontext, verify_options, &argc, &argv,
                             cancellable, error))
    goto out;

  if (argc < 2)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "A TAGNAME argument is required");
      goto out;
    }
  else if (argc > 2)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Too many arguments");
      goto out;
    }

  tagname = argv[1];

  long_tagname = g_strconcat ("refs/tags/", tagname, NULL);

  r = git_reference_name_to_id (&tag_oid, self->top_repo, long_tagname);
  if (!handle_libgit_ret (r, error))
    goto out;
  r = git_tag_lookup (&tag, self->top_repo, &tag_oid);
  if (!handle_libgit_ret (r, error))
    goto out;
  r = git_tag_target (&obj, tag);
  if (!handle_libgit_ret (r, error))
    goto out;
  specified_oid = *git_object_id (obj);

  git_oid_fmt (commit_oid_hexstr, &specified_oid);
  commit_oid_hexstr[sizeof(commit_oid_hexstr)-1] = '\0';

  if (!validate_at_head (self, &specified_oid, error))
    goto out;

  message = git_tag_message (tag);

  if (!git_oid_tostr (tag_oid_hexstr, sizeof (tag_oid_hexstr), git_tag_id (tag)))
    g_assert_not_reached ();
  
  if (!opt_no_signature)
    {
      git_verify_tag_argv[2] = tag_oid_hexstr;
      if (!spawn_sync_require_success (git_verify_tag_argv, G_SPAWN_SEARCH_PATH, error))
        goto out;
    }

  if (!checksum_commit_recurse (self, &specified_oid, &elapsed_ns,
                                cancellable, error))
    goto out;

  expected_checksum = g_checksum_get_string (self->checksum);
  
  while (TRUE)
    {
      nl = strchr (message, '\n');

      if (g_str_has_prefix (message, EVTAG_SHA512))
        {
          char *line;
          if (nl)
            line = g_strndup (message, nl - message);
          else
            line = g_strdup (message);
              
          g_strchomp (line);

          if (!verify_line (expected_checksum, line, commit_oid_hexstr, error))
            goto out;
              
          {
            char *stats = get_stats (self);
            g_print ("%s\n", stats);
            g_free (stats);
          }
          g_print ("Successfully verified: %s\n", line);
          verified = TRUE;
          break;
        }
          
      if (!nl)
        break;
      message = nl + 1;
    }
  
  if (!verified)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Failed to find %s in tag message",
                   EVTAG_SHA512);
      goto out;
    }

  ret = TRUE;
 out:
  return ret;
}
コード例 #4
0
ファイル: ident.c プロジェクト: ltworf/xinetd
/*
 * This function always runs in a forked process.
 */
idresult_e log_remote_user( const struct server *serp, unsigned timeout )
{
    static char         buf[ IBUFSIZE ] ;
    int                 cc ;
    union xsockaddr     sin_local, sin_remote, sin_contact, sin_bind;
    volatile unsigned   local_port;
    volatile unsigned   remote_port;
    int                 sd ;
    socklen_t           sin_len ;
    char               *p ;
    const char         *func = "log_remote_user" ;

    if ( timeout && signal( SIGALRM, sigalrm_handler ) == SIG_ERR )
    {
        msg( LOG_ERR, func, "signal: %m" ) ;
        return( IDR_ERROR ) ;
    }

    /*
     * Determine local and remote addresses
     */
    sin_len = sizeof( sin_local ) ;
    if ( getsockname( SERVER_FD( serp ), &sin_local.sa, &sin_len ) == -1 )
    {
        msg( LOG_ERR, func, "(%d) getsockname: %m", getpid() ) ;
        return( IDR_ERROR ) ;
    }

    if ( CONN_XADDRESS( SERVER_CONNECTION( serp ) ) == NULL )
    {
        /*
         * This shouldn't happen since identification only works for
         * connection-based services.
         */
        msg( LOG_ERR, func, "connection has no address" ) ;
        return( IDR_ERROR ) ;
    }

    CLEAR( sin_contact );
    sin_remote = *CONN_XADDRESS( SERVER_CONNECTION( serp ) ) ;
    sin_contact = sin_remote;
    memcpy( &sin_bind, &sin_local, sizeof(sin_bind) ) ;
    local_port = 0;
    remote_port = 0;
    if( sin_remote.sa.sa_family == AF_INET ) {
        local_port = ntohs( sin_local.sa_in6.sin6_port ) ;
        remote_port = ntohs( sin_remote.sa_in6.sin6_port ) ;
        sin_contact.sa_in6.sin6_port = htons( IDENTITY_SERVICE_PORT ) ;
        sin_bind.sa_in.sin_port = 0 ;
    } else if( sin_remote.sa.sa_family == AF_INET6 ) {
        local_port = ntohs( sin_local.sa_in.sin_port ) ;
        remote_port = ntohs( sin_remote.sa_in.sin_port ) ;
        sin_contact.sa_in.sin_port = htons( IDENTITY_SERVICE_PORT ) ;
        sin_bind.sa_in6.sin6_port = 0 ;
    }

    /*
     * Create a socket, bind it, and set the close-on-exec flag on the
     * descriptor. We set the flag in case we are called as part of a
     * successful attempt to start a server (i.e. execve will follow).
     * The socket must be bound to the receiving address or ident might
     * fail for multi-homed hosts.
     */
    sd = socket( sin_remote.sa.sa_family, SOCK_STREAM, 0 ) ;
    if ( sd == -1 )
    {
        msg( LOG_ERR, func, "socket creation: %m" ) ;
        return( IDR_ERROR ) ;
    }
    if ( bind(sd, &sin_bind.sa, sizeof(sin_bind.sa)) == -1 )
    {
        msg( LOG_ERR, func, "socket bind: %m" ) ;
        (void) Sclose( sd ) ;
        return( IDR_ERROR ) ;
    }
    if ( fcntl( sd, F_SETFD, FD_CLOEXEC ) == -1 )
    {
        msg( LOG_ERR, func, "fcntl F_SETFD: %m" ) ;
        (void) Sclose( sd ) ;
        return( IDR_ERROR ) ;
    }

    if ( timeout ) {
        if ( sigsetjmp( env, 1 ) == 0 )
            START_TIMER( timeout ) ;
        else {
            Sclose( sd ) ;
            return( IDR_TIMEDOUT ) ;
        }
    }

    if ( connect( sd, &sin_contact.sa, sizeof( sin_contact ) ) == -1 )
    {
        if ( timeout ) {
            STOP_TIMER() ;
            signal ( SIGALRM, SIG_DFL ) ;
        }
        Sclose( sd );
        return( IDR_NOSERVER ) ;
    }

    cc = strx_nprint( buf, sizeof( buf ),
                      "%d,%d\r\n", remote_port, local_port ) ;
    if ( write_buf( sd, buf, cc ) == FAILED )
    {
        if ( timeout ) {
            STOP_TIMER() ;
            signal ( SIGALRM, SIG_DFL ) ;
        }
        Sclose( sd );
        return( IDR_ERROR ) ;
    }

    p = get_line( sd, buf, sizeof( buf ) ) ;

    if ( timeout ) {
        STOP_TIMER() ;
        signal ( SIGALRM, SIG_DFL ) ;
    }

    if ( p == NULL ) {
        Sclose( sd );
        return( IDR_RESPERR ) ;
    }

    /*
     * Verify that the received line is OK
     */
    if ( ( p = verify_line( buf, local_port, remote_port ) ) == NULL )
    {
        msg(LOG_ERR, func, "Bad line received from identity server at %s: %s",
            xaddrname( &sin_remote ), buf ) ;
        Sclose( sd );
        return( IDR_BADRESP ) ;
    }

    svc_logprint( SERVER_CONNSERVICE( serp ), USERID_ENTRY, "%s", p ) ;
    return( IDR_OK ) ;
}
コード例 #5
0
ファイル: verify.c プロジェクト: Zatara7/CS311-Assignment-5
int verify_files( FILE *master, FILE *clnt, FILE *srvr ) {
  unsigned int mismatched, total;
  char line_master[MAX_LINE_LEN], line_clnt[MAX_LINE_LEN], line_srvr[MAX_LINE_LEN];

  // Check that files are valid
  if ( !( master && clnt && srvr ) ) {
    printf( "File invalid." );
    return ( -1 );
  }

  mismatched = 0;
  total = 0;

  // Read through all lines of master and student in compare them while keeping
  // track of both the number of mismatches and total number of comparisons.
  
  // Reading from files.
  // Make sure next line read isn't NULL
  while ( fgets(line_master, MAX_LINE_LEN, master) && 
          fgets(line_clnt, MAX_LINE_LEN, clnt) ) {
    // Check if we are at the cycle line. This is not compared to the professor's
    // output. Keep the output till the end and then print
    if ( !stud_cycle_out ) {
      stud_cycle_out = strstr( line_clnt, CYCLE_TOK );
      if ( stud_cycle_out ) {
        fgets(line_clnt, MAX_LINE_LEN, clnt);
      }
      if ( feof(clnt) ) { break; }
    }

    // Look for output token
    while ( !(master_out = strstr( line_master, OUTPUT_TOK )) ) {
      fgets(line_master, MAX_LINE_LEN, master);
    }
    while ( !(student_out = strstr( line_clnt, OUTPUT_TOK )) ) {
      fgets(line_clnt, MAX_LINE_LEN, clnt);
    }

    mismatched += verify_line( master_out, student_out );
    total++;
  }

  while ( !feof( master ) && !feof( srvr ) ) {
    // Get line from server file and not master file because we read master
    // file in previous loop
    fgets(line_srvr, MAX_LINE_LEN, srvr);

    // See if we are getting the master's cycle count
    if ( !master_cycle_out ) {
      master_cycle_out = strstr( line_master, CYCLE_TOK );
    }

    // Find next output line on master
    while ( !feof( master) && 
        !(master_out = strstr( line_master, OUTPUT_TOK )) ) {
      fgets(line_master, MAX_LINE_LEN, master);
    }
    // Find next output line on server
    while ( !feof( srvr ) && 
        !(student_out = strstr( line_srvr, OUTPUT_TOK )) ) {
      fgets(line_srvr, MAX_LINE_LEN, srvr);
    }
    // Compare master and server lines
    mismatched += verify_line( master_out, student_out );
    total++;
    
    // Get next line from master
    fgets(line_master, MAX_LINE_LEN, master);

  }

  // If we found both, print out as reference
  //if ( master_cycle_out && stud_cycle_out ) {
    printf( "%s %s", MASTER_IND, master_cycle_out );
    printf( "%s %s\n", STUDENT_IND, stud_cycle_out );
  //}

  // Print out the mismatches and a status of whether the verification was
  // successful or not.
  printf("Number correct / Total compared: %d/%d\n", total-mismatched, total);
  if ( mismatched ) {
    printf( ANSI_COLOR_RED      "Failed.\n"     ANSI_COLOR_RESET);
  }
  else {
    printf( ANSI_COLOR_GREEN    "Success.\n"    ANSI_COLOR_RESET);
  }

  return ( mismatched );
}