"Fossies" - the Fresh Open Source Software Archive

Member "authforce-0.9.9/src/methods.c" (13 May 2007, 3836 Bytes) of package /linux/www/old/authforce-0.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* $Id: methods.c,v 1.2 2001/02/10 00:22:46 kapheine Exp $ */
    2 
    3 #include <config.h>
    4 #include <stdio.h>
    5 #include <stdlib.h>
    6 #include <string.h>
    7 #include <unistd.h>
    8 #include <malloc.h>
    9 #ifdef MEMWATCH
   10 #include "memwatch.h"
   11 #endif /* MEMWATCH */
   12 #include "extern.h"
   13 
   14 int process_passwords(char *username) {
   15     int i;
   16     char *password;
   17     char **password_list;
   18     int result;
   19 
   20     session_function = passwords_ident;
   21     i = session_count;
   22 
   23     /* because transform will make changes to list */
   24     password_list = copy_list(master_password_list); 
   25 
   26     while ((password = password_list[i]) != NULL) {
   27         password = transform(username, password);
   28         result = submit(username, password);
   29         sleep(per_password_delay);
   30         if (result == EXIT_SUCCESS) {
   31             strncpy(user_pass[0], username, sizeof(char)*41);
   32             strncpy(user_pass[1], password, sizeof(char)*41);
   33             free(password);
   34             free_list(password_list);
   35             session_count = 0;
   36             return(EXIT_SUCCESS);
   37         }   
   38         i++;
   39         session_count = i;
   40         free(password);
   41     }
   42 
   43     session_count = 0;
   44     free_list(password_list);
   45     return(EXIT_FAILURE);
   46 }
   47 
   48 /* transforms special variables in list
   49  * parameters:
   50  *    username currently being worked on
   51  *    password to be warped
   52  * new password is returned
   53  * current transformations:
   54  */
   55 
   56 char *transform(char *username, char *password) {
   57     char *elements[] = {
   58         "{username}",
   59         "{emanresu}",
   60         NULL
   61     };
   62 
   63     char *trans_password;       /* transformed password */
   64     char *old_password;         /* before current transformation */
   65     char *cur_element;
   66     char *r_username;           /* reversed username */
   67     char insertion[41];         /* value to insert in {}s */
   68     char *left;                 /* left of element */
   69     char *right;                /* right of element */
   70     int i=0;
   71 
   72     trans_password = malloc_w(sizeof(char)*41);
   73     old_password = malloc_w(sizeof(char)*41);
   74     r_username = strdup_w(username);
   75     strrev(r_username);
   76 
   77     strncpy(old_password, password, sizeof(char)*41);
   78 
   79     while ((cur_element = elements[i]) != (char)NULL) {
   80         if (!strcmp(password, "{username}"))
   81             strncpy(insertion, username, sizeof(insertion));
   82         else if (!strcmp(password, "{emanresu}"))
   83             strncpy(insertion, r_username, sizeof(insertion));
   84         else strncpy(insertion, "", sizeof(insertion));
   85         while ((right = strstr(old_password, cur_element))) {
   86             left = old_password;
   87             *right = '\0';
   88             right += strlen(cur_element);
   89             snprintf(trans_password, sizeof(char)*41, "%s%s%s", left, insertion, right);
   90             strncpy(old_password, trans_password, sizeof(char)*41);
   91         }
   92         i++;
   93     }
   94 
   95     free(trans_password);
   96     free(r_username);
   97     return(old_password);
   98 }
   99 
  100 void common_pairs(void) {
  101     int i;
  102     char **common_pairs_list;
  103     int result;
  104     char *path = NULL;
  105     char *username;
  106     char *password;
  107 
  108     session_function = common_pairs_ident;
  109     i = session_count;
  110 
  111     username = (char*)malloc_w(sizeof(char)*81);
  112 
  113     path = search_path(common_pairs_file, pathlist);
  114     common_pairs_list = textlist(path);
  115     free(path);
  116 
  117     if (abs(session_count) > (num_lines+1)) {
  118         fprintf(stderr, "common_pairs: session_count greater than num_lines\n");
  119         exit(EXIT_FAILURE);
  120     }
  121 
  122     while (1) {
  123         if (common_pairs_list[i] == (char)NULL)
  124             break;
  125         strncpy(username, common_pairs_list[i], sizeof(char)*81);
  126         password = extract(username, ':');
  127         if (!password) {
  128             fprintf(stderr, "common_pairs: list element invalid\n");
  129             exit(EXIT_FAILURE);
  130         }
  131         result = submit(username, password);
  132         sleep(per_password_delay);
  133         if (result == EXIT_SUCCESS) {
  134             if (!quiet)
  135                 printf("match [%s:%s]\n", username, password);
  136             if (beep)
  137                 printf("\007");
  138             fprintf(logfd, "match [%s:%s]\n", username, password);
  139             found++;
  140         }
  141         i++;
  142         session_count = i;
  143         if (max_users == num_users && max_users != 0) {
  144             if (!quiet)
  145                 printf("max users reached at %i\n", num_users);
  146             fprintf(logfd, "max users reached at %i\n", num_users);
  147             break;
  148         }
  149         num_users++;
  150     }
  151 
  152     session_count=0;
  153     free(username);
  154     free_list(common_pairs_list);
  155 }