Esempio n. 1
0
PRODUCTKEY_API int extract_expr_time ( char* product_key, long* expr_time)
{
	char	plain_text [(2*MAX_PASS_LEN) + 1];

	assert (product_key);
	assert (expr_time);

	if ( validate (product_key) == PKEY_OK )
	{	
		memset ( plain_text, '\0', (2 * MAX_PASS_LEN) + 1 );
		strcpy ( plain_text, product_key );

		decrypt_password ( plain_text );

		plain_text[0]						= KEY_FIRST_CHAR;
		plain_text[strlen(plain_text)-1]	= KEY_LAST_CHAR;

		*expr_time = atol ( plain_text );

		return (PKEY_OK);
	}
	else
	{
		*expr_time = 0;
		return (PKEY_INVALID);
	}
}
Esempio n. 2
0
PRODUCTKEY_API int	validate ( char* product_key )
{
	char	plain_text [(2*MAX_PASS_LEN) + 1];
	long	last_char_index;
	DWORD	index;
	int		is_lower_hex;
	char	current_char;

	assert (product_key);

	if ( strlen (product_key) != (2*MAX_PASS_LEN) )
		return (PKEY_INVALID);

	for (index = 0; index < strlen(product_key); index++)
	{
		current_char = product_key[index];
		is_lower_hex = ( current_char >= '0' && current_char <= '9' ) ||
					   ( current_char >= 'a' && current_char <= 'f' ); 	
		if ( ! is_lower_hex )
			return (PKEY_INVALID);
	}		

	memset ( plain_text, '\0', (2 * MAX_PASS_LEN) + 1);
	strcpy ( plain_text, product_key );
	decrypt_password ( plain_text );

	last_char_index = strlen(plain_text)-1;
	if ( plain_text[0] == VALID_KEY_CHAR && plain_text[last_char_index] == VALID_KEY_CHAR )
	{
		return (PKEY_OK);
	}
	else
	{
		return (PKEY_INVALID);
	}	
}
int csa_docreateaccount(void *source, int cargc, char **cargv) {
  nick *sender=(nick *)source;
  int execute;
  char *error_username = NULL, *error_password = NULL, *error_email = NULL;
  char *username = NULL, *password = NULL, *email = NULL;
  char account_info[512];
  char passbuf[512];
  int do_create;
  int activate;

  if(cargc<5) {
    controlreply(sender, "CREATEACCOUNT FALSE args");
    return CMD_ERROR;
  }

  execute = cargv[0][0] == '1';
  if(strcmp(cargv[1], "0"))
    username = cargv[1];
  if(strcmp(cargv[2], "0"))
    email = cargv[2];
  if(strcmp(cargv[3], "0")) {
    int errorcode = decrypt_password(createaccountsecret, KEY_BITS, passbuf, sizeof(passbuf), cargv[3]);
    if(errorcode) {
      Error("chanserv_relay",ERR_WARNING,"createaccount unable to decrypt password, error code: %d", errorcode);
      controlreply(sender, "CREATEACCOUNT FALSE args");
      return CMD_ERROR;
    }
    password = passbuf;
  }
  activate = cargv[4][0] == '1';

  if(username) {
    if (findreguserbynick(username)) {
      error_username = "******";
    } else if(csa_checkaccountname_r(username)) {
      error_username = "******";
    }
  }

  if(email)
    error_email = email_to_error(email);

  if(password) {
    int r = csa_checkpasswordquality(password);
    if(r == QM_PWTOSHORT) {
      error_password = "******";
    } else if(r == QM_PWTOLONG) {
      error_password = "******";
    } else if(r == QM_PWTOWEAK) {
      error_password = "******";
    } else if(r == QM_PWINVALID) {
      error_password = "******";
    } else if(r != -1) {
      error_password = "******";
    }
  }

  if(execute && email && password && username && !error_email && !error_password && !error_username) {
    reguser *rup;
    do_create = 1;

    rup = csa_createaccount(username, password, email);

    if(!activate)
      USetInactive(rup);

    cs_log(sender,"CREATEACCOUNT created auth %s (%s) %s",rup->username,rup->email->content,activate?"(active)": "(inactive)");
    csdb_createuser(rup);
    snprintf(account_info, sizeof(account_info), " %u %lu", rup->ID, (unsigned long)rup->lastpasschange);

    if(!activate)
      sendemail(rup);
  } else {
    account_info[0] = '\0';
    do_create = 0;
  }

  controlreply(sender, "CREATEACCOUNT %s%s%s%s%s%s%s%s",
    do_create ? "TRUE" : "FALSE",
    account_info,
    email && error_email ? " " : "", email && error_email ? error_email : "",
    password && error_password ? " " : "", password && error_password ? error_password : "",
    username && error_username ? " " : "", username && error_username ? error_username : ""
  );

  return CMD_OK;
}