Exemple #1
0
int main(int argc, char **argv) {
  hardened_shadow_openlog("useradd");

  if (lckpwdf() != 0)
    err(EXIT_FAILURE, "lckpwdf");

  if (!read_defaults_file())
    warnx("failed to read defaults file");

  parse_args(argc, argv);

  if (flag_defaults)
    return (handle_flag_defaults()) ? EXIT_SUCCESS : EXIT_FAILURE;

  determine_uid_gid();
  if (!flag_no_log_init)
    initialize_lastlog();
  if (flag_create_home)
    create_home_dir();
  if (default_create_mail_spool && !flag_system)
    create_mail_spool();
  create_account();

  hardened_shadow_flush_nscd("passwd");
  hardened_shadow_flush_nscd("group");

  if (ulckpwdf() != 0)
    warn("ulckpwdf");

  return EXIT_SUCCESS;
}
int main ()
{
   
   // testing for all possible good and bad data

   // testing with good data 
   bank_account* b = create_account("Ploni Amoni", 250000, "0123456789876");

/* ALL OF THESE WITH BAD DATA "WORK" BY DISPLAYING GUIDING MESSAGES TO THE USER WITHOUT BOMBING OUT THE SYSTEM */
      
   // testing with incorrect account name
   // Running caused Segmentation fault (core dumped)
   // bank_account* b = create_account("", 150000, "0123456789876");

   // testing with incorrect amount
   // error: causes a Segmentation fault (core dumped)
   // bank_account* b = create_account("Bais Hillel", -100, "0123456789876");

   // testing with incorrect account_num length
   // bank_account* b = create_account("Bais Hillel", 150000, "0123456789");
   
   // testing with incorrect account_num chars instead of ints
   //bank_account* b = create_account("Bais Hillel", 250000, "01A3B5C7D9E7F");


/* MUST HANDLE EACH OF THESE CASES THAT BOMBED OUT!!! */

   // testing with incorrect number of parameters
   // bank_account* b = create_account("Bais Hillel", 0123456789876);
   
   // error:  with "badamount": incompatible type for argument 2 of âcreate_accountâ
   // bank_account.h:20: note: expected âdoubleâ but argument is of type âchar *â

   // bank_account* b = create_account("Bais Hillel", "badamount", "0123456789876");

   // error with badamount:  âbadamountâ undeclared (first use in this function)

   //bank_account* b = create_account("Bais Hillel", badamount, "0123456789876");


   if(b == NULL)
   {
      printf("Invalid account");   
   }
   
   if(b->balance < 0)            
   {
      printf("Invalid account");
   }
     
   else
   {
      display_account(b);
      delete_account(b);
   }
   
   return 0;
}
Exemple #3
0
/** creates an ACCOUNT struct from random generated data fields
 * @return Pointer to created ACCOUNT struct
 */
ACCOUNT* random_account(){
  char* rand_name;
  int dollars, account_number, length;
  length = 10;
  rand_name = rand_str_generator(NAME_LENGTH);
  dollars = rand() % 500;
  account_number = rand() % 30;
  return create_account(rand_name,account_number,dollars);
}
Exemple #4
0
int main(int argc, char **argv) {
    struct passwd  *p;
    int             i, ecode;

    init_defaults(basename(argv[0]), "passwd");
    while ((i=getopt(argc,argv,"c")) != EOF) {
        switch (i) {
        case 'c':
            if (getuid() != 0) {
                fprintf(stderr,"%s: must be root to set chroot option\n", argv[0]);
                return EXIT_FAILURE;
            }
            passwd_stub = CHROOTED_PASSWD;
            break;
        default:
            fprintf(stderr,"%s: bad option %c\n", argv[0], i);
            return EXIT_FAILURE;
        }
    }
    if (optind == argc) {
        if (!(p = getpwuid(getuid()))) {
            fprintf(stderr, "%s: cannot locate your password entry\n", argv[0]);
            return EXIT_FAILURE;
        }
        return change_passwd(p);
    }
    /* passwd should use getopt to support -- syntax */
    ecode = Success;
    for (i = optind; i < argc; i++) {
        if (!(p = getpwnam(argv[i]))) {
            if (getuid() != 0) {
                fprintf(stderr, "%s: must be root to create new accounts\n",
                        argv[0]);
                return EXIT_FAILURE;
            }
            if (strlen(argv[i]) > LOGIN_NAME_MAX) {
                fprintf(stderr,"%s: username exceeds maximum length of %d characters\n", argv[0], LOGIN_NAME_MAX);
                return EXIT_FAILURE;
            }
            if (strchr(argv[i], ':')) {
                fprintf(stderr, "%s: username cannot contain ':' character\n",
                        argv[0]);
                return EXIT_FAILURE;
            }
            if ((ecode=create_account(argv[i])) != Success) {
                return ecode;
            }
        } else if (p->pw_uid != getuid() && getuid() != 0) {
            fprintf(stderr, "%s: sorry, only root may change another user's password\n", argv[0]);
        } else if ((ecode=change_passwd(p)) != Success) {
            return ecode;
        }
    }
    return ecode;
}
Exemple #5
0
pack_and_data_t * generate_new_init_and_init_resp(pack_and_data_t *pin) {
    packet_head_t *ip = pin->ph;
    packet_data_balance_t *b = pin->data;

    if(b == NULL) {

        return NULL;
    }


    uint32_t cid = register_card_id();
    uint32_t acd = register_auth_code();





    int acct_ok = create_account(cid, acd, b);

    if(acct_ok != OK) {
        return NULL;
    }



    account_entry_t *ae = get_account(cid, acd);
    if(ae == NULL) {
        return NULL;
    }


    open_txn(ae, ip);

    // needed for log entry
    pin->ph->card_id = cid;
    pin->ph->auth_code = acd;
    txn_entry_t * t = add_transaction_log_entry(ae, pin);

    if(t == NULL) {
        return NULL;
    }

    return create_basic_response(cid, acd, ip->transaction_id, INIT, ISSUE, OK, 0);

}
Exemple #6
0
int main()
{
    FILE *fp = fopen("input.txt", "r");

    int number_of_operations = 0;

    fscanf(fp, "%d", &number_of_operations);

    DB *database = malloc(sizeof(DB));
    int logged_in = 0;
    int failed_attempts = 0;
    int i = 0;
    for(; i <= number_of_operations; i++)
    {
        if (logged_in)
        {
            printf("1. Log in as an existing user\n");
            printf("2. Create a new account\n");
            printf("3. Log out\n\n");
        }
        else
        {
            printf("1. Log in as an existing user\n");
            printf("2. Create a new account\n\n");
        }

        int operation = 0;
        fscanf(fp, "%d", &operation);

        switch (operation)
        {
            case 1:
            {
                // log in
                char *username = malloc(sizeof(char) * MAX_USERNAME_LEN);
                char *password = malloc(sizeof(char) * MAX_PASSWORD_LEN);

                fscanf(fp, "%s %s", username, password);
                printf("Log in as an existing user\n");
                printf("Username: %s\n", username);
                printf("Password: %s\n\n", password);

                if (login(database, username, password))
                {
                    printf("Successfully logged in. Welcome, %s.\n\n", username);
                    logged_in = 1;
                }
                else
                {
                    printf("Sorry, your username/password was incorrect. Please try again.\n\n");
                    break;
                }

                break;
            }

            case 2:
            {
                // create a new account
                char *username = malloc(sizeof(char) * MAX_USERNAME_LEN);
                char *password = malloc(sizeof(char) * MAX_PASSWORD_LEN);

                fscanf(fp, "%s %s", username, password);

                printf("Create an account\n");
                printf("Username: %s\n", username);
                printf("Password: %s\n\n", password);

                if (create_account(database, username, password))
                        printf("Account successfully created. Please log in.\n\n");
                break;
            }

            case 3:
            {
                // logout
                printf("Successfully logged out.\n");
                fclose(fp);
                return 0;
            }
        }
    }

    printf("\n");

    fclose(fp);
    return 0;
}
Exemple #7
0
void
rcv_account_create (struct htlc_conn *htlc)
{
   create_account(htlc, 1);
}
Exemple #8
0
void
rcv_account_modify (struct htlc_conn *htlc)
{
   create_account(htlc, 0);
}
void booking(clients list, books type, books type2,int op)
{
	char ans;
	int num_c, verif;
	
	Booking book;

	printf("\n\t\tAlready have a client account? [y for yes; n for no]: ");
	ans = getchar();

	/*unacceptable answer*/
	while(ans!= 'n' && ans != 'N' && ans != 'y' && ans != 'Y'){
		getchar();
		printf("\n\t\tOnly y or n are accepted.\n\n\t\tPlease, enter a new answer: ");getchar();
		ans = getchar();
	}

	/*acceptable answers*/
	if(ans == 'n' || ans == 'N'){ /*no client account, creating one*/
		Client person;
		printf("\n\t\t\033[0;92mCreate new account:\033[0m\n");
	
		getchar();
		person = create_account();
		insert_client(list, &person);
		write_client(&person, "clients.txt");
		book_it(&book, person.id_client, op);
		booking_validation(type,type2,&book,op);
		printf("\n\t\t\033[0;92m***Successfuly booked***\033[0m\n");
	}

	else if(ans == 'y' || ans == 'Y'){
		clients ant;
		clients actual;
		/*has client account, going to check who that person is*/
		printf("\n\t\tEnter client id: ");
		scanf("%d", &num_c);
		
		search_clients_id(list, num_c, &ant, &actual); /*searches for the client id*/

		if(actual == NULL){
			/*If it doesn't exist, maybe it was a mistake, let's double check*/
			printf("\n\t\tClient id does not exist. Please enter cellphone number: ");
			scanf("%d",&verif); /*using second parameter, cellphone number*/

			search_clients_cell(list, verif, &ant, &actual); /*searches for the client cellphone*/

			if(actual == NULL) /*If it doesn't exist, then the account doesn't exist either*/
			{
				Client person;
				printf("\n\t\tThere's no account for that client. Let's create a new one.\n\n");
				getchar();
				person = create_account(); /*Than, let's create one*/
				insert_client(list, &person);
				write_client(&person, "clients.txt");
				book_it(&book,num_c, op);
				booking_validation(type,type2,&book,op);
			}
			else if(actual != NULL){ /*If the id exists, the account exists; Let's confirm by the name*/
				/*Going to show cellphone and name, and then ask to confirm to proceed*/
				printf("\n\t\tClient name: "); puts(actual->info.name);
				printf("\n\t\tCellphone number: %d\n\n", actual->info.cell);

				printf("\t\tConfirm? [y for yes; n for no]: ");getchar();
				ans = getchar();
				
				/*if confirmed, proceed to booking*/
				if(ans == 'y' || ans == 'Y'){
					book_it(&book, num_c, op);
					booking_validation(type,type2,&book,op); /*checks if book is valid or not*/
				}
			}
		}
		else if(actual != NULL){ /*If the id exists, the account exists; Let's confirm by the name*/
			/*Going to show cellphone and name, and then ask to confirm to proceed*/
			printf("\n\t\tClient name: "); puts(actual->info.name);
			printf("\n\t\tCellphone number: %d\n\n", actual->info.cell);

			printf("\t\tConfirm? [y for yes; n for no]: ");getchar();
			ans = getchar();
			
			/*if confirmed, proceed to booking*/
			if(ans == 'y' || ans == 'Y'){
				book_it(&book, num_c, op);
				booking_validation(type,type2,&book,op); /*checks if book is valid or not*/
			}
		}
	}
	if (op == 1){
	    write_to_file(type,"wash_books.txt");
	}
	else if(op == 2){
	    write_to_file(type,"fix_books.txt");
	}
}
Exemple #10
0
int main(int argc, char** argv)
{
    /*axis2_stub_t *stub = NULL;*/
    /*axiom_node_t *node = NULL;*/
    axis2_status_t status = AXIS2_FAILURE;
    const axutil_env_t *env = NULL;
    axis2_char_t *address = NULL;
    axis2_char_t *client_home = NULL;
    /*axiom_node_t *ret_node = NULL;*/
    axis2_char_t *operation = NULL;

    env = axutil_env_create_all("trader_client.log", AXIS2_LOG_LEVEL_TRACE);

    client_home = getenv("WSFC_HOME");
    if (!(client_home))
    {
#ifdef WSFC_PREFIX
        client_home = WSFC_PREFIX;
        if (!client_home)
        {
#endif
            printf ("WSFC_HOME environment variable not set properly. Please recheck.\n");
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                "[wsclient] WSFC_HOME is empty");
            return 0;
#ifdef WSFC_PREFIX
        }
        else
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                "WSFC_HOME environment variable not set properly. Using %s as WSFC_HOME.\n", client_home);
#endif
    }

    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
        "[wsclient] WSFC_HOME %s", client_home);
    
    
    address = "http://localhost:9090/axis2/services/traderclient";
    if (argc > 1)
        operation = argv[1];

    else
    {
        printf("Type ./trader -h for usage\n");
        return 0;
    }    

    if (axutil_strcmp(operation, "-h") == 0)
    {
        printf("Usage : %s [create-account] [username] [password] [endpoint_url]\n", argv[0]);
        printf("Usage : %s [buy] [username] [password] [symbol] [quantity] [endpoint_url]\n", argv[0]);
        printf("Usage : %s [sell] [username] [password] [symbol] [quantity] [endpoint_url]\n", argv[0]);
        printf("use -h for help\n");
        printf("NOTE: command line arguments must appear in given order, with trailing ones being optional\n");
        return 0;
    }

    printf("Using endpoint : %s\n", address);

    if(axutil_strcmp(operation, "create-account") == 0)
    {
        if(argc < 4)
        {
            printf("Some arguments are missing\n .use -h for help\n");   
            return 0;
        }  
        else if(argc > 4)
        {    
            address = argv[4]; 
        }    
        status = create_account(env, argv[2], argv[3], address, client_home);
    }    
    else if(axutil_strcmp(operation, "buy") == 0)
    {
        if(argc < 6)
        {
            printf("Some arguments are missing\n .use -h for help\n");
            return 0;
        }
        else if(argc > 6)
        {    
            address = argv[6];    
        }    
        status = buy(env, argv[2], argv[3], argv[4], argv[5], address, client_home);
    }    
    else if(axutil_strcmp(operation, "sell") == 0)
    {
        if(argc < 6)
        {
            printf("Some arguments are missing\n .use -h for help\n");
            return 0;
        }
        else if(argc > 6)
        {
            address = argv[6];
        }    
        status = sell(env, argv[2], argv[3], argv[4], argv[5], address, client_home);
    }    

    else
    {
        printf("Unknown operation \n");
    }
    
    if(status != AXIS2_SUCCESS)
    {
        printf("Trader-Client invoke failed\n");
    }
    else
    {
        printf("Trader-Client invoke Successful\n");
    }
    if (env)
    {
        axutil_env_free((axutil_env_t *) env);
        env = NULL;
    }
    
    return status;
}