Ejemplo n.º 1
0
//checks if client does not already exist, and if not so, sends ACK message to client
int checkClient(int connfd){

    struct MessageSBCP joinMessage;
    struct AttributeSBCP joinMessageAttribute;
    char temp[16];
    int status = 0;
    read(connfd,(struct MessageSBCP *) &joinMessage,sizeof(joinMessage));
    //joinMessageAttribute.payload = (char *)malloc(sizeof(char *) * joinMessage.joinMessageAttribute.length);
    joinMessageAttribute = joinMessage.attribute[0];
    //clients[clientCount].username = (char *)malloc(sizeof(char *) * joinMessage.joinMessageAttribute.length);
    strcpy(temp, joinMessageAttribute.payload);
    status = checkUsername(temp);
    if(status == 1)
    {
        printf("\nClient already exists.");
        sendNAK(connfd, 1); // 1 for client already exists 
    }
    else
    {
        strcpy(clients[clientCount].username, temp);
        clients[clientCount].fd = connfd;
        clients[clientCount].clientCount = clientCount;
        clientCount = clientCount + 1;
        sendACK(connfd);
    }
    return status;
}
Ejemplo n.º 2
0
// spracovni parametru
int handleArgs (const int argc, const char *argv[], connectionInfo & server) {
   if (argc < 4 || argc > 5) {
      return 1;
   }
   if (strlen(argv[2]) != 2) {
      return 1;
   }
   if (checkUsername(argv[3]) != 0) {
      return 1;
   }

   if (argc == 4) {
      if (!strcmp(argv[2], "-r"))
	 server.requestType = requestTypes[0];
      else
	 return 1;
   }
   if (argc == 5) {
      if (!strcmp(argv[2], "-s")) {
	 server.requestType = requestTypes[1];
	 server.message = argv[4];
      }
      else if (!strcmp(argv[2], "-d")) {
	 server.requestType = requestTypes[2];
	 for (unsigned i = 0; i < strlen(argv[4]); i++) {
	    if (!isdigit(argv[4][i]))
	       return 1;
	 }
	 server.messageIndex = argv[4];
      }
      else
	 return 1;
   }
   server.username = argv[3];

   // ziskani adresy a cisla portu
   std::string host = argv[1];
   regmatch_t strMatch[3];
   regex_t uriRe;
   int status;
   std::string uriPattern = "^([^/?#:]+):([0-9]+)$";
   if (regcomp(&uriRe, uriPattern.c_str(), REG_EXTENDED) != 0) {
      return 1;
   }
   status = regexec(&uriRe, host.c_str(), 3, strMatch, 0);
   if (status == 0) {
      if (strMatch[0].rm_so == -1 || strMatch[1].rm_so == -1)
	 return 1;
      server.hostname = host.substr(strMatch[1].rm_so, strMatch[1].rm_eo-strMatch[1].rm_so);
      std::string portNumber = host.substr(strMatch[2].rm_so, strMatch[2].rm_eo-strMatch[2].rm_so);
      server.port = atoi(portNumber.c_str());
   }
   return 0;
}
Ejemplo n.º 3
0
/* Both password and username are inserted into their respective map.	 */
void Authentication::newUser() {
    string temp;
    cout << "Please choose a username:  "******"Enter Password:  "******"\nRe-Enter Password:  ");

    m_password.insert(pair<int, string>(m_password.size(), password));
    writeFile();

    m_user = name;
}
Ejemplo n.º 4
0
// Description
//
// Extracts the Authy ID from the configuration file 
//
// Parameters
// 
//   pszConfFilename - Full path to the configuration file
//   pszUsername     - The Username (login) for which we are getting the Authy ID
//   pszCommonName   - Common name from the OpenVPN certificate
//
// Returns
// 
// standard RESULT
//
RESULT
getAuthyIdAndValidateCommonName(__out char *pszAuthyId,
           const char *pszConfFilename, 
           const char *pszUsername, 
           const char *pszCommonName) 
{
  FILE *fpConfFile = NULL;
	char *pch = NULL;
  RESULT r = FAIL;

  char line[LINE_LENGTH];
  char *columns[3] = {NULL};
  int i = 0;


  if(!pszConfFilename || !pszUsername || FAILED(checkUsername(pszUsername))) {
    r = FAIL;
    trace(ERROR, __LINE__, "[Authy] getAuthyId: Wrong configuration file or username\n");
    goto EXIT;
  }

  fpConfFile = fopen(pszConfFilename, "r");

  if(NULL == fpConfFile) {
		trace(ERROR, __LINE__, "[Authy] getAuthyId: unable to read file %s\n", pszConfFilename);
    r = FAIL;
    goto EXIT;
  }

  memset(columns, 0, sizeof(columns));
  while(NULL != fgets(line, ARRAY_SIZE(line), fpConfFile)){
		pch = strtok(line," \t");
    i = 0;
    while(pch != NULL && i < 3){
      columns[i] = removeSpaces(pch);
      pch = strtok (NULL, " \t"); //Go to the next token 
      i++;
    }    
    if(columns[1] != NULL && 0 == strcmp(columns[0], pszUsername)){
      trace(DEBUG, __LINE__, "[Authy] Found column for pszUsername=%s column is %s\n", pszUsername, line); 
      break; 
    }
    memset(columns, 0, sizeof(columns));
  }

  if(columns[0] == NULL){
    r = FAIL;
    trace(ERROR, __LINE__, "[Authy] Username %s not found in Authy Config file\n", pszUsername);
    goto EXIT;
  } 
  
  assert(columns[1] != NULL);
  
  if(FALSE == isAnAuthyId(columns[1])){
    r = FAIL;
    trace(ERROR, __LINE__, "[Authy] AuthyID %s for Username %s is not valid. Authy ID's can only be numeric values\n", columns[1], pszUsername);
    goto EXIT;
  }

  if(columns[2] != NULL && strcmp(columns[2], pszCommonName) != 0){
    r = FAIL;
    trace(ERROR, __LINE__, "[Authy] CommonName %s does not match the configuration file common name %s\n", pszCommonName, columns[2]);
    goto EXIT;
  }

  snprintf(pszAuthyId, MAX_AUTHY_ID_LENGTH, "%s", columns[1]);
  trace(INFO, __LINE__, "[Authy] Found Authy ID: %s for username: %s\n", pszAuthyId, pszUsername);
  r = OK;

EXIT:
  if(fpConfFile){
    fclose(fpConfFile);
  }
  return r;
}
Ejemplo n.º 5
0
/*Identifying phase in menu*/
int userIdentify()
{
	extern char username[20];
	char prompt[20];

	clearCommander(0);
	silenceOff();

	/*Username step*/
	while (1 == 1)
	{
		printAndWriteFrom(20, "Username: "******"Type 'exit' to break identifying process ");
		/*Wait for input*/
		flushinp();
		getstr(prompt);
		/*If the player would like to exit the logging menu*/
		if (strcmp(prompt, "exit") == 0)
		{
			break;
		}
		/*If provided username do not exist*/
		else if (checkUsername(prompt) == FALSE)
		{
			thrillerAnimation("Inconsistency detected", "Invalid username, try "
                     "again", 1);
			continue;
		}
		/*If provided username exist, assign its string into 'username' variab*/
		else
		{
			int i = 0;
			for (i = 0; prompt[i] != '\0'; ++i)
			{
				username[i] = prompt[i];
			}
		}

		/*Password step*/
		memset (prompt, '\0', sizeof(prompt));
		clearCommander(0);
		while (1 == 1)
		{
			printAndWriteFrom(20, "Password: "******"exit") == 0)
			{
				showCommanderInfo("Identifying has being canceled",1 );
				break;
			}
			if (checkPassword(prompt) == FALSE)
			{
				thrillerAnimation("Inconsistency detected", "Invalid password, "
                      "try again", 1);
				continue;
			}
			/*If player had successfully logged in*/
			else
			{
				thrillerAnimation("Logging in", "Successfully logged in", 1);
				return TRUE;
			}
		}
		break;
	}
	return 0;
}