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

« back to all changes in this revision

Viewing changes to plugins/sudoers/iolog.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:
135
135
 * Uses file locking to avoid sequence number collisions.
136
136
 */
137
137
void
138
 
io_nextid(char *iolog_dir, char sessid[7])
 
138
io_nextid(char *iolog_dir, char *iolog_dir_fallback, char sessid[7])
139
139
{
140
140
    struct stat sb;
141
141
    char buf[32], *ep;
172
172
        log_fatal(USE_ERRNO, _("unable to open %s"), pathbuf);
173
173
    lock_file(fd, SUDO_LOCK);
174
174
 
175
 
    /* Read seq number (base 36). */
176
 
    nread = read(fd, buf, sizeof(buf));
177
 
    if (nread != 0) {
178
 
        if (nread == -1)
179
 
            log_fatal(USE_ERRNO, _("unable to read %s"), pathbuf);
180
 
        id = strtoul(buf, &ep, 36);
181
 
        if (buf == ep || id >= SESSID_MAX)
182
 
            log_fatal(0, _("invalid sequence number %s"), pathbuf);
 
175
    /*
 
176
     * If there is no seq file in iolog_dir and a fallback dir was
 
177
     * specified, look for seq in the fallback dir.  This is to work
 
178
     * around a bug in sudo 1.8.5 and older where iolog_dir was not
 
179
     * expanded before the sequence number was updated.
 
180
     */
 
181
    if (iolog_dir_fallback != NULL && fstat(fd, &sb) == 0 && sb.st_size == 0) {
 
182
        char fallback[PATH_MAX];
 
183
 
 
184
        len = snprintf(fallback, sizeof(fallback), "%s/seq",
 
185
            iolog_dir_fallback);
 
186
        if (len > 0 && len < sizeof(fallback)) {
 
187
            int fd2 = open(fallback, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
 
188
            if (fd2 != -1) {
 
189
                nread = read(fd2, buf, sizeof(buf));
 
190
                if (nread > 0) {
 
191
                    id = strtoul(buf, &ep, 36);
 
192
                    if (buf == ep || id >= SESSID_MAX)
 
193
                        id = 0;
 
194
                }
 
195
                close(fd2);
 
196
            }
 
197
        }
 
198
    }
 
199
 
 
200
    /* Read current seq number (base 36). */
 
201
    if (id == 0) {
 
202
        nread = read(fd, buf, sizeof(buf));
 
203
        if (nread != 0) {
 
204
            if (nread == -1)
 
205
                log_fatal(USE_ERRNO, _("unable to read %s"), pathbuf);
 
206
            id = strtoul(buf, &ep, 36);
 
207
            if (buf == ep || id >= SESSID_MAX)
 
208
                log_fatal(0, _("invalid sequence number %s"), pathbuf);
 
209
        }
183
210
    }
184
211
    id++;
185
212
 
198
225
    sessid[6] = '\0';
199
226
 
200
227
    /* Rewind and overwrite old seq file. */
201
 
    if (lseek(fd, 0, SEEK_SET) == (off_t)-1 || write(fd, buf, 7) != 7)
 
228
    if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1 || write(fd, buf, 7) != 7)
202
229
        log_fatal(USE_ERRNO, _("unable to write to %s"), pathbuf);
203
230
    close(fd);
204
231
 
476
503
        /* Get next session ID and convert it into a path. */
477
504
        tofree = emalloc(sizeof(_PATH_SUDO_IO_LOGDIR) + sizeof(sessid) + 2);
478
505
        memcpy(tofree, _PATH_SUDO_IO_LOGDIR, sizeof(_PATH_SUDO_IO_LOGDIR));
479
 
        io_nextid(tofree, sessid);
 
506
        io_nextid(tofree, NULL, sessid);
480
507
        snprintf(tofree + sizeof(_PATH_SUDO_IO_LOGDIR), sizeof(sessid) + 2,
481
508
            "%c%c/%c%c/%c%c", sessid[0], sessid[1], sessid[2], sessid[3],
482
509
            sessid[4], sessid[5]);
565
592
done:
566
593
    efree(tofree);
567
594
    if (details.runas_pw)
568
 
        pw_delref(details.runas_pw);
 
595
        sudo_pw_delref(details.runas_pw);
569
596
    sudo_endpwent();
570
597
    if (details.runas_gr)
571
 
        gr_delref(details.runas_gr);
 
598
        sudo_gr_delref(details.runas_gr);
572
599
    sudo_endgrent();
573
600
 
574
601
    debug_return_bool(rval);
683
710
    return sudoers_io_log(buf, len, IOFD_STDERR);
684
711
}
685
712
 
686
 
struct io_plugin sudoers_io = {
 
713
__dso_public struct io_plugin sudoers_io = {
687
714
    SUDO_IO_PLUGIN,
688
715
    SUDO_API_VERSION,
689
716
    sudoers_io_open,