1#include <stdlib.h>
2#include <string.h>
3
4#include <security/pam_appl.h>
5
6#include "openpam_impl.h"
7
8/*
9 * OpenPAM extension
10 *
11 * Unset an environment variable
12 * Mirrors unsetenv(3)
13 */
14
15int
16pam_unsetenv(pam_handle_t *pamh, const char *name)
17{
18	int i;
19
20	ENTER();
21	if (pamh == NULL)
22		RETURNC(PAM_SYSTEM_ERR);
23
24	/* sanity checks */
25	if (name == NULL)
26		RETURNC(PAM_SYSTEM_ERR);
27
28	/* find and remove the variable from the environment */
29	if ((i = openpam_findenv(pamh, name, strlen(name))) >= 0) {
30		memset(pamh->env[i], 0, strlen(pamh->env[i]));
31		FREE(pamh->env[i]);
32		pamh->env[i] = pamh->env[pamh->env_count-1];
33		pamh->env[pamh->env_count-1] = NULL;
34		pamh->env_count--;
35		RETURNC(PAM_SUCCESS);
36	}
37
38	RETURNC(PAM_SYSTEM_ERR);
39}
40
41/*
42 * Error codes:
43 *
44 *	=pam_unsetenv
45 *	PAM_SYSTEM_ERR
46 */
47
48/**
49 * The =pam_unsetenv function unsets a environment variable.
50 * Its semantics are similar to those of =unsetenv, but it modifies the PAM
51 * context's environment list instead of the application's.
52 *
53 * >pam_getenv
54 * >pam_getenvlist
55 * >pam_putenv
56 */
57