summaryrefslogtreecommitdiff
path: root/src/basic/fd-util.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-27 16:55:16 +0100
committerTom Gundersen <teg@jklm.no>2015-10-27 16:55:16 +0100
commit0d0696812980d8f41c54739ad73716a233a2fa7c (patch)
tree217d98308a3039e106efde5fd6a7b6a657916950 /src/basic/fd-util.c
parentf47fc3ffc4b69a00083a76308f777b52afb8efbf (diff)
parent7760171904ef007f19e8f46aa240a00e382d5b74 (diff)
Merge pull request #1691 from poettering/util-lib-3
split up util.h and macro.h into even more bits
Diffstat (limited to 'src/basic/fd-util.c')
-rw-r--r--src/basic/fd-util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index e54c104597..d1b1db3a4d 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -19,7 +19,10 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "dirent-util.h"
#include "fd-util.h"
+#include "parse-util.h"
+#include "socket-util.h"
#include "util.h"
int close_nointr(int fd) {
@@ -319,3 +322,30 @@ void cmsg_close_all(struct msghdr *mh) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
}
+
+bool fdname_is_valid(const char *s) {
+ const char *p;
+
+ /* Validates a name for $LISTEN_FDNAMES. We basically allow
+ * everything ASCII that's not a control character. Also, as
+ * special exception the ":" character is not allowed, as we
+ * use that as field separator in $LISTEN_FDNAMES.
+ *
+ * Note that the empty string is explicitly allowed
+ * here. However, we limit the length of the names to 255
+ * characters. */
+
+ if (!s)
+ return false;
+
+ for (p = s; *p; p++) {
+ if (*p < ' ')
+ return false;
+ if (*p >= 127)
+ return false;
+ if (*p == ':')
+ return false;
+ }
+
+ return p - s < 256;
+}