diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-12 18:04:48 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-13 07:55:07 +0100 |
| commit | 8479f8e7797b4b26230d50bde981ff4e3f520603 (patch) | |
| tree | 4340475b7be344b05d50890059840210d80d58e3 /auth.c | |
| parent | dd1ceb550c13d433cd26191ec3176eca0e2d70a1 (diff) | |
Bump libweb
libweb has introduced several breaking changes:
- Add optional expiration date to http_cookie_create
- Replace Makefile with configure script
Diffstat (limited to 'auth.c')
| -rw-r--r-- | auth.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "auth.h" #include "crealpath.h" #include "hex.h" @@ -13,6 +15,7 @@ #include <stdint.h> #include <stdio.h> #include <string.h> +#include <time.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> @@ -171,8 +174,24 @@ static int generate_cookie(const char *const name, const char *const key, unsigned char dkey[KEYLEN]; int ret = -1; char *jwt = NULL; + time_t t = time(NULL); + + if (t == (time_t)-1) + { + fprintf(stderr, "%s: time(3): %s\n", __func__, strerror(errno)); + goto end; + } - if (hex_decode(key, dkey, sizeof dkey)) + t += 365 * 24 * 60 * 60; + + struct tm tm; + + if (!localtime_r(&t, &tm)) + { + fprintf(stderr, "%s: localtime_r(3): %s\n", __func__, strerror(errno)); + goto end; + } + else if (hex_decode(key, dkey, sizeof dkey)) { fprintf(stderr, "%s: hex_decode failed\n", __func__); goto end; @@ -182,7 +201,7 @@ static int generate_cookie(const char *const name, const char *const key, fprintf(stderr, "%s: jwt_encode failed\n", __func__); goto end; } - else if (!(*cookie = http_cookie_create(name, jwt))) + else if (!(*cookie = http_cookie_create(name, jwt, &tm))) { fprintf(stderr, "%s: http_cookie_create failed\n", __func__); goto end; |
