2 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.
8 #include "k5-platform.h"
18 #include <gssrpc/rpc.h>
19 #include <gssrpc/pmap_clnt.h>
20 #include <arpa/inet.h> /* inet_ntoa */
21 #include <gssapi/gssapi.h>
22 #include <gssapi/gssapi_generic.h>
23 #include <gssrpc/auth_gssapi.h>
24 #include <sys/param.h> /* MAXHOSTNAMELEN */
27 extern int svc_debug_gssapi, misc_debug_gssapi;
29 void rpc_test_badauth(OM_uint32 major, OM_uint32 minor,
30 struct sockaddr_in *addr, caddr_t data);
31 void log_miscerr(struct svc_req *rqst, struct rpc_msg *msg, char
33 void log_badauth_display_status(OM_uint32 major, OM_uint32 minor);
34 void log_badauth_display_status_1(OM_uint32 code, int type, int rec);
35 static void rpc_test_badverf(gss_name_t client, gss_name_t server,
36 struct svc_req *rqst, struct rpc_msg *msg,
40 #define SERVICE_NAME "server"
45 fprintf(stderr, "Usage: server {-t|-u} [svc-debug] [misc-debug]\n");
50 static void handlesig(int dummy)
52 static void handlesig(void)
59 main(int argc, char **argv)
62 auth_gssapi_name names[2];
69 names[0].name = SERVICE_NAME;
70 names[0].type = (gss_OID) gss_nt_service_name;
75 while ((c = getopt(argc, argv, "tu")) != -1) {
96 misc_debug_gssapi = atoi(argv[1]);
98 svc_debug_gssapi = atoi(argv[0]);
106 (void) pmap_unset(RPC_TEST_PROG, RPC_TEST_VERS_1);
108 if (prot == IPPROTO_TCP)
109 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
111 transp = svcudp_create(RPC_ANYSOCK);
112 if (transp == NULL) {
113 fprintf(stderr, "cannot create tcp service.");
116 if (!svc_register(transp, RPC_TEST_PROG, RPC_TEST_VERS_1,
117 rpc_test_prog_1_svc, 0)) {
119 "unable to register (RPC_TEST_PROG, RPC_TEST_VERS_1, %s).",
120 prot == IPPROTO_TCP ? "tcp" : "udp");
123 printf("port: %d\n", (int)transp->xp_port);
125 if (svcauth_gssapi_set_names(names, 0) == FALSE) {
126 fprintf(stderr, "unable to set gssapi names\n");
130 svcauth_gssapi_set_log_badauth_func(rpc_test_badauth, NULL);
131 svcauth_gssapi_set_log_badverf_func(rpc_test_badverf, NULL);
132 svcauth_gssapi_set_log_miscerr_func(log_miscerr, NULL);
135 (void) sigemptyset(&sa.sa_mask);
137 sa.sa_handler = handlesig;
138 (void) sigaction(SIGHUP, &sa, NULL);
139 (void) sigaction(SIGINT, &sa, NULL);
140 (void) sigaction(SIGTERM, &sa, NULL);
142 signal(SIGHUP, handlesig);
143 signal(SIGINT, handlesig);
144 signal(SIGTERM, handlesig);
149 fprintf(stderr, "svc_run returned");
154 char **rpc_test_echo_1_svc(char **arg, struct svc_req *h)
156 static char *res = NULL;
160 asprintf(&res, "Echo: %s", *arg);
164 static void rpc_test_badverf(gss_name_t client, gss_name_t server,
165 struct svc_req *rqst, struct rpc_msg *msg,
168 OM_uint32 minor_stat;
170 gss_buffer_desc client_name, server_name;
172 (void) gss_display_name(&minor_stat, client, &client_name, &type);
173 (void) gss_display_name(&minor_stat, server, &server_name, &type);
175 printf("rpc_test server: bad verifier from %.*s at %s:%d for %.*s\n",
176 (int) client_name.length, (char *) client_name.value,
177 inet_ntoa(rqst->rq_xprt->xp_raddr.sin_addr),
178 ntohs(rqst->rq_xprt->xp_raddr.sin_port),
179 (int) server_name.length, (char *) server_name.value);
181 (void) gss_release_buffer(&minor_stat, &client_name);
182 (void) gss_release_buffer(&minor_stat, &server_name);
186 * Function: log_badauth
188 * Purpose: Callback from GSS-API Sun RPC for authentication
192 * major (r) GSS-API major status
193 * minor (r) GSS-API minor status
194 * addr (r) originating address
195 * data (r) arbitrary data (NULL), not used
199 * Logs the GSS-API error to stdout.
201 void rpc_test_badauth(OM_uint32 major, OM_uint32 minor,
202 struct sockaddr_in *addr, caddr_t data)
206 /* Authentication attempt failed: <IP address>, <GSS-API error */
209 a = inet_ntoa(addr->sin_addr);
211 printf("rpc_test server: Authentication attempt failed: %s", a);
212 log_badauth_display_status(major, minor);
216 void log_miscerr(struct svc_req *rqst, struct rpc_msg *msg,
217 char *error, char *data)
221 a = inet_ntoa(rqst->rq_xprt->xp_raddr.sin_addr);
222 printf("Miscellaneous RPC error: %s, %s\n", a, error);
225 void log_badauth_display_status(OM_uint32 major, OM_uint32 minor)
227 log_badauth_display_status_1(major, GSS_C_GSS_CODE, 0);
228 log_badauth_display_status_1(minor, GSS_C_MECH_CODE, 0);
231 void log_badauth_display_status_1(OM_uint32 code, int type, int rec)
233 OM_uint32 gssstat, minor_stat, msg_ctx;
238 gssstat = gss_display_status(&minor_stat, code,
239 type, GSS_C_NULL_OID,
241 if (gssstat != GSS_S_COMPLETE) {
243 log_badauth_display_status_1(gssstat,GSS_C_GSS_CODE,1);
244 log_badauth_display_status_1(minor_stat,
247 printf("GSS-API authentication error %.*s: "
248 "recursive failure!\n", (int) msg.length,
253 printf(", %.*s", (int) msg.length, (char *)msg.value);
254 (void) gss_release_buffer(&minor_stat, &msg);