Verify the existence of the keytab for tcp_server, gssapi_server

appl/test/tcp_server and gssapi_server try to open the keytab file only when processing a connection.

This patch verifies the existence of the keytab file on program startup, so that troubleshooting is easier. In addition it adds some comments.

Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
This commit is contained in:
Marco Molteni
2012-05-01 23:01:19 +02:00
committed by Love Hornquist Astrand
parent dd267e8fc3
commit e242c40746
3 changed files with 30 additions and 11 deletions

View File

@@ -115,12 +115,18 @@ server_setup(krb5_context *context, int argc, char **argv)
if(argv[argc] != NULL)
server_usage(1, args, num_args);
if (keytab_str != NULL)
if (keytab_str != NULL) {
ret = krb5_kt_resolve (*context, keytab_str, &keytab);
else
if (ret)
krb5_err (*context, 1, ret, "krb5_kt_resolve");
} else {
ret = krb5_kt_default (*context, &keytab);
if (ret)
krb5_err (*context, 1, ret, "krb5_kt_resolve/default");
krb5_err (*context, 1, ret, "krb5_kt_default");
}
ret = krb5_kt_have_content(*context, keytab);
if (ret)
krb5_err (*context, 1, ret, "krb5_kt_have_content");
return port;
}

View File

@@ -31,6 +31,10 @@
* SUCH DAMAGE.
*/
/*
* A sample server that uses the GSSAPI.
*/
#include "test_locl.h"
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_krb5.h>
@@ -331,13 +335,12 @@ proto (int sock, const char *service)
}
}
static int
doit (int port, const char *service)
static void
loop (int port, const char *service)
{
int sock, sock2;
struct sockaddr_in my_addr;
int one = 1;
int ret;
if (keytab_str)
gsskrb5_register_acceptor_identity(keytab_str);
@@ -366,16 +369,19 @@ doit (int port, const char *service)
if (sock2 < 0)
err (1, "accept");
ret = proto (sock2, service);
proto (sock2, service);
}
return ret;
}
/*
* Iterative server; process one connection at a time.
*/
int
main(int argc, char **argv)
{
krb5_context context = NULL; /* XXX */
int port = server_setup(&context, argc, argv);
return doit (port, service);
loop (port, service);
return 0;
}

View File

@@ -31,6 +31,10 @@
* SUCH DAMAGE.
*/
/*
* A sample server that uses the Kerberos V5 API.
*/
#include "test_locl.h"
RCSID("$Id$");
@@ -160,6 +164,9 @@ doit (int port, const char *service)
return proto (STDIN_FILENO, service);
}
/*
* Process only one connection and then exit.
*/
int
main(int argc, char **argv)
{