Subversion Repositories RepoView

Rev

Rev 15 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15 Rev 29
Line 1... Line 1...
1
/* $Id: util.c 15 2024-08-21 15:36:37Z nishi $ */
1
/* $Id: util.c 29 2024-08-21 19:23:54Z nishi $ */
2
 
2
 
3
#include "rv_util.h"
3
#include "rv_util.h"
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 84... Line 84...
84
char* rv_new_token(const char* username) {
84
char* rv_new_token(const char* username) {
85
	const char tokenstr[] = "0123456789abcdefghijklmnopqrstuvwxyz";
85
	const char tokenstr[] = "0123456789abcdefghijklmnopqrstuvwxyz";
86
	char* token = malloc(17);
86
	char* token = malloc(17);
87
	token[16] = 0;
87
	token[16] = 0;
88
	int i;
88
	int i;
-
 
89
	unsigned char uc;
-
 
90
	FILE* f = fopen("/dev/urandom", "rb");
89
regenerate:
91
regenerate:
90
	for(i = 0; i < 16; i++) {
92
	for(i = 0; i < 16; i++) {
-
 
93
		fread(&uc, 1, 1, f);
91
		token[i] = tokenstr[rand() % strlen(tokenstr)];
94
		token[i] = tokenstr[uc % strlen(tokenstr)];
92
	}
95
	}
-
 
96
	fclose(f);
93
	if(rv_has_token(token)) goto regenerate;
97
	if(rv_has_token(token)) goto regenerate;
94
	rv_save_token(username, token);
98
	rv_save_token(username, token);
95
	return token;
99
	return token;
96
}
100
}
97
 
101