Ejemplo n.º 1
0
PAM_EXTERN int 
pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, const char **argv)
{
	struct options options;
	struct ttyent *ttyfileinfo;
	struct passwd *pwd;
	int retval;
	const char *user, *ttyname;

	pam_std_option(&options, NULL, argc, argv);

	PAM_LOG("Options processed");

	retval = pam_get_user(pamh, &user, NULL);
	if (retval != PAM_SUCCESS)
		PAM_RETURN(retval);

	PAM_LOG("Got user: %s", user);

	retval = pam_get_item(pamh, PAM_TTY, (const void **)&ttyname);
	if (retval != PAM_SUCCESS)
		PAM_RETURN(retval);

	PAM_LOG("Got TTY: %s", ttyname);

	/* Ignore any "/dev/" on the PAM_TTY item */
	if (strncmp(TTY_PREFIX, ttyname, sizeof(TTY_PREFIX) - 1) == 0)
		ttyname += sizeof(TTY_PREFIX) - 1;

	/* If the user is not root, secure ttys do not apply */
	pwd = getpwnam(user);
	if (pwd == NULL)
		PAM_RETURN(PAM_IGNORE);
	else if (pwd->pw_uid != 0)
		PAM_RETURN(PAM_SUCCESS);

	PAM_LOG("User is not root");

	ttyfileinfo = getttynam(ttyname);
	if (ttyfileinfo == NULL)
		PAM_RETURN(PAM_SERVICE_ERR);

	PAM_LOG("Got ttyfileinfo");

	if (ttyfileinfo->ty_status & TTY_SECURE)
		PAM_RETURN(PAM_SUCCESS);
	else {
		PAM_VERBOSE_ERROR("Not on secure TTY");
		PAM_RETURN(PAM_PERM_DENIED);
	}
}
Ejemplo n.º 2
0
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
	struct options options;

	pam_std_option(&options, NULL, argc, argv);

	PAM_LOG("Options processed");

	if (getuid() == 0)
		PAM_RETURN(PAM_SUCCESS);

	PAM_VERBOSE_ERROR("Refused; not superuser");
	PAM_LOG("User is not superuser");

	PAM_RETURN(PAM_AUTH_ERR);
}
Ejemplo n.º 3
0
PAM_EXTERN int
pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
	struct options options;

	pam_std_option(&options, NULL, argc, argv);

	PAM_LOG("Options processed");

	PAM_RETURN(PAM_SUCCESS);
}
Ejemplo n.º 4
0
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t * pamh, int flags,
		int argc, const char * argv[]) 
{
	struct passwd *pwd;
	struct stat ttyfileinfo;
	const char *user;
	const char *tty; 
	char ttyfileline[256];
	FILE *ttyfile;
	int pam_err;

	if ( ( (pam_err = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS ) 
			|| ( user == NULL ) )  {
		PAM_ERROR("Error recovering username.");
		return (pam_err);
	}

	if ( (pwd = getpwnam(user)) == NULL ) { 
		PAM_ERROR("Could not get passwd entry for user [%s]",user);
		return (PAM_SERVICE_ERR);
	}

	if ( pwd->pw_uid  != 0 ) { 
		/* secure tty applies only to root */
		return (PAM_SUCCESS);
	}

	if ( (pam_err = pam_get_item(pamh, PAM_TTY,(void *) &tty) ) != PAM_SUCCESS ) {
		PAM_ERROR("Could not determine user's tty");
		return (pam_err);
	}	

	if (tty != NULL && strncmp(TTY_PREFIX, tty, sizeof(TTY_PREFIX)) == 0) {
		PAM_LOG("tty starts with " TTY_PREFIX);
		/* get rid of prefix */
		tty = (const char *)tty + sizeof(TTY_PREFIX) - 1;
	}
	
	if ( stat(SECURETTY, &ttyfileinfo) ) { 
		PAM_ERROR("Could not open SECURETTY file :%s", SECURETTY);
		/* From LinuxPAM, they say that for compatibility issues, 
		 * this needs to succeed. */
		return (PAM_SUCCESS);
	}

	if ((ttyfileinfo.st_mode & S_IWOTH) || !S_ISREG(ttyfileinfo.st_mode)) {
		/* File is either world writable or not a regural file */
		PAM_ERROR("SECURETTY file cannot be trusted!");
		return (PAM_AUTH_ERR);
	}
	
	/* Open read-only file with securettys */
	if ( (ttyfile = fopen(SECURETTY,"r")) ==  NULL ) { 
		PAM_ERROR("Could not open SECURETTY file :%s", SECURETTY);
		return (PAM_AUTH_ERR);
	}

	pam_err = 1;
	/* Search in SECURETTY for tty */
	while (fgets(ttyfileline, sizeof(ttyfileline)-1, ttyfile) != NULL 
		&& pam_err) { 
	        if (ttyfileline[strlen(ttyfileline) - 1] == '\n')
	        	ttyfileline[strlen(ttyfileline) - 1] = '\0';

		pam_err = strcmp(ttyfileline, tty);

	}

	fclose(ttyfile);

	if (!pam_err) { 
		/* tty found in SECURETTY. Allow access */
		PAM_LOG("Access granted for %s on tty %s.", user, tty);
		return (PAM_SUCCESS); 
	}

	PAM_ERROR("Access denied: tty %s is not secure", tty);
	return (PAM_AUTH_ERR);
}
Ejemplo n.º 5
0
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
	struct options options;
	int retval;
	const char *user;
	char *principal;
	char *instance;
	const char *password;
	char localhost[MAXHOSTNAMELEN + 1];
	struct passwd *pwd;

	pam_std_option(&options, NULL, argc, argv);

	PAM_LOG("Options processed");

	retval = pam_get_user(pamh, &user, NULL);
	if (retval != PAM_SUCCESS)
		PAM_RETURN(retval);

	PAM_LOG("Got user: %s", user);

	retval = pam_get_pass(pamh, &password, PASSWORD_PROMPT, &options);
	if (retval != PAM_SUCCESS)
		PAM_RETURN(retval);

	PAM_LOG("Got password");

	if (gethostname(localhost, sizeof localhost - 1) == -1)
		PAM_RETURN(PAM_SYSTEM_ERR);

	PAM_LOG("Got localhost: %s", localhost);

	principal = strdup(user);
	if (principal == NULL)
		PAM_RETURN(PAM_BUF_ERR);

	instance = strchr(principal, '.');
	if (instance != NULL)
		*instance++ = '\0';
	else
		instance = "";

	PAM_LOG("Got principal.instance: %s.%s", principal, instance);

	retval = PAM_AUTH_ERR;
	pwd = getpwnam(user);
	if (pwd != NULL) {
		if (klogin(pwd, instance, localhost, (char *)password) == 0) {
			if (!(flags & PAM_SILENT) && notickets && !noticketsdontcomplain)
				pam_prompt(pamh, PAM_ERROR_MSG,
				    "Warning: no Kerberos tickets issued",
				    NULL);
			/*
			 * XXX - I think the ticket file isn't supposed to
			 * be created until pam_sm_setcred() is called.
			 */
			if (krbtkfile_env != NULL)
				setenv("KRBTKFILE", krbtkfile_env, 1);
			retval = PAM_SUCCESS;
		}

		PAM_LOG("Done klogin()");

	}
	/*
	 * The PAM infrastructure will obliterate the cleartext
	 * password before returning to the application.
	 */
	free(principal);

	if (retval != PAM_SUCCESS)
		PAM_VERBOSE_ERROR("Kerberos IV refuses you");

	PAM_RETURN(retval);
}
Ejemplo n.º 6
0
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
	struct opie opie;
	struct options options;
	struct passwd *pwd;
	int retval, i;
	char *(promptstr[]) = { "%s\nPassword: "******"%s\nPassword [echo on]: "};
	char challenge[OPIE_CHALLENGE_MAX];
	char prompt[OPIE_CHALLENGE_MAX+22];
	char resp[OPIE_SECRET_MAX];
	const char *user;
	const char *response;

	pam_std_option(&options, other_options, argc, argv);

	PAM_LOG("Options processed");

	/*
	 * It doesn't make sense to use a password that has already been
	 * typed in, since we haven't presented the challenge to the user
	 * yet.
	 */
	if (pam_test_option(&options, PAM_OPT_USE_FIRST_PASS, NULL) ||
	    pam_test_option(&options, PAM_OPT_TRY_FIRST_PASS, NULL))
		PAM_RETURN(PAM_AUTH_ERR);

	user = NULL;
	if (pam_test_option(&options, PAM_OPT_AUTH_AS_SELF, NULL)) {
		pwd = getpwnam(getlogin());
		user = pwd->pw_name;
	}
	else {
		retval = pam_get_user(pamh, (const char **)&user, NULL);
		if (retval != PAM_SUCCESS)
			PAM_RETURN(retval);
	}

	PAM_LOG("Got user: %s", user);

	/*
	 * Don't call the OPIE atexit() handler when our program exits,
	 * since the module has been unloaded and we will SEGV.
	 */
	opiedisableaeh();

	opiechallenge(&opie, (char *)user, challenge);
	for (i = 0; i < 2; i++) {
		snprintf(prompt, sizeof prompt, promptstr[i], challenge);
		retval = pam_get_pass(pamh, &response, prompt, &options);
		if (retval != PAM_SUCCESS) {
			opieunlock();
			PAM_RETURN(retval);
		}

		PAM_LOG("Completed challenge %d: %s", i, response);

		if (response[0] != '\0')
			break;

		/* Second time round, echo the password */
		pam_set_option(&options, PAM_OPT_ECHO_PASS);
	}

	/* We have to copy the response, because opieverify mucks with it. */
	snprintf(resp, sizeof resp, "%s", response);

	/*
	 * Opieverify is supposed to return -1 only if an error occurs.
	 * But it returns -1 even if the response string isn't in the form
	 * it expects.  Thus we can't log an error and can only check for
	 * success or lack thereof.
	 */
	PAM_RETURN(opieverify(&opie, resp) == 0 ? PAM_SUCCESS : PAM_AUTH_ERR);
}
Ejemplo n.º 7
0
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t * pamh, int flags,
		int argc, const char * argv[]) 
{
	struct passwd *opwd,*tpwd;
	struct group *group;
	const char *orig_user, *target_user;
	char **user_list;
	int pam_err, member;

	/* Get info for target user. Who do you want to su to ? */

	if ( ( (pam_err = pam_get_user(pamh, &target_user, NULL)) != PAM_SUCCESS )
			|| ( orig_user == NULL ) )  {
		PAM_ERROR("Error recovering username.");	
		return (pam_err);
	}

	if ( (tpwd = getpwnam(target_user)) == NULL ) {
		PAM_ERROR("Could not get passwd entry for user [%s]",target_user);
		return (PAM_SERVICE_ERR);
	}
	
	if ( openpam_get_option(pamh, PAM_OPT_ROOT_ONLY) ) {
		/* if su to non-root -> ignore */
		if (tpwd->pw_uid != 0) 
			return (PAM_AUTH_ERR);
	}
	
	/* Get info for originating user. Who called su? */

	if ( ( (pam_err = pam_get_user(pamh, &orig_user, NULL)) != PAM_SUCCESS )
                        || ( orig_user == NULL ) )  {                                        
	        PAM_ERROR("Error recovering username.");
		return (pam_err);
	}

	if ( (opwd = getpwnam(orig_user)) == NULL ) {
		PAM_ERROR("Could not get passwd entry for user [%s]",orig_user);
		return (PAM_SERVICE_ERR);
	}
	
	/* We now have all user info we need */

	if ( (group = getgrnam("wheel")) == NULL ) { 
		group = getgrgid(0); 
	}
	
	/* Check wheel or group with GID 0 have any members */

	if (!group || (!group->gr_mem && (opwd->pw_gid != group->gr_gid))) {
		PAM_LOG("Group wheel or with GID 0 has no members");
		return (PAM_AUTH_ERR);
	}
	/* Check user's membership to the interested groups */
	member=0;
	user_list = group->gr_mem; 
	while ( !member && user_list && *(user_list) ) {
		if (strncmp(*user_list, orig_user, strlen(orig_user)-1 ) == 0) 
		            member=1;
		
		user_list++;
	}
	
	if ( member || ( opwd->pw_gid == group->gr_gid ) ) { 
		PAM_LOG("Access granted for user '%s' to user '%s'", orig_user, target_user);
		return (PAM_SUCCESS);
	} else { 
		PAM_ERROR("Access denied for user '%s' to user '%s'", orig_user, target_user);
		return (PAM_PERM_DENIED);
	}
}