Deleted Added
full compact
pam_getenvlist.c (91094) pam_getenvlist.c (91100)
1/*-
2 * Copyright (c) 2002 Networks Associates Technologies, Inc.
3 * All rights reserved.
4 *
5 * This software was developed for the FreeBSD Project by ThinkSec AS and
6 * NAI Labs, the Security Research Division of Network Associates, Inc.
7 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
8 * DARPA CHATS research program.

--- 26 unchanged lines hidden (view full) ---

35 */
36
37#include <stdlib.h>
38#include <string.h>
39
40#include <security/pam_appl.h>
41
42#include "openpam_impl.h"
1/*-
2 * Copyright (c) 2002 Networks Associates Technologies, Inc.
3 * All rights reserved.
4 *
5 * This software was developed for the FreeBSD Project by ThinkSec AS and
6 * NAI Labs, the Security Research Division of Network Associates, Inc.
7 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
8 * DARPA CHATS research program.

--- 26 unchanged lines hidden (view full) ---

35 */
36
37#include <stdlib.h>
38#include <string.h>
39
40#include <security/pam_appl.h>
41
42#include "openpam_impl.h"
43
43/*
44 * XSSO 4.2.1
45 * XSSO 6 page 45
46 *
47 * Returns a list of all the PAM environment variables
48 */
49
50char **
51pam_getenvlist(pam_handle_t *pamh)
52{
53 char **envlist;
54 int i;
55
56 if (pamh == NULL)
57 return (NULL);
58
44/*
45 * XSSO 4.2.1
46 * XSSO 6 page 45
47 *
48 * Returns a list of all the PAM environment variables
49 */
50
51char **
52pam_getenvlist(pam_handle_t *pamh)
53{
54 char **envlist;
55 int i;
56
57 if (pamh == NULL)
58 return (NULL);
59
59 if ((envlist = malloc(sizeof(char *) * (pamh->env_count + 1))) == NULL)
60 envlist = malloc(sizeof(char *) * (pamh->env_count + 1));
61 if (envlist == NULL) {
62 openpam_log(PAM_LOG_ERROR, "%s",
63 pam_strerror(pamh, PAM_BUF_ERR));
60 return (NULL);
64 return (NULL);
65 }
61 for (i = 0; i < pamh->env_count; ++i) {
62 if ((envlist[i] = strdup(pamh->env[i])) == NULL) {
63 while (i)
64 free(envlist[--i]);
65 free(envlist);
66 for (i = 0; i < pamh->env_count; ++i) {
67 if ((envlist[i] = strdup(pamh->env[i])) == NULL) {
68 while (i)
69 free(envlist[--i]);
70 free(envlist);
71 openpam_log(PAM_LOG_ERROR, "%s",
72 pam_strerror(pamh, PAM_BUF_ERR));
66 return (NULL);
67 }
68 }
73 return (NULL);
74 }
75 }
76 envlist[i] = NULL;
77 openpam_log(PAM_LOG_DEBUG, "returning %d variables\n", pamh->env_count);
69 return (envlist);
70}
78 return (envlist);
79}
80
81/**
82 * The =pam_getenvlist function returns a copy of the given PAM context's
83 * environment list as a pointer to an array of strings.
84 * The last element in the array is =NULL.
85 * The pointer is suitable for assignment to {Va environ}.
86 *
87 * The array and the strings it lists are allocated using =malloc, and
88 * should be released using =free after use:
89 *
90 * char **envlist, **env;
91 *
92 * envlist = environ;
93 * environ = pam_getenvlist(pamh);
94 * \/\* do something nifty \*\/
95 * for (env = environ; *env != NULL; env++)
96 * free(*env);
97 * free(environ);
98 * environ = envlist;
99 *
100 * >environ 7
101 * >pam_getenv
102 * >pam_putenv
103 * >pam_setenv
104 */