~ubuntu-branches/ubuntu/raring/sudo/raring

« back to all changes in this revision

Viewing changes to compat/setenv.c

  • Committer: Package Import Robot
  • Author(s): Tyler Hicks
  • Date: 2012-07-16 14:01:42 UTC
  • mfrom: (1.3.22 sid)
  • Revision ID: package-import@ubuntu.com-20120716140142-b0tgau0k6nid4mrf
Tags: 1.8.5p2-1ubuntu1
* Merge from debian/testing (LP: #1024154), remaining changes:
  - debian/patches/keep_home_by_default.patch:
    + Set HOME in initial_keepenv_table.
  - debian/rules:
    + compile with --without-lecture --with-tty-tickets (Ubuntu specific)
    + install man/man8/sudo_root.8 in both flavours (Ubuntu specific)
    + install apport hooks
    + The ubuntu-sudo-as-admin-successful.patch was taken upstream by
      Debian however it requires a --enable-admin-flag configure flag to
      actually enable it in both flavours.
  - debian/control:
    + Mark Debian Vcs-* as XS-Debian-Vcs-*
    + update debian/control
  - debian/sudoers:
    + grant admin group sudo access
  - debian/source_sudo.py, debian/sudo-ldap.dirs, debian/sudo.dirs:
    + add usr/share/apport/package-hooks
  - debian/sudo.pam:
    + Use pam_env to read /etc/environment and /etc/default/locale
      environment files. Reading ~/.pam_environment is not permitted due to
      security reasons.
* Dropped changes:
  - debian/patches/lp927828-fix-abort-in-pam-modules-when-timestamp-valid.patch
    + Fixed upstream in 1.8.5
  - debian/patches/CVE-2012-2337.patch:
    + Fixed upstream in 1.8.4p5
  - debian/patches/pam_env_merge.patch:
    + Feature released upstream in 1.8.5
  - debian/{sudo,sudo-ldap}.{preinst,postinst,postrm}:
    + Drop Ubuntu-specific sudoers file migration code because the only
      upgrade path to quantal is from precise. All necessary sudoers file
      migration will have already been done by the time this version of the
      sudo package is installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
3
 
 *
4
 
 * Permission to use, copy, modify, and distribute this software for any
5
 
 * purpose with or without fee is hereby granted, provided that the above
6
 
 * copyright notice and this permission notice appear in all copies.
7
 
 *
8
 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 
 */
16
 
 
17
 
#include <config.h>
18
 
 
19
 
#include <sys/types.h>
20
 
 
21
 
#include <stdio.h>
22
 
#ifdef STDC_HEADERS
23
 
# include <stdlib.h>
24
 
# include <stddef.h>
25
 
#else
26
 
# ifdef HAVE_STDLIB_H
27
 
#  include <stdlib.h>
28
 
# endif
29
 
#endif /* STDC_HEADERS */
30
 
#ifdef HAVE_STRING_H
31
 
# include <string.h>
32
 
#endif /* HAVE_STRING_H */
33
 
#ifdef HAVE_STRINGS_H
34
 
# include <strings.h>
35
 
#endif /* HAVE_STRINGS_H */
36
 
#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
37
 
# include <malloc.h>
38
 
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
39
 
#include <errno.h>
40
 
 
41
 
#include "missing.h"
42
 
 
43
 
int
44
 
setenv(const char *var, const char *val, int overwrite)
45
 
{
46
 
    char *envstr, *dst;
47
 
    const char *src;
48
 
    size_t esize;
49
 
 
50
 
    if (!var || *var == '\0') {
51
 
        errno = EINVAL;
52
 
        return -1;
53
 
    }
54
 
 
55
 
    /*
56
 
     * POSIX says a var name with '=' is an error but BSD
57
 
     * just ignores the '=' and anything after it.
58
 
     */
59
 
    for (src = var; *src != '\0' && *src != '='; src++)
60
 
        ;
61
 
    esize = (size_t)(src - var) + 2;
62
 
    if (val) {
63
 
        esize += strlen(val);   /* glibc treats a NULL val as "" */
64
 
    }
65
 
 
66
 
    /* Allocate and fill in envstr. */
67
 
    if ((envstr = malloc(esize)) == NULL)
68
 
        return -1;
69
 
    for (src = var, dst = envstr; *src != '\0' && *src != '=';)
70
 
        *dst++ = *src++;
71
 
    *dst++ = '=';
72
 
    if (val) {
73
 
        for (src = val; *src != '\0';)
74
 
            *dst++ = *src++;
75
 
    }
76
 
    *dst = '\0';
77
 
 
78
 
    if (!overwrite && getenv(var) != NULL) {
79
 
        free(envstr);
80
 
        return 0;
81
 
    }
82
 
    return putenv(envstr);
83
 
}