diff options
author | 2010-04-28 12:54:04 +0000 | |
---|---|---|
committer | 2010-04-28 12:54:04 +0000 | |
commit | 91384d0cb3fe18492205d26357a81ac5abaa9e9c (patch) | |
tree | a507a20a019910c5afd64ee7798a39f8e859c699 /sys/kern/subr_disk.c | |
parent | Cast 'a' to (void *) in the REASON_SET macro. Makes gcc4 happy. (diff) | |
download | wireguard-openbsd-91384d0cb3fe18492205d26357a81ac5abaa9e9c.tar.xz wireguard-openbsd-91384d0cb3fe18492205d26357a81ac5abaa9e9c.zip |
When setting a disklabel automatically generate a new UID if it does not
already have one.
ok krw@
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r-- | sys/kern/subr_disk.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 0d462c86ec5..8c66be4bcb0 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.101 2010/04/25 06:15:17 deraadt Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.102 2010/04/28 12:54:04 jsing Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -608,8 +608,10 @@ notfat: int setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int openmask) { - int i; struct partition *opp, *npp; + struct disk *dk = NULL; + u_int64_t uid; + int i; /* sanity clause */ if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 || @@ -648,6 +650,19 @@ setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int openmask) npp->p_cpg = opp->p_cpg; } } + + /* Generate a UID if the disklabel does not already have one. */ + uid = 0; + if (bcmp(nlp->d_uid, &uid, sizeof(nlp->d_uid)) == 0) { + do { + arc4random_buf(nlp->d_uid, sizeof(nlp->d_uid)); + TAILQ_FOREACH(dk, &disklist, dk_link) + if (dk->dk_label && bcmp(dk->dk_label->d_uid, + nlp->d_uid, sizeof(nlp->d_uid)) == 0) + break; + } while (dk != NULL); + } + nlp->d_checksum = 0; nlp->d_checksum = dkcksum(nlp); *olp = *nlp; |