pam_getenvlist.c revision 91094
1169695Skan/*-
2169695Skan * Copyright (c) 2002 Networks Associates Technologies, Inc.
3169695Skan * All rights reserved.
4169695Skan *
5169695Skan * This software was developed for the FreeBSD Project by ThinkSec AS and
6169695Skan * NAI Labs, the Security Research Division of Network Associates, Inc.
7169695Skan * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
8169695Skan * DARPA CHATS research program.
9169695Skan *
10169695Skan * Redistribution and use in source and binary forms, with or without
11169695Skan * modification, are permitted provided that the following conditions
12169695Skan * are met:
13169695Skan * 1. Redistributions of source code must retain the above copyright
14169695Skan *    notice, this list of conditions and the following disclaimer.
15169695Skan * 2. Redistributions in binary form must reproduce the above copyright
16169695Skan *    notice, this list of conditions and the following disclaimer in the
17169695Skan *    documentation and/or other materials provided with the distribution.
18169695Skan * 3. The name of the author may not be used to endorse or promote
19169695Skan *    products derived from this software without specific prior written
20169695Skan *    permission.
21169695Skan *
22169695Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23169695Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24169695Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25169695Skan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26169695Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27169695Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28169695Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29169695Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30169695Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31169695Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32169695Skan * SUCH DAMAGE.
33169695Skan *
34169695Skan * $Id$
35169695Skan */
36169695Skan
37169695Skan#include <stdlib.h>
38169695Skan#include <string.h>
39169695Skan
40169695Skan#include <security/pam_appl.h>
41169695Skan
42169695Skan#include "openpam_impl.h"
43169695Skan/*
44169695Skan * XSSO 4.2.1
45169695Skan * XSSO 6 page 45
46169695Skan *
47169695Skan * Returns a list of all the PAM environment variables
48169695Skan */
49169695Skan
50169695Skanchar **
51169695Skanpam_getenvlist(pam_handle_t *pamh)
52169695Skan{
53169695Skan	char **envlist;
54169695Skan	int i;
55169695Skan
56169695Skan	if (pamh == NULL)
57169695Skan		return (NULL);
58169695Skan
59169695Skan	if ((envlist = malloc(sizeof(char *) * (pamh->env_count + 1))) == NULL)
60169695Skan		return (NULL);
61169695Skan	for (i = 0; i < pamh->env_count; ++i) {
62169695Skan		if ((envlist[i] = strdup(pamh->env[i])) == NULL) {
63169695Skan			while (i)
64169695Skan				free(envlist[--i]);
65169695Skan			free(envlist);
66169695Skan			return (NULL);
67169695Skan		}
68169695Skan	}
69169695Skan	return (envlist);
70169695Skan}
71169695Skan