Use 128-bit hexadecimal string tokens generated with /dev/urandom instead of UUIDs for xdg-foreign handles, removing the libuuid dependency. Update readme and CI. Closes #2830. build: remove xdg-foreign feature With no external dependencies required, there's no reason not to always build it. Remove WLR_HAS_XDG_FOREIGN as well.master
parent
5a178c4a23
commit
b29ac8fbac
@ -0,0 +1,9 @@
|
||||
#ifndef UTIL_TOKEN_H
|
||||
#define UTIL_TOKEN_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TOKEN_STRLEN 33
|
||||
bool generate_token(char out[static TOKEN_STRLEN]);
|
||||
|
||||
#endif
|
@ -1,8 +0,0 @@
|
||||
#ifndef UTIL_UUID_H
|
||||
#define UTIL_UUID_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool generate_uuid(char out[static 37]);
|
||||
|
||||
#endif
|
@ -0,0 +1,29 @@
|
||||
#include "util/token.h"
|
||||
#include "wlr/util/log.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
bool generate_token(char out[static TOKEN_STRLEN]) {
|
||||
static FILE *urandom = NULL;
|
||||
uint64_t data[2];
|
||||
|
||||
if (!urandom) {
|
||||
if (!(urandom = fopen("/dev/urandom", "r"))) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to open random device");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (fread(data, sizeof(data), 1, urandom) != 1) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to read from random device");
|
||||
return false;
|
||||
}
|
||||
if (snprintf(out, TOKEN_STRLEN, "%016" PRIx64 "%016" PRIx64, data[0], data[1]) != TOKEN_STRLEN - 1) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to format hex string token");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
#include <uuid.h>
|
||||
#include "util/uuid.h"
|
||||
|
||||
#if HAS_LIBUUID
|
||||
bool generate_uuid(char out[static 37]) {
|
||||
uuid_t uuid;
|
||||
uuid_generate_random(uuid);
|
||||
uuid_unparse(uuid, out);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool generate_uuid(char out[static 37]) {
|
||||
uuid_t uuid;
|
||||
uint32_t status;
|
||||
uuid_create(&uuid, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
return false;
|
||||
}
|
||||
char *str;
|
||||
uuid_to_string(&uuid, &str, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(strlen(str) + 1 == 37);
|
||||
memcpy(out, str, 37);
|
||||
free(str);
|
||||
return true;
|
||||
}
|
||||
#endif
|
Loading…
Reference in new issue