Skip to content

Commit 765b9ef

Browse files
rootjengelh
authored andcommitted
tests: add gssauth helper program
1 parent 9328407 commit 765b9ef

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mapi_la_LDFLAGS += -Wl,--allow-shlib-undefined
241241
endif
242242
EXTRA_mapi_la_DEPENDENCIES = default.sym
243243

244-
noinst_PROGRAMS = dldcheck tests/bdump tests/bodyconv tests/compress tests/dnsbl_check tests/exrpctest tests/gxl-383 tests/jsontest tests/lzxpress tests/oxcmail_ie tests/ucvttest tests/udb tests/utf8filter tests/utiltest tests/vcard tools/tzdump
244+
noinst_PROGRAMS = dldcheck tests/bdump tests/bodyconv tests/compress tests/dnsbl_check tests/exrpctest tests/gssauth tests/gxl-383 tests/jsontest tests/lzxpress tests/oxcmail_ie tests/ucvttest tests/udb tests/utf8filter tests/utiltest tests/vcard tools/tzdump
245245
if HAVE_ESEDB
246246
noinst_PROGRAMS += tests/epv_unpack
247247
endif
@@ -262,6 +262,8 @@ tests_epv_unpack_SOURCES = tests/epv_unpack.cpp tools/edb_pack.cpp tools/edb_pac
262262
tests_epv_unpack_LDADD = ${libesedb_LIBS} ${libHX_LIBS} libgromox_common.la libgromox_mapi.la
263263
tests_exrpctest_SOURCES = tests/exrpctest.cpp
264264
tests_exrpctest_LDADD = libgromox_common.la libgromox_exrpc.la libgromox_mapi.la
265+
tests_gssauth_SOURCES = tests/gssauth.cpp
266+
tests_gssauth_LDADD = ${libHX_LIBS} ${gss_LIBS} libgromox_common.la
265267
tests_gxl_383_SOURCES = tests/gxl-383.cpp
266268
tests_gxl_383_LDADD = libgromox_common.la libgromox_exrpc.la libgromox_mapi.la
267269
tests_jsontest_SOURCES = tests/jsontest.cpp

tests/gssauth.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
// SPDX-FileCopyrightText: 2025 grommunio GmbH
3+
// This file is part of Gromox.
4+
/*
5+
* Minimal GSS auth helper loosely working similar to
6+
* `/usr/libexec/squid/negotiate_kerberos_auth -s GSS_C_NO_NAME`.
7+
* Use for testing with http.cfg:gss_program only.
8+
*/
9+
#include <string>
10+
#include <unistd.h>
11+
#include <gssapi/gssapi.h>
12+
#include <libHX/string.h>
13+
#include <gromox/fileio.h>
14+
15+
using namespace gromox;
16+
17+
int main(int argc, char **argv)
18+
{
19+
gss_cred_id_t srv_creds{};
20+
gss_ctx_id_t ctx{};
21+
OM_uint32 status{};
22+
hxmc_t *line = nullptr;
23+
setvbuf(stdout, NULL, _IOLBF, 0);
24+
25+
while (HX_getl(&line, stdin)) {
26+
HX_chomp(line);
27+
bool yr = line[0] == 'Y' && line[1] == 'R' && line[2] == ' ';
28+
bool kk = line[0] == 'K' && line[1] == 'K' && line[2] == ' ';
29+
if (yr) {
30+
auto ret = gss_acquire_cred(&status, nullptr,
31+
GSS_C_INDEFINITE, GSS_C_NO_OID_SET,
32+
GSS_C_ACCEPT, &srv_creds, nullptr, nullptr);
33+
if (ret != GSS_S_COMPLETE) {
34+
fprintf(stderr, "BH gss_acquire_cred failed\n");
35+
continue;
36+
}
37+
}
38+
if (yr || kk) {
39+
auto vss = base64_decode(&line[3]);
40+
gss_buffer_desc input_buf{}, user_buf{}, output_token{};
41+
gss_name_t username{};
42+
input_buf.value = vss.data();
43+
input_buf.length = vss.size();
44+
auto ret = gss_accept_sec_context(&status, &ctx, srv_creds,
45+
&input_buf, GSS_C_NO_CHANNEL_BINDINGS, &username,
46+
nullptr, &output_token, nullptr, nullptr,
47+
nullptr);
48+
if (ret == GSS_S_CONTINUE_NEEDED) {
49+
std::string_view sv(static_cast<char *>(output_token.value), output_token.length);
50+
printf("TT %s\n", base64_encode(sv).c_str());
51+
continue;
52+
} else if (ret != 0) {
53+
fprintf(stderr, "BH gss_accept_sec_context failed\n");
54+
return 1;
55+
}
56+
ret = gss_display_name(&status, username, &user_buf, nullptr);
57+
if (ret != 0) {
58+
fprintf(stderr, "BH no username determined\n");
59+
continue;
60+
}
61+
std::string sv(static_cast<char *>(user_buf.value), user_buf.length);
62+
printf("AF = %s\n", sv.c_str());
63+
continue;
64+
}
65+
printf("BH what?\n");
66+
}
67+
return 0;
68+
}

0 commit comments

Comments
 (0)