[PATCH] iwhd: require safe permissions on the user.js credentials file
Jim Meyering
jim at meyering.net
Thu Nov 10 10:45:42 UTC 2011
This change makes iwhd reject a --userlist-specified file that is
group- or other-readable or -writable.
>From b11e9429596e81c90c8ddb6f98cdedffb73d7978 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Thu, 10 Nov 2011 11:42:51 +0100
Subject: [PATCH] iwhd: require safe permissions on the user.js credentials
file
* rest.c (safe_credential_file_permissions): New function.
(main): Exit if permissions are too lax.
(usage): Mention the 0600 permissions requirement.
* NEWS: Mention this.
---
NEWS | 5 +++++
rest.c | 25 ++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/NEWS b/NEWS
index afe5b7c..c31a3df 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ iwhd NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+* Changes in behavior
+
+ iwhd now rejects a --userlist file that is group- or other-readable
+ or -writable.
+
* Noteworthy changes in release 1.0 (2011-10-31) [stable]
diff --git a/rest.c b/rest.c
index 4630279..ba5d9b0 100644
--- a/rest.c
+++ b/rest.c
@@ -2741,7 +2741,7 @@ A configuration file must be specified.\n\
-m, --master=HOST_PORT master (upstream) server as ip[:port]\n\
-o, --oauth enable OAuth\n\
-p, --port=PORT alternate listen port (default 9090)\n\
- -u, --userlist=FILE list of user names, secrets\n\
+ -u, --userlist=FILE list of user names, secrets (0600 permissions)\n\
-v, --verbose verbose/debug output\n\
\n\
--help display this help and exit\n\
@@ -2799,6 +2799,26 @@ extract_host_port (char const *s, char **hostname, unsigned short *port)
*port = get_port (colon + 1);
}
+static bool
+safe_credential_file_permissions (char const *file_name)
+{
+ struct stat st;
+ if (stat (file_name, &st) != 0) {
+ error(0, errno, _("failed to stat %s"), file_name);
+ return false;
+ }
+
+ // Ensure that it's not readable or writable by group or other. */
+ if (st.st_mode & (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) {
+ error(0, 0,
+ _("%s: credentials are group- or world-readable or writable"),
+ file_name);
+ return false;
+ }
+
+ return true;
+}
+
int
main (int argc, char **argv)
{
@@ -2888,6 +2908,9 @@ args_done:
user_add(usercred);
}
if (user_file) {
+ if (!safe_credential_file_permissions (user_file))
+ exit (EXIT_FAILURE);
+
if (!parse_users(user_file)) {
error (0, 0, _("could not parse %s"),user_file);
return !0;
--
1.7.8.rc0.61.g8a042
More information about the iwhd-devel
mailing list