File: Permit-user-to-use--u-option-on-self.patch

package info (click to toggle)
cron 3.0pl1-162
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,204 kB
  • sloc: ansic: 47,007; perl: 733; makefile: 429; sh: 425; python: 36
file content (41 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From: Christian Kastner <ckk@kvr.at>
Date: Sat, 26 Dec 2015 19:51:53 +0100
Subject: Permit user to use -u option on self

Instead of entirely prohibiting non-root users to use the -u option, allow them
to use it on themselves, as this should be a null-op.

Fix provided by Steve Greenland <stevegr@debian.org>.

Forwarded: no
Last-Update: 2015-12-26
Index: cron/crontab.c
===================================================================
--- cron.orig/crontab.c
+++ cron/crontab.c
@@ -176,18 +176,19 @@ parse_args(argc, argv)
 				usage("bad debug option");
 			break;
 		case 'u':
-			if (getuid() != ROOT_UID)
-			{
-				fprintf(stderr,
-					"must be privileged to use -u\n");
-				exit(ERROR_EXIT);
-			}
 			if (!(pw = getpwnam(optarg)))
 			{
 				fprintf(stderr, "%s:  user `%s' unknown\n",
 					ProgramName, optarg);
 				exit(ERROR_EXIT);
 			}
+			if ((getuid() != ROOT_UID) &&
+				(getuid() != pw->pw_uid))
+			{
+				fprintf(stderr,
+					"must be privileged to use -u\n");
+				exit(ERROR_EXIT);
+			}
 			free(User);
 			if ((User=strdup(pw->pw_name)) == NULL) {
 			        fprintf(stderr, "Memory allocation error\n");