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 (+118 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 "u:g:" getoptstring_COMMON
27
static struct option longopts[] = {
28
	{ "user",           1, NULL, 'u'},
29
	{ "group",          1, NULL, 'g'},
30
	longopts_COMMON
31
	{ NULL,             0, NULL, 0}
32
};
33
#include "_usage.c"
34
35
static char *progname;
36
37
static int do_check(char *path, uid_t uid, gid_t gid)
38
{
39
	struct stat dirstat;
40
41
	/* create dir, if it doesn't exist */
42
	if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ))
43
		if (errno != EEXIST)
44
			eerrorx("%s: mkdir: %s", progname, strerror(errno));
45
	else
46
		einfo("Created directory %s", path);
47
48
	if (stat(path, &dirstat))
49
		eerrorx("%s: %s", progname, strerror(errno));
50
51
	if (dirstat.st_uid != uid || dirstat.st_gid != gid) {
52
		einfo("Correcting directory ownership.");
53
		if (chown(path, uid, gid))
54
			eerrorx("%s: chown: %s", progname, strerror(errno));
55
	}
56
}
57
58
int checkdir (int argc, char **argv)
59
{
60
	int opt;
61
	char *user = NULL;
62
	char *group = NULL;
63
	uid_t uid = getuid();
64
	gid_t gid = getgid();
65
66
	progname = argv[0];
67
68
	while ((opt = getopt_long (argc, argv, getoptstring,
69
		longopts, (int *) 0)) != -1) {
70
		switch (opt) {
71
			case 'u':
72
				user = strsep (&optarg, ":");
73
				if (user[0] == '\0')
74
					user = NULL;
75
				group = optarg;
76
				break;
77
78
			case 'g':
79
				group = optarg;
80
				break;
81
	
82
			case_RC_COMMON_GETOPT
83
		}
84
	}
85
86
	if (user != NULL) {
87
		struct passwd *pwd;
88
		char *endptr;
89
90
		uid = strtol(user, &endptr, 10);		
91
		if (endptr[0] != '\0') {
92
			if ( (pwd = getpwnam(user)) == NULL)
93
				eerrorx("%s: Can't set user: %s", argv[0],
94
					user);
95
			uid = pwd->pw_uid;
96
		}
97
	}
98
99
	if (group != NULL) {
100
		struct group *grp;
101
		char *endptr;
102
103
		gid = strtol(group, &endptr, 10);		
104
		if (endptr[0] != '\0') {
105
			if ( (grp = getgrnam(group)) == NULL)
106
				eerrorx("%s: Can't set group: %s", argv[0],
107
					group);
108
			gid = grp->gr_gid;
109
		}
110
	}
111
112
	while (optind < argc) {
113
		do_check(argv[optind], uid, gid);
114
		optind++;
115
	}
116
117
	exit(EXIT_SUCCESS);
118
}
(-)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