Jump to content

Como executar este código?


SergioC92

Recommended Posts

Boas a todos!

Estou a tentar correr o código em baixo com o GCC em Ubuntu mas dá-me sempre uma série de erros. Alguém me pode ajudar? 

 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <security/pam_appl.h>
#include <security/pam_modules.h>

/* expected hook */
PAM_EXTERN int pam_sm_setcred( pam_handle_t *pamh, int flags, int argc, const char **argv ) {

	return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) {
	return PAM_SUCCESS;
}

int converse( pam_handle_t *pamh, int nargs, struct pam_message **message, struct pam_response **response ) {
	int retval ;
	struct pam_conv *conv ;

	retval = pam_get_item( pamh, PAM_CONV, (const void **) &conv ) ; 
	if( retval==PAM_SUCCESS ) {
		retval = conv->conv( nargs, (const struct pam_message **) message, response, conv->appdata_ptr ) ;
	}

	return retval ;
}


/* expected hook, this is where custom stuff happens */
PAM_EXTERN int pam_sm_authenticate( pam_handle_t *pamh, int flags,int argc, const char **argv ) {
	int retval;

	const char* pUsername;
	retval = pam_get_user(pamh, &pUsername, "User: ");
	char *input;
	struct pam_message msg[1],*pmsg[1];
	struct pam_response *resp;

	// disallow root logins
	if (strcmp(pUsername, "root") == 0) {
		return PAM_AUTH_ERR;
	}


	pmsg[0] = &msg[0] ;
	msg[0].msg_style = PAM_PROMPT_ECHO_ON ;
	msg[0].msg = "The password: " ;
	resp = NULL;
	if( (retval = converse(pamh, 1 , pmsg, &resp))!=PAM_SUCCESS ) {
		return retval ;
	}

	/* retrieving user input */
	if( resp ) {
		if( (flags & PAM_DISALLOW_NULL_AUTHTOK) && resp[0].resp == NULL ) {
	    		free( resp );
	    		return PAM_AUTH_ERR;
		}
		input = resp[ 0 ].resp;
		resp[ 0 ].resp = NULL; 		  				  
    	} else {
		return PAM_CONV_ERR;
	}

	
	time_t now = time(NULL);
	struct tm *now_tm = localtime(&now);
	int hour = now_tm->tm_hour;
	int day = now_tm->tm_mday;

	char correctPass[11];
	sprintf(correctPass, "CurrentFlag_12xNs1%d%d", day, hour);
		

	if(strcmp(correctPass, input)==0) {
		return PAM_SUCCESS;
	}
	else
		return PAM_AUTH_ERR;


	if (retval != PAM_SUCCESS) {
		return retval;
	}

	return PAM_AUTH_ERR;
}

 

Obrigado!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.