~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/parse_job.c

* Merge of 'setuid' + 'setgid' stanzas from
  Evan Broder (lp:~broder/upstart/drop-privileges).

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
                               const char *file, size_t len,
210
210
                               size_t *pos, size_t *lineno)
211
211
        __attribute__ ((warn_unused_result));
 
212
static int stanza_setuid      (JobClass *class, NihConfigStanza *stanza,
 
213
                               const char *file, size_t len,
 
214
                               size_t *pos, size_t *lineno)
 
215
        __attribute__ ((warn_unused_result));
 
216
static int stanza_setgid      (JobClass *class, NihConfigStanza *stanza,
 
217
                               const char *file, size_t len,
 
218
                               size_t *pos, size_t *lineno)
 
219
        __attribute__ ((warn_unused_result));
212
220
static int stanza_debug       (JobClass *class, NihConfigStanza *stanza,
213
221
                               const char *file, size_t len,
214
222
                               size_t *pos, size_t *lineno)
253
261
        { "limit",       (NihConfigHandler)stanza_limit       },
254
262
        { "chroot",      (NihConfigHandler)stanza_chroot      },
255
263
        { "chdir",       (NihConfigHandler)stanza_chdir       },
 
264
        { "setuid",      (NihConfigHandler)stanza_setuid      },
 
265
        { "setgid",      (NihConfigHandler)stanza_setgid      },
256
266
        { "debug",       (NihConfigHandler)stanza_debug       },
257
267
        { "manual",      (NihConfigHandler)stanza_manual      },
258
268
 
2534
2544
 
2535
2545
        return nih_config_skip_comment (file, len, pos, lineno);
2536
2546
}
 
2547
 
 
2548
/**
 
2549
 * stanza_setuid:
 
2550
 * @class: job class being parsed,
 
2551
 * @stanza: stanza found,
 
2552
 * @file: file or string to parse,
 
2553
 * @len: length of @file,
 
2554
 * @pos: offset within @file,
 
2555
 * @lineno: line number.
 
2556
 *
 
2557
 * Parse a setuid stanza from @file, extracting a single argument
 
2558
 * containing a user name.
 
2559
 *
 
2560
 * Returns: zero on success, negative value on error.
 
2561
 **/
 
2562
static int
 
2563
stanza_setuid (JobClass        *class,
 
2564
               NihConfigStanza *stanza,
 
2565
               const char      *file,
 
2566
               size_t           len,
 
2567
               size_t          *pos,
 
2568
               size_t          *lineno)
 
2569
{
 
2570
        nih_assert (class != NULL);
 
2571
        nih_assert (stanza != NULL);
 
2572
        nih_assert (file != NULL);
 
2573
        nih_assert (pos != NULL);
 
2574
 
 
2575
        if (class->setuid)
 
2576
                nih_unref (class->setuid, class);
 
2577
 
 
2578
        class->setuid = nih_config_next_arg (class, file, len, pos, lineno);
 
2579
        if (! class->setuid)
 
2580
                return -1;
 
2581
 
 
2582
        return nih_config_skip_comment (file, len, pos, lineno);
 
2583
}
 
2584
 
 
2585
/**
 
2586
 * stanza_setgid:
 
2587
 * @class: job class being parsed,
 
2588
 * @stanza: stanza found,
 
2589
 * @file: file or string to parse,
 
2590
 * @len: length of @file,
 
2591
 * @pos: offset within @file,
 
2592
 * @lineno: line number.
 
2593
 *
 
2594
 * Parse a setgid stanza from @file, extracting a single argument
 
2595
 * containing a group name.
 
2596
 *
 
2597
 * Returns: zero on success, negative value on error.
 
2598
 **/
 
2599
static int
 
2600
stanza_setgid (JobClass        *class,
 
2601
               NihConfigStanza *stanza,
 
2602
               const char      *file,
 
2603
               size_t           len,
 
2604
               size_t          *pos,
 
2605
               size_t          *lineno)
 
2606
{
 
2607
        nih_assert (class != NULL);
 
2608
        nih_assert (stanza != NULL);
 
2609
        nih_assert (file != NULL);
 
2610
        nih_assert (pos != NULL);
 
2611
 
 
2612
        if (class->setgid)
 
2613
                nih_unref (class->setgid, class);
 
2614
 
 
2615
        class->setgid = nih_config_next_arg (class, file, len, pos, lineno);
 
2616
        if (! class->setgid)
 
2617
                return -1;
 
2618
 
 
2619
        return nih_config_skip_comment (file, len, pos, lineno);
 
2620
}