* [Cluster-devel] conga/ricci/ricci main.cpp
@ 2008-02-19 15:51 rmccabe
0 siblings, 0 replies; 2+ messages in thread
From: rmccabe @ 2008-02-19 15:51 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2008-02-19 15:51:52
Modified files:
ricci/ricci : main.cpp
Log message:
Clean up error paths when dropping privs
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/ricci/main.cpp.diff?cvsroot=cluster&r1=1.9&r2=1.10
--- conga/ricci/ricci/main.cpp 2008/02/19 03:14:12 1.9
+++ conga/ricci/ricci/main.cpp 2008/02/19 15:51:52 1.10
@@ -49,52 +49,66 @@
int drop_privs(uid_t new_uid) {
int ret;
- cap_t caps = cap_get_proc();
cap_value_t saved_caps[] = { CAP_SYS_BOOT, CAP_SETUID };
+
+ /*
+ ** Keep the capability to reboot the system for when
+ ** fencing support is requested (via -F).
+ */
cap_value_t saved_caps_final[] = { CAP_SYS_BOOT };
+ cap_t caps = cap_init();
- ret = prctl(PR_SET_KEEPCAPS, 1);
- if (ret != 0)
- return -errno;
+ if (caps == NULL)
+ return (-errno);
+
+ if (prctl(PR_SET_KEEPCAPS, 1) != 0)
+ goto out_err;
+
+ if (cap_clear(caps) != 0)
+ goto out_err;
- cap_clear(caps);
ret = cap_set_flag(caps, CAP_PERMITTED,
sizeof(saved_caps) / sizeof(saved_caps[0]), saved_caps, CAP_SET);
if (ret != 0)
- return -errno;
+ goto out_err;
ret = cap_set_flag(caps, CAP_EFFECTIVE,
sizeof(saved_caps) / sizeof(saved_caps[0]), saved_caps, CAP_SET);
if (ret != 0)
- return -errno;
+ goto out_err;
- ret = cap_set_proc(caps);
- if (ret != 0)
- return -errno;
+ if (cap_set_proc(caps) != 0)
+ goto out_err;
- ret = setuid(new_uid);
- if (ret != 0)
- return -errno;
+ /* We don't drop gid=0 so we can read the cluster.conf file. */
+ if (setuid(new_uid) != 0)
+ goto out_err;
+
+ if (cap_clear(caps) != 0)
+ goto out_err;
- cap_clear(caps);
ret = cap_set_flag(caps, CAP_PERMITTED,
sizeof(saved_caps_final) / sizeof(saved_caps_final[0]),
saved_caps_final, CAP_SET);
if (ret != 0)
- return -errno;
+ goto out_err;
ret = cap_set_flag(caps, CAP_EFFECTIVE,
sizeof(saved_caps_final) / sizeof(saved_caps_final[0]),
saved_caps_final, CAP_SET);
if (ret != 0)
- return -errno;
+ goto out_err;
- ret = cap_set_proc(caps);
- if (ret != 0)
- return -errno;
+ if (cap_set_proc(caps) != 0)
+ goto out_err;
+ cap_free(caps);
prctl(PR_SET_KEEPCAPS, 0);
return (0);
+
+out_err:
+ cap_free(caps);
+ return (-errno);
}
int main(int argc, char **argv) {
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Cluster-devel] conga/ricci/ricci main.cpp
@ 2008-02-19 16:01 rmccabe
0 siblings, 0 replies; 2+ messages in thread
From: rmccabe @ 2008-02-19 16:01 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2008-02-19 16:01:39
Modified files:
ricci/ricci : main.cpp
Log message:
Add a help dialog to be printed when the -h flag is given on the command line
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/ricci/main.cpp.diff?cvsroot=cluster&r1=1.10&r2=1.11
--- conga/ricci/ricci/main.cpp 2008/02/19 15:51:52 1.10
+++ conga/ricci/ricci/main.cpp 2008/02/19 16:01:39 1.11
@@ -47,6 +47,19 @@
bool advertise_cluster = false;
bool self_fence = false;
+void print_help(void) {
+ printf("Usage: ricci [options]\n\
+ -c Announce cluster name and OS to unauthenticated clients.\n\
+ -d Enable debugging.\n\
+ -f Run in the foreground.\n\
+ -F Enable support for commands that allow clients to force\n\
+ a reboot (same effect as /sbin/reboot -fn) as an alternative\n\
+ to proper fencing.\n\
+ -h Print this help dialog.\n\
+ -p <port> Listen for connections on the specified port.\n\
+ -u <uid> Drop root and run with the specified uid.\n");
+}
+
int drop_privs(uid_t new_uid) {
int ret;
cap_value_t saved_caps[] = { CAP_SYS_BOOT, CAP_SETUID };
@@ -116,7 +129,7 @@
int32_t ricci_port = RICCI_SERVER_PORT;
int ret;
- while ((ret = getopt(argc, argv, "cdfFu:p:")) != EOF) {
+ while ((ret = getopt(argc, argv, "cdfFhu:p:")) != EOF) {
switch (ret) {
case 'c':
advertise_cluster = true;
@@ -134,6 +147,10 @@
self_fence = true;
break;
+ case 'h':
+ print_help();
+ exit(0);
+
case 'p':
if (optarg != NULL) {
uint32_t port;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-02-19 16:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-19 15:51 [Cluster-devel] conga/ricci/ricci main.cpp rmccabe
-- strict thread matches above, loose matches on Subject: below --
2008-02-19 16:01 rmccabe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).