mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 00:22:25 +00:00
parent
3a685b10b6
commit
4a8e681a5f
13
util/token.c
13
util/token.c
@ -1,20 +1,31 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include "util/token.h"
|
#include "util/token.h"
|
||||||
#include "wlr/util/log.h"
|
#include "wlr/util/log.h"
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
bool generate_token(char out[static TOKEN_STRLEN]) {
|
bool generate_token(char out[static TOKEN_STRLEN]) {
|
||||||
static FILE *urandom = NULL;
|
static FILE *urandom = NULL;
|
||||||
uint64_t data[2];
|
uint64_t data[2];
|
||||||
|
|
||||||
if (!urandom) {
|
if (!urandom) {
|
||||||
if (!(urandom = fopen("/dev/urandom", "r"))) {
|
int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||||
|
if (fd < 0) {
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to open random device");
|
wlr_log_errno(WLR_ERROR, "Failed to open random device");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!(urandom = fdopen(fd, "r"))) {
|
||||||
|
wlr_log_errno(WLR_ERROR, "fdopen failed");
|
||||||
|
close(fd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fread(data, sizeof(data), 1, urandom) != 1) {
|
if (fread(data, sizeof(data), 1, urandom) != 1) {
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to read from random device");
|
wlr_log_errno(WLR_ERROR, "Failed to read from random device");
|
||||||
|
Loading…
Reference in New Issue
Block a user