次にさまざまなサポート関数について説明します。
display_status() — 最後に呼び出した GSS-API 関数から戻された状態を表示します。
write_all() — バッファをファイルに書き込みます。
read_all() — ファイルからバッファに読み取ります。
display_ctx_flags() — 現在のコンテキストについての情報を人が読める形式で表示します。たとえば、機密性または相互認証が許可されているかどうかなどです。
print_token() — トークンの値を出力します。
/* * Copyright 1994 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appears in all copies and * that both that copyright notice and this permission notice appear in * supporting documentation, and that the name of OpenVision not be used * in advertising or publicity pertaining to distribution of the software * without specific, written prior permission. OpenVision makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ #if !defined(lint) && !defined(__CODECENTER__) static char *rcsid = "$Header: /afs/athena.mit.edu/astaff/project/krbdev/.cvsroot /src/appl/gss-sample/gss-misc.c,v 1.15 1996/07/22 20:21:20 marc Exp $"; #endif #include <stdio.h> #include <sys/types.h> #include <netinet/in.h> #include <errno.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <string.h> #include <gssapi/gssapi.h> #include "gss-misc.h" #include <stdlib.h> FILE *display_file; extern gss_OID g_mechOid; static void display_status_1(char *m, OM_uint32 code, int type); static int write_all(int fildes, char *buf, unsigned int nbyte) { int ret; char *ptr; for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) { ret = write(fildes, ptr, nbyte); if (ret < 0) { if (errno == EINTR) continue; return(ret); } else if (ret == 0) { return(ptr-buf); } } return(ptr-buf); } static int read_all(int fildes, char *buf, unsigned int nbyte) { int ret; char *ptr; for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) { ret = read(fildes, ptr, nbyte); if (ret < 0) { if (errno == EINTR) continue; return(ret); } else if (ret == 0) { return(ptr-buf); } } return(ptr-buf); } static void display_status_1(m, code, type) char *m; OM_uint32 code; int type; { OM_uint32 maj_stat, min_stat; gss_buffer_desc msg = GSS_C_EMPTY_BUFFER; OM_uint32 msg_ctx; msg_ctx = 0; while (1) { maj_stat = gss_display_status(&min_stat, code, type, g_mechOid, &msg_ctx, &msg); if (maj_stat != GSS_S_COMPLETE) { if (display_file) { fprintf(display_file, "error in gss_display_status" " called from <%s>\n", m); } break; } else if (display_file) fprintf(display_file, "GSS-API error %s: %s\n", m, (char *)msg.value); if (msg.length != 0) (void) gss_release_buffer(&min_stat, &msg); if (!msg_ctx) break; } } /* * 関数: display_status * * 目的: GSS-API メッセージを表示する * * 引数: * * msg メッセージと一緒に表示する文字列 * maj_stat GSS-API メジャー状態コード * min_stat GSS-API マイナー状態コード * * 効果: * * maj_stat と min_stat に関連する GSS-API メッセージが stderr に * 表示される。各メッセージの前には「GSS-API error <msg>:」が * 後には復帰改行が出力される。 */ void display_status(msg, maj_stat, min_stat) char *msg; OM_uint32 maj_stat; OM_uint32 min_stat; { display_status_1(msg, maj_stat, GSS_C_GSS_CODE); display_status_1(msg, min_stat, GSS_C_MECH_CODE); } /* * 関数: display_ctx_flags * * 目的: コンテキスト起動から戻されたフラグを人が読める形式で表示する * * 引数: * * int ret_flags * * 効果: * * コンテキストフラグに対応する文字列が stdout に出力される。各文字列の * 前には、「context flag:」が、後には復帰改行が出力される。 */ void display_ctx_flags(flags) OM_uint32 flags; { if (flags & GSS_C_DELEG_FLAG) fprintf(display_file, "context flag: GSS_C_DELEG_FLAG\n"); if (flags & GSS_C_MUTUAL_FLAG) fprintf(display_file, "context flag: GSS_C_MUTUAL_FLAG\n"); if (flags & GSS_C_REPLAY_FLAG) fprintf(display_file, "context flag: GSS_C_REPLAY_FLAG\n"); if (flags & GSS_C_SEQUENCE_FLAG) fprintf(display_file, "context flag: GSS_C_SEQUENCE_FLAG\n"); if (flags & GSS_C_CONF_FLAG ) fprintf(display_file, "context flag: GSS_C_CONF_FLAG \n"); if (flags & GSS_C_INTEG_FLAG ) fprintf(display_file, "context flag: GSS_C_INTEG_FLAG \n"); } void print_token(tok) gss_buffer_t tok; { int i; unsigned char *p = tok->value; if (!display_file) return; for (i=0; i < tok->length; i++, p++) { fprintf(display_file, "%02x ", *p); if ((i % 16) == 15) { fprintf(display_file, "\n"); } } fprintf(display_file, "\n"); fflush(display_file); } |