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

« back to all changes in this revision

Viewing changes to plugins/sudoers/iolog_path.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:
46
46
 
47
47
struct path_escape {
48
48
    const char *name;
49
 
    size_t (*copy_fn)(char *, size_t);
 
49
    size_t (*copy_fn)(char *, size_t, char *);
50
50
};
51
51
 
52
 
static size_t fill_seq(char *, size_t);
53
 
static size_t fill_user(char *, size_t);
54
 
static size_t fill_group(char *, size_t);
55
 
static size_t fill_runas_user(char *, size_t);
56
 
static size_t fill_runas_group(char *, size_t);
57
 
static size_t fill_hostname(char *, size_t);
58
 
static size_t fill_command(char *, size_t);
 
52
static size_t fill_seq(char *, size_t, char *);
 
53
static size_t fill_user(char *, size_t, char *);
 
54
static size_t fill_group(char *, size_t, char *);
 
55
static size_t fill_runas_user(char *, size_t, char *);
 
56
static size_t fill_runas_group(char *, size_t, char *);
 
57
static size_t fill_hostname(char *, size_t, char *);
 
58
static size_t fill_command(char *, size_t, char *);
59
59
 
60
 
static struct path_escape escapes[] = {
 
60
/* Note: "seq" must be first in the list. */
 
61
static struct path_escape io_path_escapes[] = {
61
62
    { "seq", fill_seq },
62
63
    { "user", fill_user },
63
64
    { "group", fill_group },
69
70
};
70
71
 
71
72
static size_t
72
 
fill_seq(char *str, size_t strsize)
 
73
fill_seq(char *str, size_t strsize, char *logdir)
73
74
{
74
75
    static char sessid[7];
75
76
    int len;
76
77
    debug_decl(sudoers_io_version, SUDO_DEBUG_UTIL)
77
78
 
78
79
    if (sessid[0] == '\0')
79
 
        io_nextid(def_iolog_dir, sessid);
 
80
        io_nextid(logdir, def_iolog_dir, sessid);
80
81
 
81
82
    /* Path is of the form /var/log/sudo-io/00/00/01. */
82
83
    len = snprintf(str, strsize, "%c%c/%c%c/%c%c", sessid[0],
87
88
}
88
89
 
89
90
static size_t
90
 
fill_user(char *str, size_t strsize)
 
91
fill_user(char *str, size_t strsize, char *unused)
91
92
{
92
93
    debug_decl(fill_user, SUDO_DEBUG_UTIL)
93
94
    debug_return_size_t(strlcpy(str, user_name, strsize));
94
95
}
95
96
 
96
97
static size_t
97
 
fill_group(char *str, size_t strsize)
 
98
fill_group(char *str, size_t strsize, char *unused)
98
99
{
99
100
    struct group *grp;
100
101
    size_t len;
102
103
 
103
104
    if ((grp = sudo_getgrgid(user_gid)) != NULL) {
104
105
        len = strlcpy(str, grp->gr_name, strsize);
105
 
        gr_delref(grp);
 
106
        sudo_gr_delref(grp);
106
107
    } else {
107
108
        len = strlen(str);
108
109
        len = snprintf(str + len, strsize - len, "#%u",
112
113
}
113
114
 
114
115
static size_t
115
 
fill_runas_user(char *str, size_t strsize)
 
116
fill_runas_user(char *str, size_t strsize, char *unused)
116
117
{
117
118
    debug_decl(fill_runas_user, SUDO_DEBUG_UTIL)
118
119
    debug_return_size_t(strlcpy(str, runas_pw->pw_name, strsize));
119
120
}
120
121
 
121
122
static size_t
122
 
fill_runas_group(char *str, size_t strsize)
 
123
fill_runas_group(char *str, size_t strsize, char *unused)
123
124
{
124
125
    struct group *grp;
125
126
    size_t len;
130
131
    } else {
131
132
        if ((grp = sudo_getgrgid(runas_pw->pw_gid)) != NULL) {
132
133
            len = strlcpy(str, grp->gr_name, strsize);
133
 
            gr_delref(grp);
 
134
            sudo_gr_delref(grp);
134
135
        } else {
135
136
            len = strlen(str);
136
137
            len = snprintf(str + len, strsize - len, "#%u",
141
142
}
142
143
 
143
144
static size_t
144
 
fill_hostname(char *str, size_t strsize)
 
145
fill_hostname(char *str, size_t strsize, char *unused)
145
146
{
146
147
    debug_decl(fill_hostname, SUDO_DEBUG_UTIL)
147
148
    debug_return_size_t(strlcpy(str, user_shost, strsize));
148
149
}
149
150
 
150
151
static size_t
151
 
fill_command(char *str, size_t strsize)
 
152
fill_command(char *str, size_t strsize, char *unused)
152
153
{
153
154
    debug_decl(fill_command, SUDO_DEBUG_UTIL)
154
155
    debug_return_size_t(strlcpy(str, user_base, strsize));
165
166
{
166
167
    size_t len, prelen = 0;
167
168
    char *dst, *dst0, *path, *pathend, tmpbuf[PATH_MAX];
 
169
    char *slash = NULL;
168
170
    const char *endbrace, *src = dir;
 
171
    static struct path_escape *escapes;
169
172
    int pass;
170
173
    bool strfit;
171
174
    debug_decl(expand_iolog_path, SUDO_DEBUG_UTIL)
193
196
        switch (pass) {
194
197
        case 0:
195
198
            src = dir;
 
199
            escapes = io_path_escapes + 1; /* skip "${seq}" */
196
200
            break;
197
201
        case 1:
198
202
            /* Trim trailing slashes from dir component. */
199
203
            while (dst - path - 1 > prelen && dst[-1] == '/')
200
204
                dst--;
201
 
            if (slashp)
202
 
                *slashp = dst;
203
 
            src = "/";
204
 
            break;
 
205
            /* The NUL will be replaced with a '/' at the end. */
 
206
            if (dst + 1 >= pathend)
 
207
                goto bad;
 
208
            slash = dst++;
 
209
            continue;
205
210
        case 2:
206
211
            src = file;
 
212
            escapes = io_path_escapes;
207
213
            break;
208
214
        }
209
215
        dst0 = dst;
220
226
                                break;
221
227
                        }
222
228
                        if (esc->name != NULL) {
223
 
                            len = esc->copy_fn(dst, (size_t)(pathend - dst));
 
229
                            len = esc->copy_fn(dst, (size_t)(pathend - dst),
 
230
                                path + prelen);
224
231
                            if (len >= (size_t)(pathend - dst))
225
232
                                goto bad;
226
233
                            dst += len;
275
282
            *dst = '\0';
276
283
        }
277
284
    }
 
285
    if (slashp)
 
286
        *slashp = slash;
 
287
    *slash = '/';
278
288
 
279
289
    debug_return_str(path);
280
290
bad: