Merge lp:~goraxe/upstart/user_sid into lp:~canonical-scott/upstart/trunk

Proposed by goraxe
Status: Superseded
Proposed branch: lp:~goraxe/upstart/user_sid
Merge into: lp:~canonical-scott/upstart/trunk
Diff against target: 616 lines (+460/-2)
8 files modified
init/job_class.c (+3/-0)
init/job_class.h (+3/-0)
init/job_process.c (+89/-0)
init/job_process.h (+6/-1)
init/parse_job.c (+85/-0)
init/tests/test_job_class.c (+2/-0)
init/tests/test_job_process.c (+47/-1)
init/tests/test_parse_job.c (+225/-0)
To merge this branch: bzr merge lp:~goraxe/upstart/user_sid
Reviewer Review Type Date Requested Status
Scott James Remnant (Canonical) Pending
Review via email: mp+31905@code.launchpad.net

This proposal has been superseded by a proposal from 2011-04-27.

Description of the change

adds a user stanza to the config set, job_process_spawn uses this to setuid before exec-ing

proposing for merge to get feedback/review on code, approach, tests, error handling etc.

To post a comment you must log in.
Revision history for this message
Johan Kiviniemi (ion) wrote :

There’s some inconsistent use of whitespace. There also are some superfluous whitespace changes to preexisting code.

Asserting getpwnam doesn’t fail might not be the best thing to do for an init daemon.

The success of the setuid call is not verified.

lp:~goraxe/upstart/user_sid updated
1244. By goraxe

convert indentation to spaces, minimise white space noise

1245. By goraxe

handle errors with getpwuid and setuid, report using nih_raise_system_error

1246. By goraxe

change stanzer to uid, add gid, & initgroups

1247. By goraxe

fix white space

Revision history for this message
termie (termie) wrote :

ping?

Revision history for this message
goraxe (goraxe) wrote :

pong

> -----Original Message-----
> From: <email address hidden> [mailto:<email address hidden>] On Behalf Of
> termie
> Sent: January 12, 2011 1:36 PM
> To: <email address hidden>
> Subject: Re: [Merge] lp:~goraxe/upstart/user_sid into lp:upstart
>
> ping?
> --
> https://code.launchpad.net/~goraxe/upstart/user_sid/+merge/31905
> You are the owner of lp:~goraxe/upstart/user_sid.

Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
Company Reg No 2096520. VAT Reg No GB 991 2418 08.

Revision history for this message
Scott James Remnant (scott) wrote :

At a first pass, this looks ok to me. But I'd like to do another pass or two before approving.

Could you change the proposed branch to be the new lp:upstart to make tracking easier?

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hello!

New message, please read <http://okna-blagodat.com/blood.php?md2x0>

<email address hidden>

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hey,

I've got some good news for you, read more about it here <http://raryndetho.spookpictures.com/score.php?xl6>

Later, <email address hidden>

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Greetings,

Just take a look at that new store, they have so many cool things, they also have a very nice on-line store <http://attach.carnow.ca/lnril>

philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Yo!

Have you read this new book already? I'm so delighted with it, please read it here http://extra.sixpacksoul.com/5958

Hugs, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hey,

I'd like to show you a nice gift a friend of mine gave me recently, it's something really cool)) Please take a look http://harjap.com/coach.php?8a8b

Hope this helps, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hello,

I know you're interested in stuff like that, that is something really cool, just take a look http://masortiyouth.org/cycle.php?e5e4

Hope this helps, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Dear,

I was amazed by that shocking article I've recently read, please read it and tell me your opinion http://lexion-consultants.com/vs.php?2120

Warmest regards, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hello friend,

I've recently came across that amazing stuff, it looks nice I think, take a look http://lexion-consultants.com/rack.php?a4a5

Yours sincerely, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Yo!

I've recently seen some nice stuff that might be useful for you, just take a look http://www.tcsoluciones.cl/less.php?1110

My Best, philipp

Unmerged revisions

1247. By goraxe

fix white space

1246. By goraxe

change stanzer to uid, add gid, & initgroups

1245. By goraxe

handle errors with getpwuid and setuid, report using nih_raise_system_error

1244. By goraxe

convert indentation to spaces, minimise white space noise

1243. By goraxe

become the user of the class

1242. By goraxe

set user to null in job_new

1241. By goraxe

add user to parser

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'init/job_class.c'
--- init/job_class.c 2009-07-09 11:50:19 +0000
+++ init/job_class.c 2010-08-10 22:45:55 +0000
@@ -218,6 +218,9 @@
218 class->chroot = NULL;218 class->chroot = NULL;
219 class->chdir = NULL;219 class->chdir = NULL;
220220
221 class->uid = NULL;
222 class->gid = NULL;
223
221 class->deleted = FALSE;224 class->deleted = FALSE;
222225
223 return class;226 return class;
224227
=== modified file 'init/job_class.h'
--- init/job_class.h 2009-07-09 11:01:53 +0000
+++ init/job_class.h 2010-08-10 22:45:55 +0000
@@ -98,6 +98,7 @@
98 * @chroot: root directory of process (implies @chdir if not set),98 * @chroot: root directory of process (implies @chdir if not set),
99 * @chdir: working directory of process,99 * @chdir: working directory of process,
100 * @deleted: whether job should be deleted when finished.100 * @deleted: whether job should be deleted when finished.
101 * @uid: holds the name or id of a user who's id should be set via setid
101 *102 *
102 * This structure holds the configuration of a known task or service that103 * This structure holds the configuration of a known task or service that
103 * should be tracked by the init daemon; as tasks and services are104 * should be tracked by the init daemon; as tasks and services are
@@ -146,6 +147,8 @@
146 char *chroot;147 char *chroot;
147 char *chdir;148 char *chdir;
148149
150 char *uid;
151 char *gid;
149 int deleted;152 int deleted;
150} JobClass;153} JobClass;
151154
152155
=== modified file 'init/job_process.c'
--- init/job_process.c 2010-02-26 15:31:13 +0000
+++ init/job_process.c 2010-08-10 22:45:55 +0000
@@ -38,6 +38,8 @@
38#include <stdlib.h>38#include <stdlib.h>
39#include <string.h>39#include <string.h>
40#include <unistd.h>40#include <unistd.h>
41#include <pwd.h>
42#include <grp.h>
4143
42#include <nih/macros.h>44#include <nih/macros.h>
43#include <nih/alloc.h>45#include <nih/alloc.h>
@@ -522,6 +524,68 @@
522 }524 }
523 }525 }
524526
527 /* drop privilages */
528 if (class->uid) {
529 struct passwd *pw;
530 uid_t uid;
531 gid_t gid;
532 char *user;
533 /* convet value of uid to numerical form */
534 uid = strtol(class->uid, NULL, 10);
535 /* if failed assume user and lookup via nss */
536 if (uid == 0 && errno == EINVAL) {
537 pw = getpwnam (class->uid);
538 if (pw == NULL) {
539 nih_error_raise_system ();
540 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_USER, 0);
541 }
542 } else {
543 /* we need to lookup real user name */
544 pw = getpwuid (uid);
545 if (pw == NULL) {
546 nih_error_raise_system ();
547 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_USER, 0);
548 }
549 }
550
551 uid = pw->pw_uid;
552 gid = pw->pw_gid;
553 user = pw->pw_name;
554 /* now check to see if we have been given a group */
555 if (class->gid) {
556 struct group *gr;
557
558 gid = strtol(class->gid, NULL, 10);
559 if (gid == 0 && errno == EINVAL) {
560 gr = getgrnam(class->gid);
561 if (gr == NULL) {
562 nih_error_raise_system ();
563 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_GROUP, 0);
564 }
565 } else {
566 gr = getgrgid (gid);
567 if (gr == NULL) {
568 nih_error_raise_system ();
569 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_GROUP, 0);
570 }
571 }
572
573 gid = gr->gr_gid;
574 }
575 if (setuid (uid) < 0) {
576 nih_error_raise_system ();
577 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETUID, 0);
578 }
579 if (setgid (gid) < 0) {
580 nih_error_raise_system ();
581 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETGID, 0);
582 }
583 if (initgroups(user, gid) < 0) {
584 nih_error_raise_system ();
585 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_INITGROUPS, 0);
586 }
587 }
588
525 /* Execute the process, if we escape from here it failed */589 /* Execute the process, if we escape from here it failed */
526 if (execvp (argv[0], argv) < 0) {590 if (execvp (argv[0], argv) < 0) {
527 nih_error_raise_system ();591 nih_error_raise_system ();
@@ -710,6 +774,31 @@
710 err, _("unable to execute: %s"),774 err, _("unable to execute: %s"),
711 strerror (err->errnum)));775 strerror (err->errnum)));
712 break;776 break;
777 case JOB_PROCESS_ERROR_USER:
778 err->error.message = NIH_MUST (nih_sprintf (
779 err, _("unable to find user for job: %s"),
780 strerror (err->errnum)));
781 break;
782 case JOB_PROCESS_ERROR_SETUID:
783 err->error.message = NIH_MUST (nih_sprintf (
784 err, _("unable to setuid: %s"),
785 strerror (err->errnum)));
786 break;
787 case JOB_PROCESS_ERROR_SETGID:
788 err->error.message = NIH_MUST (nih_sprintf (
789 err, _("unable to setgid: %s"),
790 strerror (err->errnum)));
791 break;
792 case JOB_PROCESS_ERROR_GROUP:
793 err->error.message = NIH_MUST (nih_sprintf (
794 err, _("unable to find group for job: %s"),
795 strerror (err->errnum)));
796 break;
797 case JOB_PROCESS_ERROR_INITGROUPS:
798 err->error.message = NIH_MUST (nih_sprintf (
799 err, _("unable to initgroups: %s"),
800 strerror (err->errnum)));
801 break;
713 default:802 default:
714 nih_assert_not_reached ();803 nih_assert_not_reached ();
715 }804 }
716805
=== modified file 'init/job_process.h'
--- init/job_process.h 2009-07-09 11:01:53 +0000
+++ init/job_process.h 2010-08-10 22:45:55 +0000
@@ -45,7 +45,12 @@
45 JOB_PROCESS_ERROR_CHROOT,45 JOB_PROCESS_ERROR_CHROOT,
46 JOB_PROCESS_ERROR_CHDIR,46 JOB_PROCESS_ERROR_CHDIR,
47 JOB_PROCESS_ERROR_PTRACE,47 JOB_PROCESS_ERROR_PTRACE,
48 JOB_PROCESS_ERROR_EXEC48 JOB_PROCESS_ERROR_EXEC,
49 JOB_PROCESS_ERROR_USER,
50 JOB_PROCESS_ERROR_GROUP,
51 JOB_PROCESS_ERROR_SETUID,
52 JOB_PROCESS_ERROR_SETGID,
53 JOB_PROCESS_ERROR_INITGROUPS
49} JobProcessErrorType;54} JobProcessErrorType;
5055
51/**56/**
5257
=== modified file 'init/parse_job.c'
--- init/parse_job.c 2010-03-31 17:29:24 +0000
+++ init/parse_job.c 2010-08-10 22:45:55 +0000
@@ -210,6 +210,14 @@
210 size_t *pos, size_t *lineno)210 size_t *pos, size_t *lineno)
211 __attribute__ ((warn_unused_result));211 __attribute__ ((warn_unused_result));
212212
213static int stanza_uid (JobClass *class, NihConfigStanza *stanza,
214 const char *file, size_t len,
215 size_t *pos, size_t *lineno)
216 __attribute__ ((warn_unused_result));
217static int stanza_gid (JobClass *class, NihConfigStanza *stanza,
218 const char *file, size_t len,
219 size_t *pos, size_t *lineno)
220 __attribute__ ((warn_unused_result));
213221
214/**222/**
215 * stanzas:223 * stanzas:
@@ -245,6 +253,8 @@
245 { "limit", (NihConfigHandler)stanza_limit },253 { "limit", (NihConfigHandler)stanza_limit },
246 { "chroot", (NihConfigHandler)stanza_chroot },254 { "chroot", (NihConfigHandler)stanza_chroot },
247 { "chdir", (NihConfigHandler)stanza_chdir },255 { "chdir", (NihConfigHandler)stanza_chdir },
256 { "uid", (NihConfigHandler)stanza_uid },
257 { "gid", (NihConfigHandler)stanza_gid },
248258
249 NIH_CONFIG_LAST259 NIH_CONFIG_LAST
250};260};
@@ -2391,3 +2401,78 @@
23912401
2392 return nih_config_skip_comment (file, len, pos, lineno);2402 return nih_config_skip_comment (file, len, pos, lineno);
2393}2403}
2404
2405
2406/**
2407 * stanza_uid:
2408 * @class: job class being parsed,
2409 * @stanza: stanza found,
2410 * @file: file or string to parse,
2411 * @len: length of @file,
2412 * @pos: offset within @file,
2413 * @lineno: line number.
2414 *
2415 * Parse a user stanza from @file, extracting a single argument
2416 * containing a user to drop priviagles to.
2417 *
2418 * Returns: zero on success, negative value on error.
2419 **/
2420static int
2421stanza_uid (JobClass *class,
2422 NihConfigStanza *stanza,
2423 const char *file,
2424 size_t len,
2425 size_t *pos,
2426 size_t *lineno)
2427{
2428 nih_assert (class != NULL);
2429 nih_assert (stanza != NULL);
2430 nih_assert (file != NULL);
2431 nih_assert (pos != NULL);
2432
2433 if (class->uid)
2434 nih_unref (class->uid, class);
2435 /* FIXME lookup uid */
2436 class->uid = nih_config_next_arg (class, file, len, pos, lineno);
2437 if (! class->uid)
2438 return -1;
2439
2440 return nih_config_skip_comment (file, len, pos, lineno);
2441}
2442
2443/**
2444 * stanza_gid:
2445 * @class: job class being parsed,
2446 * @stanza: stanza found,
2447 * @file: file or string to parse,
2448 * @len: length of @file,
2449 * @pos: offset within @file,
2450 * @lineno: line number.
2451 *
2452 * Parse a gid stanza from @file, extracting a single argument
2453 * containing a group to drop priviagles to.
2454 *
2455 * Returns: zero on success, negative value on error.
2456 **/
2457static int
2458stanza_gid (JobClass *class,
2459 NihConfigStanza *stanza,
2460 const char *file,
2461 size_t len,
2462 size_t *pos,
2463 size_t *lineno)
2464{
2465 nih_assert (class != NULL);
2466 nih_assert (stanza != NULL);
2467 nih_assert (file != NULL);
2468 nih_assert (pos != NULL);
2469
2470 if (class->gid)
2471 nih_unref (class->gid, class);
2472
2473 class->gid = nih_config_next_arg (class, file, len, pos, lineno);
2474 if (! class->gid)
2475 return -1;
2476
2477 return nih_config_skip_comment (file, len, pos, lineno);
2478}
23942479
=== modified file 'init/tests/test_job_class.c'
--- init/tests/test_job_class.c 2009-07-09 11:50:19 +0000
+++ init/tests/test_job_class.c 2010-08-10 22:45:55 +0000
@@ -139,6 +139,8 @@
139139
140 TEST_EQ_P (class->chroot, NULL);140 TEST_EQ_P (class->chroot, NULL);
141 TEST_EQ_P (class->chdir, NULL);141 TEST_EQ_P (class->chdir, NULL);
142 TEST_EQ_P (class->uid, NULL);
143 TEST_EQ_P (class->gid, NULL);
142 TEST_FALSE (class->deleted);144 TEST_FALSE (class->deleted);
143145
144 nih_free (class);146 nih_free (class);
145147
=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c 2010-02-26 15:31:13 +0000
+++ init/tests/test_job_process.c 2010-08-10 22:45:55 +0000
@@ -36,6 +36,7 @@
36#include <stdlib.h>36#include <stdlib.h>
37#include <string.h>37#include <string.h>
38#include <unistd.h>38#include <unistd.h>
39#include <pwd.h>
3940
40#include <nih/macros.h>41#include <nih/macros.h>
41#include <nih/string.h>42#include <nih/string.h>
@@ -63,7 +64,8 @@
63 TEST_PIDS,64 TEST_PIDS,
64 TEST_CONSOLE,65 TEST_CONSOLE,
65 TEST_PWD,66 TEST_PWD,
66 TEST_ENVIRONMENT67 TEST_ENVIRONMENT,
68 TEST_USER
67};69};
6870
69static char *argv0;71static char *argv0;
@@ -75,6 +77,8 @@
75 FILE *out;77 FILE *out;
76 char tmpname[PATH_MAX], path[PATH_MAX];78 char tmpname[PATH_MAX], path[PATH_MAX];
77 int i;79 int i;
80 struct passwd *pw;
81 int uid;
7882
79 strcpy (tmpname, filename);83 strcpy (tmpname, filename);
80 strcat (tmpname, ".tmp");84 strcat (tmpname, ".tmp");
@@ -104,6 +108,15 @@
104 assert (getcwd (path, sizeof (path)));108 assert (getcwd (path, sizeof (path)));
105 fprintf (out, "wd: %s\n", path);109 fprintf (out, "wd: %s\n", path);
106 break;110 break;
111 case TEST_USER:
112 /* get our id */
113 uid = getuid();
114
115 /* find this users passwd record */
116 pw = getpwuid(uid);
117 assert(pw != NULL);
118 fprintf(out, "user: %s\n", pw->pw_name);
119 break;
107 case TEST_ENVIRONMENT:120 case TEST_ENVIRONMENT:
108 for (char **env = environ; *env; env++)121 for (char **env = environ; *env; env++)
109 fprintf (out, "%s\n", *env);122 fprintf (out, "%s\n", *env);
@@ -897,6 +910,39 @@
897 nih_free (class);910 nih_free (class);
898911
899912
913 /* Check that a job with a specified user runs as that user, requires
914 * root privs to run
915 */
916 TEST_FEATURE ("with user");
917 sprintf (function, "%d", TEST_USER);
918
919 class = job_class_new(NULL, "test");
920
921 struct passwd *pw;
922 int uid;
923 /* get our id */
924 uid = getuid();
925
926 /* find this users passwd record */
927 pw = getpwuid(uid);
928 class->uid = nih_strdup(class, pw->pw_name);
929
930
931 pid = job_process_spawn (class, args, NULL, FALSE);
932 TEST_GT(pid,0);
933
934 waitpid (pid, NULL, 0);
935
936 output = fopen (filename, "r");
937
938 sprintf(buf, "user: %s\n", pw->pw_name);
939 TEST_FILE_EQ (output, buf);
940 TEST_FILE_END (output);
941
942 fclose (output);
943 unlink (filename);
944
945 nih_free (class);
900 /* Check that a job is run with only the environment variables946 /* Check that a job is run with only the environment variables
901 * specifiec in the function call.947 * specifiec in the function call.
902 */948 */
903949
=== modified file 'init/tests/test_parse_job.c'
--- init/tests/test_parse_job.c 2009-07-09 11:01:53 +0000
+++ init/tests/test_parse_job.c 2010-08-10 22:45:55 +0000
@@ -7425,6 +7425,230 @@
7425 nih_free (err);7425 nih_free (err);
7426}7426}
74277427
7428void
7429test_stanza_uid(void)
7430{
7431 JobClass*job;
7432 NihError *err;
7433 size_t pos, lineno;
7434 char buf[1024];
7435
7436 TEST_FUNCTION ("stanza_uid");
7437
7438 /* Check that a uid stanza with an argument results in it
7439 * being stored in the job.
7440 */
7441 TEST_FEATURE ("with single argument");
7442 strcpy (buf, "uid nobody\n");
7443
7444 TEST_ALLOC_FAIL {
7445 pos = 0;
7446 lineno = 1;
7447 job = parse_job (NULL, "test", buf, strlen (buf),
7448 &pos, &lineno);
7449 if (test_alloc_failed) {
7450 TEST_EQ_P (job, NULL);
7451
7452 err = nih_error_get ();
7453 TEST_EQ (err->number, ENOMEM);
7454 nih_free (err);
7455
7456 continue;
7457 }
7458 TEST_EQ (pos, strlen (buf));
7459 TEST_EQ (lineno, 2);
7460
7461 TEST_ALLOC_SIZE (job, sizeof (JobClass));
7462
7463 TEST_ALLOC_PARENT (job->uid, job);
7464 TEST_EQ_STR (job->uid, "nobody");
7465 nih_free (job);
7466 }
7467
7468 /* Check that the last of multiple uid stanzas is used.
7469 */
7470 TEST_FEATURE ("with multiple stanzas");
7471 strcpy (buf, "uid nobody\n");
7472 strcat (buf, "uid gordon\n");
7473
7474 TEST_ALLOC_FAIL {
7475 pos = 0;
7476 lineno = 1;
7477 job = parse_job (NULL, "test", buf, strlen (buf),
7478 &pos, &lineno);
7479
7480 if (test_alloc_failed) {
7481 TEST_EQ_P (job, NULL);
7482
7483 err = nih_error_get ();
7484 TEST_EQ (err->number, ENOMEM);
7485 nih_free (err);
7486
7487 continue;
7488 }
7489
7490 TEST_EQ (pos, strlen (buf));
7491 TEST_EQ (lineno, 3);
7492
7493 TEST_ALLOC_SIZE (job, sizeof (JobClass));
7494
7495 TEST_ALLOC_PARENT (job->uid, job);
7496 TEST_EQ_STR (job->uid, "gordon");
7497
7498 nih_free (job);
7499 }
7500
7501
7502 /* Check that a uid stanza without an argument results in
7503 * a syntax error.
7504 */
7505 TEST_FEATURE ("with missing argument");
7506 strcpy (buf, "uid\n");
7507
7508 pos = 0;
7509 lineno = 1;
7510 job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7511
7512 TEST_EQ_P (job, NULL);
7513
7514 err = nih_error_get ();
7515 TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
7516 TEST_EQ (pos, 3);
7517 TEST_EQ (lineno, 1);
7518 nih_free (err);
7519
7520
7521 /* Check that a uid stanza with an extra second argument
7522 * results in a syntax error.
7523 */
7524 TEST_FEATURE ("with extra argument");
7525 strcpy (buf, "uid bar foo\n");
7526
7527 pos = 0;
7528 lineno = 1;
7529 job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7530
7531 TEST_EQ_P (job, NULL);
7532
7533 err = nih_error_get ();
7534 TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
7535 TEST_EQ (pos, 8);
7536 TEST_EQ (lineno, 1);
7537 nih_free (err);
7538}
7539
7540void
7541test_stanza_gid(void)
7542{
7543 JobClass*job;
7544 NihError *err;
7545 size_t pos, lineno;
7546 char buf[1024];
7547
7548 TEST_FUNCTION ("stanza_gid");
7549
7550 /* Check that a gid stanza with an argument results in it
7551 * being stored in the job.
7552 */
7553 TEST_FEATURE ("with single argument");
7554 strcpy (buf, "gid nobody\n");
7555
7556 TEST_ALLOC_FAIL {
7557 pos = 0;
7558 lineno = 1;
7559 job = parse_job (NULL, "test", buf, strlen (buf),
7560 &pos, &lineno);
7561 if (test_alloc_failed) {
7562 TEST_EQ_P (job, NULL);
7563
7564 err = nih_error_get ();
7565 TEST_EQ (err->number, ENOMEM);
7566 nih_free (err);
7567
7568 continue;
7569 }
7570 TEST_EQ (pos, strlen (buf));
7571 TEST_EQ (lineno, 2);
7572
7573 TEST_ALLOC_SIZE (job, sizeof (JobClass));
7574
7575 TEST_ALLOC_PARENT (job->gid, job);
7576 TEST_EQ_STR (job->gid, "nobody");
7577 nih_free (job);
7578 }
7579
7580 /* Check that the last of multiple gid stanzas is used.
7581 */
7582 TEST_FEATURE ("with multiple stanzas");
7583 strcpy (buf, "gid nobody\n");
7584 strcat (buf, "gid gordon\n");
7585
7586 TEST_ALLOC_FAIL {
7587 pos = 0;
7588 lineno = 1;
7589 job = parse_job (NULL, "test", buf, strlen (buf),
7590 &pos, &lineno);
7591
7592 if (test_alloc_failed) {
7593 TEST_EQ_P (job, NULL);
7594
7595 err = nih_error_get ();
7596 TEST_EQ (err->number, ENOMEM);
7597 nih_free (err);
7598
7599 continue;
7600 }
7601
7602 TEST_EQ (pos, strlen (buf));
7603 TEST_EQ (lineno, 3);
7604
7605 TEST_ALLOC_SIZE (job, sizeof (JobClass));
7606
7607 TEST_ALLOC_PARENT (job->gid, job);
7608 TEST_EQ_STR (job->gid, "gordon");
7609
7610 nih_free (job);
7611 }
7612
7613
7614 /* Check that a gid stanza without an argument results in
7615 * a syntax error.
7616 */
7617 TEST_FEATURE ("with missing argument");
7618 strcpy (buf, "gid\n");
7619
7620 pos = 0;
7621 lineno = 1;
7622 job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7623
7624 TEST_EQ_P (job, NULL);
7625
7626 err = nih_error_get ();
7627 TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
7628 TEST_EQ (pos, 3);
7629 TEST_EQ (lineno, 1);
7630 nih_free (err);
7631
7632
7633 /* Check that a gid stanza with an extra second argument
7634 * results in a syntax error.
7635 */
7636 TEST_FEATURE ("with extra argument");
7637 strcpy (buf, "gid bar foo\n");
7638
7639 pos = 0;
7640 lineno = 1;
7641 job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7642
7643 TEST_EQ_P (job, NULL);
7644
7645 err = nih_error_get ();
7646 TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
7647 TEST_EQ (pos, 8);
7648 TEST_EQ (lineno, 1);
7649 nih_free (err);
7650}
7651
7428int7652int
7429main (int argc,7653main (int argc,
7430 char *argv[])7654 char *argv[])
@@ -7466,6 +7690,7 @@
7466 test_stanza_oom ();7690 test_stanza_oom ();
7467 test_stanza_limit ();7691 test_stanza_limit ();
7468 test_stanza_chroot ();7692 test_stanza_chroot ();
7693 test_stanza_uid();
7469 test_stanza_chdir ();7694 test_stanza_chdir ();
74707695
7471 return 0;7696 return 0;

Subscribers

People subscribed via source and target branches