Subversion Repositories RepoView

Rev

Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 15
Line 1... Line 1...
1
/* $Id: util.c 11 2024-08-21 04:31:55Z nishi $ */
1
/* $Id: util.c 15 2024-08-21 15:36:37Z 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 8... Line 8...
8
#include "rv_db.h"
8
#include "rv_db.h"
9
 
9
 
10
#include <stdio.h>
10
#include <stdio.h>
11
#include <stdlib.h>
11
#include <stdlib.h>
12
#include <string.h>
12
#include <string.h>
-
 
13
#include <unistd.h>
-
 
14
#include <sys/wait.h>
13
 
15
 
14
char* rv_strcat(const char* a, const char* b) {
16
char* rv_strcat(const char* a, const char* b) {
15
	char* str = malloc(strlen(a) + strlen(b) + 1);
17
	char* str = malloc(strlen(a) + strlen(b) + 1);
16
	memcpy(str, a, strlen(a));
18
	memcpy(str, a, strlen(a));
17
	memcpy(str + strlen(a), b, strlen(b));
19
	memcpy(str + strlen(a), b, strlen(b));
Line 63... Line 65...
63
			cbuf[0] = (hex_to_num(str[i + 1]) << 4) | hex_to_num(str[i + 2]);
65
			cbuf[0] = (hex_to_num(str[i + 1]) << 4) | hex_to_num(str[i + 2]);
64
			char* tmp = r;
66
			char* tmp = r;
65
			r = rv_strcat(tmp, cbuf);
67
			r = rv_strcat(tmp, cbuf);
66
			free(tmp);
68
			free(tmp);
67
			i += 2;
69
			i += 2;
-
 
70
		} else if(str[i] == '+') {
-
 
71
			char* tmp = r;
-
 
72
			r = rv_strcat(tmp, " ");
-
 
73
			free(tmp);
68
		} else {
74
		} else {
69
			cbuf[0] = str[i];
75
			cbuf[0] = str[i];
70
			char* tmp = r;
76
			char* tmp = r;
71
			r = rv_strcat(tmp, cbuf);
77
			r = rv_strcat(tmp, cbuf);
72
			free(tmp);
78
			free(tmp);
Line 86... Line 92...
86
	}
92
	}
87
	if(rv_has_token(token)) goto regenerate;
93
	if(rv_has_token(token)) goto regenerate;
88
	rv_save_token(username, token);
94
	rv_save_token(username, token);
89
	return token;
95
	return token;
90
}
96
}
-
 
97
 
-
 
98
void rv_add_auth(const char* username, const char* password) {
-
 
99
	pid_t pid = fork();
-
 
100
	if(pid == 0) {
-
 
101
		char* cmd[] = {"htpasswd", "-b", APACHE_PASSWD, (char*)username, (char*)password, NULL};
-
 
102
		execvp("htpasswd", cmd);
-
 
103
		_exit(0);
-
 
104
	} else {
-
 
105
		waitpid(pid, 0, 0);
-
 
106
	}
-
 
107
}