~ubuntu-branches/ubuntu/saucy/sudo/saucy

« back to all changes in this revision

Viewing changes to plugins/sudoers/sudo_nss.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-11-16 09:31:32 UTC
  • mfrom: (1.4.13)
  • Revision ID: package-import@ubuntu.com-20121116093132-ptext55adlzbrq6y
Tags: 1.8.6p3-0ubuntu1
* New upstream release (1.8.6p3).
* Add patch to fix building with sssd when ldap is disabled.
* Drop sudo.manpages and sudo-ldap.manpages as the upstream build system
  now does the right thing here.
* Build the main sudo package with support for sssd, this doesn't add any
  additional build time or runtime dependency. sudo will dynamically load
  the sssd library if 'sss' is listed for the 'sudoers' nss service.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include <sys/types.h>
20
20
#include <sys/param.h>
 
21
#include <sys/stat.h>
 
22
 
21
23
#include <stdio.h>
22
24
#ifdef STDC_HEADERS
23
25
# include <stdlib.h>
47
49
#ifdef HAVE_LDAP
48
50
extern struct sudo_nss sudo_nss_ldap;
49
51
#endif
 
52
#ifdef HAVE_SSSD
 
53
extern struct sudo_nss sudo_nss_sss;
 
54
#endif
50
55
 
51
 
#if defined(HAVE_LDAP) && defined(_PATH_NSSWITCH_CONF)
 
56
#if (defined(HAVE_LDAP) || defined(HAVE_SSSD)) && defined(_PATH_NSSWITCH_CONF)
52
57
/*
53
58
 * Read in /etc/nsswitch.conf
54
59
 * Returns a tail queue of matches.
58
63
{
59
64
    FILE *fp;
60
65
    char *cp;
 
66
#ifdef HAVE_SSSD
 
67
    bool saw_sss = false;
 
68
#endif
61
69
    bool saw_files = false;
62
70
    bool saw_ldap = false;
63
71
    bool got_match = false;
81
89
            if (strcasecmp(cp, "files") == 0 && !saw_files) {
82
90
                tq_append(&snl, &sudo_nss_file);
83
91
                got_match = true;
 
92
#ifdef HAVE_LDAP
84
93
            } else if (strcasecmp(cp, "ldap") == 0 && !saw_ldap) {
85
94
                tq_append(&snl, &sudo_nss_ldap);
86
95
                got_match = true;
 
96
#endif
 
97
#ifdef HAVE_SSSD
 
98
            } else if (strcasecmp(cp, "sss") == 0 && !saw_sss) {
 
99
                tq_append(&snl, &sudo_nss_sss);
 
100
                got_match = true;
 
101
#endif
87
102
            } else if (strcasecmp(cp, "[NOTFOUND=return]") == 0 && got_match) {
88
103
                /* NOTFOUND affects the most recent entry */
89
104
                tq_last(&snl)->ret_if_notfound = true;
90
105
                got_match = false;
 
106
            } else if (strcasecmp(cp, "[SUCCESS=return]") == 0 && got_match) {
 
107
                /* SUCCESS affects the most recent entry */
 
108
                tq_last(&snl)->ret_if_found = true;
 
109
                got_match = false;
91
110
            } else
92
111
                got_match = false;
93
112
        }
104
123
    debug_return_ptr(&snl);
105
124
}
106
125
 
107
 
#else /* HAVE_LDAP && _PATH_NSSWITCH_CONF */
 
126
#else /* (HAVE_LDAP || HAVE_SSSD) && _PATH_NSSWITCH_CONF */
108
127
 
109
 
# if defined(HAVE_LDAP) && defined(_PATH_NETSVC_CONF)
 
128
# if (defined(HAVE_LDAP) || defined(HAVE_SSSD)) && defined(_PATH_NETSVC_CONF)
110
129
 
111
130
/*
112
131
 * Read in /etc/netsvc.conf (like nsswitch.conf on AIX)
117
136
{
118
137
    FILE *fp;
119
138
    char *cp, *ep;
 
139
#ifdef HAVE_SSSD
 
140
    bool saw_sss = false;
 
141
#endif
120
142
    bool saw_files = false;
121
143
    bool saw_ldap = false;
122
144
    bool got_match = false;
151
173
                tq_append(&snl, &sudo_nss_file);
152
174
                got_match = true;
153
175
                ep = &cp[5];
 
176
#ifdef HAVE_LDAP
154
177
            } else if (!saw_ldap && strncasecmp(cp, "ldap", 4) == 0 &&
155
178
                (isspace((unsigned char)cp[4]) || cp[4] == '\0')) {
156
179
                tq_append(&snl, &sudo_nss_ldap);
157
180
                got_match = true;
158
181
                ep = &cp[4];
 
182
#endif
 
183
#ifdef HAVE_SSSD
 
184
            } else if (!saw_sss && strncasecmp(cp, "sss", 3) == 0 &&
 
185
                (isspace((unsigned char)cp[3]) || cp[3] == '\0')) {
 
186
                tq_append(&snl, &sudo_nss_sss);
 
187
                got_match = true;
 
188
                ep = &cp[3];
 
189
#endif
159
190
            } else {
160
191
                got_match = false;
161
192
            }
195
226
    static struct sudo_nss_list snl;
196
227
    debug_decl(sudo_read_nss, SUDO_DEBUG_NSS)
197
228
 
 
229
#  ifdef HAVE_SSSD
 
230
    tq_append(&snl, &sudo_nss_sss);
 
231
#  endif
198
232
#  ifdef HAVE_LDAP
199
233
    tq_append(&snl, &sudo_nss_ldap);
200
234
#  endif
233
267
{
234
268
    struct sudo_nss *nss;
235
269
    struct lbuf defs, privs;
236
 
    int count, olen;
 
270
    struct stat sb;
 
271
    int cols, count, olen;
237
272
    debug_decl(display_privs, SUDO_DEBUG_NSS)
238
273
 
239
 
    lbuf_init(&defs, output, 4, NULL, sudo_user.cols);
240
 
    lbuf_init(&privs, output, 4, NULL, sudo_user.cols);
 
274
    cols = sudo_user.cols;
 
275
    if (fstat(STDOUT_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode))
 
276
        cols = 0;
 
277
    lbuf_init(&defs, output, 4, NULL, cols);
 
278
    lbuf_init(&privs, output, 4, NULL, cols);
241
279
 
242
280
    /* Display defaults from all sources. */
243
281
    lbuf_append(&defs, _("Matching Defaults entries for %s on this host:\n"),
272
310
    tq_foreach_fwd(snl, nss) {
273
311
        count += nss->display_privs(nss, pw, &privs);
274
312
    }
275
 
    if (count) {
276
 
        lbuf_print(&defs);
277
 
        lbuf_print(&privs);
278
 
    } else {
279
 
        printf(_("User %s is not allowed to run sudo on %s.\n"), pw->pw_name,
280
 
            user_shost);
 
313
    if (count == 0) {
 
314
        defs.len = 0;
 
315
        privs.len = 0;
 
316
        lbuf_append(&privs, _("User %s is not allowed to run sudo on %s.\n"),
 
317
            pw->pw_name, user_shost);
281
318
    }
 
319
    lbuf_print(&defs);
 
320
    lbuf_print(&privs);
282
321
 
283
322
    lbuf_destroy(&defs);
284
323
    lbuf_destroy(&privs);