Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 192682 | Differences between
and this patch

Collapse All | Expand All

(-)baselayout-2.0.0_rc4/src/builtins.h (+1 lines)
Lines 15-18 Link Here
15
int rc_update (int argc, char **argv);
15
int rc_update (int argc, char **argv);
16
int runscript (int argc, char **argv);
16
int runscript (int argc, char **argv);
17
int start_stop_daemon (int argc, char **argv);
17
int start_stop_daemon (int argc, char **argv);
18
int checkdir (int argc, char **argv);
18
19
(-)baselayout-2.0.0_rc4/src/checkdir.c (+119 lines)
Line 0 Link Here
1
/*
2
   checkdir.c
3
   Checks for the existance of a directory and creates it
4
   if necessary. It can also correct its ownership.
5
6
   Copyright 2007 Gentoo Foundation
7
   */
8
9
#define APPLET "checkdir"
10
11
#include <errno.h>
12
#include <getopt.h>
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <string.h>
16
#include <unistd.h>
17
#include <sys/stat.h>
18
#include <sys/types.h>
19
#include <pwd.h>
20
#include <grp.h>
21
22
#include "builtins.h"
23
#include "einfo.h"
24
25
#include "_usage.h"
26
#define getoptstring "d:u:g:m:" getoptstring_COMMON
27
static struct option longopts[] = {
28
	{ "user",           1, NULL, 'u'},
29
	{ "group",          1, NULL, 'g'},
30
	{ "mode",           1, NULL, 'm'},
31
	longopts_COMMON
32
	{ NULL,             0, NULL, 0}
33
};
34
#include "_usage.c"
35
36
static char *progname;
37
38
static int do_check(char *path, uid_t uid, gid_t gid)
39
{
40
	struct stat dirstat;
41
42
	/* create dir, if it doesn't exist */
43
	if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ))
44
		if (errno != EEXIST)
45
			eerrorx("%s: mkdir: %s", progname, strerror(errno));
46
	else
47
		einfo("Created directory %s", path);
48
49
	if (stat(path, &dirstat))
50
		eerrorx("%s: %s", progname, strerror(errno));
51
52
	if (dirstat.st_uid != uid || dirstat.st_gid != gid) {
53
		einfo("Correcting directory ownership.");
54
		if (chown(path, uid, gid))
55
			eerrorx("%s: chown: %s", progname, strerror(errno));
56
	}
57
}
58
59
int checkdir (int argc, char **argv)
60
{
61
	int opt;
62
	char *user = NULL;
63
	char *group = NULL;
64
	uid_t uid = getuid();
65
	gid_t gid = getgid();
66
67
	progname = argv[0];
68
69
	while ((opt = getopt_long (argc, argv, getoptstring,
70
		longopts, (int *) 0)) != -1) {
71
		switch (opt) {
72
			case 'u':
73
				user = strsep (&optarg, ":");
74
				if (user[0] == '\0')
75
					user = NULL;
76
				group = optarg;
77
				break;
78
79
			case 'g':
80
				group = optarg;
81
				break;
82
	
83
			case_RC_COMMON_GETOPT
84
		}
85
	}
86
87
	if (user != NULL) {
88
		struct passwd *pwd;
89
		char *endptr;
90
91
		uid = strtol(user, &endptr, 10);		
92
		if (endptr[0] != '\0') {
93
			if ( (pwd = getpwnam(user)) == NULL)
94
				eerrorx("%s: Can't set user: %s", argv[0],
95
					user);
96
			uid = pwd->pw_uid;
97
		}
98
	}
99
100
	if (group != NULL) {
101
		struct group *grp;
102
		char *endptr;
103
104
		gid = strtol(group, &endptr, 10);		
105
		if (endptr[0] != '\0') {
106
			if ( (grp = getgrnam(group)) == NULL)
107
				eerrorx("%s: Can't set group: %s", argv[0],
108
					group);
109
			gid = grp->gr_gid;
110
		}
111
	}
112
113
	while (optind < argc) {
114
		do_check(argv[optind], uid, gid);
115
		optind++;
116
	}
117
118
	exit(EXIT_SUCCESS);
119
}
(-)baselayout-2.0.0_rc4/src/Makefile (-1 / +1 lines)
Lines 34-40 Link Here
34
34
35
RCOBJS = env-update.o fstabinfo.o mountinfo.o \
35
RCOBJS = env-update.o fstabinfo.o mountinfo.o \
36
		 rc-depend.o rc-plugin.o rc-status.o rc-update.o runscript.o \
36
		 rc-depend.o rc-plugin.o rc-status.o rc-update.o runscript.o \
37
		 start-stop-daemon.o
37
		 start-stop-daemon.o checkdir.o
38
38
39
LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
39
LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
40
SBIN_TARGETS = rc
40
SBIN_TARGETS = rc
(-)baselayout-2.0.0_rc4/src/rc.c (+2 lines)
Lines 758-763 Link Here
758
		exit (runscript (argc, argv));
758
		exit (runscript (argc, argv));
759
	else if (strcmp (applet, "start-stop-daemon") == 0)
759
	else if (strcmp (applet, "start-stop-daemon") == 0)
760
		exit (start_stop_daemon (argc, argv));
760
		exit (start_stop_daemon (argc, argv));
761
	else if (strcmp (applet, "checkdir") == 0)
762
		exit (checkdir (argc, argv));
761
763
762
	argc--;
764
	argc--;
763
	argv++;
765
	argv++;

Return to bug 192682