summaryrefslogtreecommitdiffstats
path: root/polyp/authkey.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-12-12 22:58:53 +0000
committerLennart Poettering <lennart@poettering.net>2004-12-12 22:58:53 +0000
commite02be6c15beddec976220bce2ee1a68520286c01 (patch)
treeda9cfdfd7a254fa7e8e21b1ef29456b852dbc133 /polyp/authkey.c
parent9a01cf44f09e92e14a720f4f531e943a50f26b72 (diff)
* fix include file names in installed header files
* add browsing API * add new tool pabrowse * add typeid subsystem * bump API version * split off random.c * add an identification cookie git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@320 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/authkey.c')
-rw-r--r--polyp/authkey.c40
1 files changed, 7 insertions, 33 deletions
diff --git a/polyp/authkey.c b/polyp/authkey.c
index 1355c8d9..e16883d3 100644
--- a/polyp/authkey.c
+++ b/polyp/authkey.c
@@ -38,50 +38,24 @@
#include "authkey.h"
#include "util.h"
#include "log.h"
-
-#define RANDOM_DEVICE "/dev/urandom"
+#include "random.h"
/* Generate a new authorization key, store it in file fd and return it in *data */
-static int generate(int fd, void *data, size_t length) {
- int random_fd, ret = -1;
+static int generate(int fd, void *ret_data, size_t length) {
ssize_t r;
- assert(fd >= 0 && data && length);
-
- if ((random_fd = open(RANDOM_DEVICE, O_RDONLY)) >= 0) {
-
- if ((r = pa_loop_read(random_fd, data, length)) < 0 || (size_t) r != length) {
- pa_log(__FILE__": failed to read entropy from '%s'\n", RANDOM_DEVICE);
- goto finish;
- }
-
- } else {
- uint8_t *p;
- size_t l;
- pa_log(__FILE__": WARNING: Failed to open entropy device '"RANDOM_DEVICE"': %s"
- ", falling back to unsecure pseudo RNG.\n", strerror(errno));
+ assert(fd >= 0 && ret_data && length);
- srandom(time(NULL));
-
- for (p = data, l = length; l > 0; p++, l--)
- *p = (uint8_t) random();
- }
+ pa_random(ret_data, length);
lseek(fd, 0, SEEK_SET);
ftruncate(fd, 0);
- if ((r = pa_loop_write(fd, data, length)) < 0 || (size_t) r != length) {
+ if ((r = pa_loop_write(fd, ret_data, length)) < 0 || (size_t) r != length) {
pa_log(__FILE__": failed to write cookie file: %s\n", strerror(errno));
- goto finish;
+ return -1;
}
- ret = 0;
-
-finish:
-
- if (random_fd >= 0)
- close(random_fd);
-
- return ret;
+ return 0;
}
/* Load an euthorization cookie from file fn and store it in data. If