Ejemplo n.º 1
0
/**
 * @brief performs a basic error check and after everything has passed, passes the information onto server via sendall
 * after the execution of this function, we will be authenticated with the server
 * @param username the name of our server we want to join
 * @param passwd the password for the server network
 * @param conn a pointer to the connection status of the server
 * @return return 0 for success, -1 for failure
 */
int storage_auth(const char *username, const char *passwd, void *conn)
{
	// if we have not Connected, do not execute. Also raise the error
	if (didConnect != 1){
		errno = ERR_CONNECTION_FAIL;
		return -1;
	}

	// Connection is really just a socket file descriptor.
	int sock = (int)conn;

	// Send some data.
	char buf[MAX_CMD_LEN];
	memset(buf, 0, sizeof buf);
	char *encrypted_passwd = generate_encrypted_password(passwd, NULL);
	snprintf(buf, sizeof buf, "AUTH %s %s\n", username, encrypted_passwd);
	if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) {
		if (strcmp("Failed", buf)== 0){
			errno = ERR_AUTHENTICATION_FAILED;
			return -1;		
		}
		didAuthenticate = 1;
		return 0;
	}

	return -1;
}
Ejemplo n.º 2
0
/**
 * @brief Authenticate the client via the server
 *
 * @param username username of client
 * @param passwd password of client
 * @param conn represents connection to the server
 * @return returns 0 if successful / -1 if unsuccessfull
 */
int storage_auth(const char *username, const char *passwd, void *conn)
{

    if ((username == NULL) || (passwd == NULL) || (conn == NULL))
    {
        errno = ERR_INVALID_PARAM;
        return -1;
    }
    // Connection is really just a socket file descriptor.
    int sock = (int)conn;

    // Send some data.
    char buf[MAX_CMD_LEN];
    memset(buf, 0, sizeof buf); // Memory management, useful to log this event as it can potentially crash
    // the system or cause problems in the future

    char log_message[100];
    sprintf(log_message, "Authorizing: memset complete\n"); // Specifies it is the storage_auth function
    logger(fclientOut, log_message, LOGGING_CLIENT);

    char *encrypted_passwd = generate_encrypted_password(passwd, NULL);
    snprintf(buf, sizeof buf, "AUTH;%s;%s\n", username, encrypted_passwd);
    if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0)
    {
        char *if_auth = strstr(buf, "SUCCESS");
        if (if_auth)
        {
            return 0;
        }
        else
        {
            errno = ERR_AUTHENTICATION_FAILED;
            return -1;
        }
    }
    errno = ERR_CONNECTION_FAIL;
    return -1;
}
Ejemplo n.º 3
0
/**
 * @brief This is the authentication function, this function will send the client information to the 
 * server and verify that information with the deafult.conf file. Once the information has been verified
 * this function will return a code depending on the status of the verification. if it returned 0 then the 
 * authentication is successful. If another number is returned however, then an error occured. The type of 
 * error is determined by the code that is returned.
 */
int storage_auth(const char *username, const char *passwd, void *conn)
{
	//We have to handle commands that cannot be handled by the server.
	if (conn == NULL || username == NULL || passwd == NULL){
		errno = ERR_INVALID_PARAM;
		return -1;	
	}
	
	//CANNOT AUTH IF NOT CONNECTED!
	if(!conn)
	{
		errno = ERR_CONNECTION_FAIL;
		return -1;
	}

	//int auth_status=0; //WHAT IS THIS?

	// Connection is really just a socket file descriptor.
	int sock = (int)conn;

	// Send some data.
	char buf[MAX_CMD_LEN];
	memset(buf, 0, sizeof buf);

	char *encrypted_passwd = generate_encrypted_password(passwd, NULL);
	
	snprintf(buf, sizeof buf, "AUTH %s %s\n", username, encrypted_passwd);

	// if sendall is zero, the value is sent to server successfully
	// if recvline is zero, the value is received succcessfully

	if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) {
		//auth_status = atoi(buf);
		//errno=auth_status;
	
		//Check if authentication successful!		
		if (atoi(buf) == 0){
			//NO ERROR, Send Success.
			AUTH_STATUS = 0; 
			errno = 0;			
			return 0; //success
		}
		else if (atoi(buf) == ERR_AUTHENTICATION_FAILED){
			
			//ERROR, Auth FAILED.			
			AUTH_STATUS = ERR_AUTHENTICATION_FAILED;
			errno = ERR_AUTHENTICATION_FAILED;			
			return -1; //failure
		}
		
		else{
			errno = ERR_UNKNOWN;
			return -1; //failure
		}

	}

	
	//Should never get here, but if we do:
	errno = ERR_UNKNOWN;
	return -1;

}
Ejemplo n.º 4
0
/**
 * @brief This is just a minimal stub implementation.  You should modify it
 * according to your design.
 */
int storage_auth(const char *username, const char *passwd, void *conn)
{
    
    char check[MAX_CONFIG_LINE_LEN], trash[MAX_CONFIG_LINE_LEN];
    
    if(conn == NULL)
    {
        errno = ERR_INVALID_PARAM;
        sprintf(log_buffer, "storage_auth: Invalid connection");
        logger(client_log, log_buffer);
        return -1;
    }
    else if(username == NULL || sscanf(username, "%s %s", check, trash) != 1)
    {
        errno = ERR_INVALID_PARAM;
        sprintf(log_buffer, "storage_auth: Incorrect username entered: %s\n", username);
        logger(client_log, log_buffer);
        return NULL;
    }
    else if(passwd == NULL || sscanf(passwd, "%s %s", check, trash) != 1)
    {
        errno = ERR_INVALID_PARAM;
        sprintf(log_buffer, "storage_auth: Incorrect password entered: %s\n", passwd);
        logger(client_log, log_buffer);
        return NULL;
    }
    else if(connected == false)
    {
        errno = ERR_CONNECTION_FAIL;
        sprintf(log_buffer, "storage_auth: Not connected to a server\n");
        logger(client_log, log_buffer);
        return -1;
    }
    
    // Connection is really just a socket file descriptor.
    int sock = (int)conn;
    
    int i;
    char pass_asterik[strlen(passwd) + 1];
    for(i = 0; i < strlen(passwd); i++)
        pass_asterik[i] = '*';
    pass_asterik[i] = 0;
    
    
    // Send some data.
    char buf[MAX_CMD_LEN];
    memset(buf, 0, sizeof buf);
    char *encrypted_passwd = generate_encrypted_password(passwd, NULL);
    sprintf(buf, "AUTH #%.63s #%.63s\n", username, encrypted_passwd);
    if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0)
    {
        if(strcmp(buf, "AUTH #pass") == 0)
        {
            authenticated = true;
            // Log successful client authorization.
            sprintf(log_buffer, "storage_auth: Client authorization successful. Username: %s and Password: %s\n", username, pass_asterik);
            logger(client_log, log_buffer);
            return 0;
        }
        else
            errno = ERR_AUTHENTICATION_FAILED;
    }
    else
        errno = ERR_UNKNOWN;
    
    // Log failed client authorization.
    sprintf(log_buffer, "storage_auth: Client authorization failure. Username: %s and Password: %s\n", username, pass_asterik);
    logger(client_log, log_buffer);
    
    return -1;
}