- sprintf(filename, "%s/%s/token", DATA_PATH, username);
- token_fd = open(filename, O_RDONLY, 0600);
- if (token_fd == -1) {
- perror("Could not open token");
- return NULL;
- }
-
- token = malloc(TOKEN_SIZE * 2 + 1);
- read(token_fd, token, TOKEN_SIZE * 2);
- close(token_fd);
-
- return token;
-}
-
-int auth_check_token(const char *username, const char *given_token) {
- char *token = auth_get_token(username);
- if (token != NULL && given_token != NULL) {
- int ret = (strncmp(token, given_token, TOKEN_SIZE * 2) == 0);
- free(token);
- return ret;
- } else {
- return 0;
- }