diff options
author | 2010-11-15 15:07:40 +0000 | |
---|---|---|
committer | 2010-11-15 15:07:40 +0000 | |
commit | cf1d09751bc589a24cf8ce58d61cb85c254fd040 (patch) | |
tree | 41be1d65f2d99394a0677700704df44b91a5f2bf /lib/libutil/opendev.c | |
parent | Do not fatal if an attempt to open a message envelope results in ENOENT. (diff) | |
download | wireguard-openbsd-cf1d09751bc589a24cf8ce58d61cb85c254fd040.tar.xz wireguard-openbsd-cf1d09751bc589a24cf8ce58d61cb85c254fd040.zip |
Factor out DUID identification code so that it can easily be reused.
ok krw@
Diffstat (limited to 'lib/libutil/opendev.c')
-rw-r--r-- | lib/libutil/opendev.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/lib/libutil/opendev.c b/lib/libutil/opendev.c index 53c3c537bfe..5856cbd2bb7 100644 --- a/lib/libutil/opendev.c +++ b/lib/libutil/opendev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: opendev.c,v 1.10 2010/06/28 19:12:29 chl Exp $ */ +/* $OpenBSD: opendev.c,v 1.11 2010/11/15 15:07:40 jsing Exp $ */ /* * Copyright (c) 2000, Todd C. Miller. All rights reserved. @@ -41,28 +41,6 @@ #include "util.h" -/* Returns 1 if a valid disklabel UID. */ -static int -valid_diskuid(const char *duid, int dflags) -{ - char c; - int i; - - /* Basic format check. */ - if (!((strlen(duid) == 16 && (dflags & OPENDEV_PART)) || - (strlen(duid) == 18 && duid[16] == '.'))) - return 0; - - /* Check UID. */ - for (i = 0; i < 16; i++) { - c = duid[i]; - if ((c < '0' || c > '9') && (c < 'a' || c > 'f')) - return 0; - } - - return 1; -} - /* * This routine is a generic rewrite of the original code found in * disklabel(8). @@ -88,7 +66,7 @@ opendev(char *path, int oflags, int dflags, char **realpath) if ((slash = strchr(path, '/'))) fd = open(path, oflags); - else if (valid_diskuid(path, dflags)) { + else if (isduid(path, dflags)) { if ((fd = open("/dev/diskmap", oflags)) != -1) { bzero(&dm, sizeof(struct dk_diskmap)); strlcpy(namebuf, path, sizeof(namebuf)); |