#include #include #include #include #include #include #include #include #include #include "gss_common.h" /* ** Extern Routine Prototypes */ extern sys$parse (); /* ** Static Routine Prototypes */ static void _put_message ( char *, OM_uint32, int, char *, va_list); /* ** ** parse_prog_name - Parse a program name from a file specification ** ** Functional Description: ** ** This routine parses a program name from a file specification. If the ** parse is unsuccessful, then the input file spec. is returned. ** ** Usage: ** ** parse_prog_name file_spec, prog_name ** ** Formal parameters: ** ** file_spec - (IN) address of the file specification string ** prog_name - (OUT) address of the pointer to which the newly ** allocated program name will returned. ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** None ** ** Side Effects: ** ** None ** */ void parse_prog_name ( char *file_spec, char **prog_name ) { #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __save #pragma __required_pointer_size 32 char *temp_spec; #pragma __required_pointer_size __restore #endif char esa[NAM$C_MAXRSS], rsa[NAM$C_MAXRSS]; struct FAB fab; struct NAM nam; int status; /* ** Initialize FAB & NAM structures */ fab = cc$rms_fab; nam = cc$rms_nam; #if __INITIAL_POINTER_SIZE == 64 temp_spec = _malloc32 (strlen (file_spec) + 1); strcpy (temp_spec, file_spec); fab.fab$l_fna = temp_spec; fab.fab$b_fns = strlen (temp_spec); #else fab.fab$l_fna = file_spec; fab.fab$b_fns = strlen (file_spec); #endif fab.fab$l_nam = &nam; nam.nam$l_esa = esa; nam.nam$b_ess = sizeof (esa); nam.nam$l_rsa = rsa; nam.nam$b_rss = sizeof (rsa); nam.nam$v_synchk = 1; /* ** Parse the file spec., If the parse fails then we simply ** return the entered file spec., otherwise we extract and ** return the file name. */ status = sys$parse (&fab); if (! (status & 1)) { *prog_name = malloc (strlen (file_spec) + 1); strcpy (*prog_name, file_spec); } else { *prog_name = malloc (nam.nam$b_name + 1); strncpy (*prog_name, nam.nam$l_name, nam.nam$b_name); *(*prog_name + nam.nam$b_name) = '\0'; } /* ** Free the temporary specification */ #if __INITIAL_POINTER_SIZE == 64 free (temp_spec); #endif } /* ** ** net_write - write a data buffer over a given socket ** ** Functional Description: ** ** This routine write a data buffer over a given socket. If the ** code is compiled on Alpha, then the data to be written is ** copied to a 32 bit address to accommodate the socket write. ** ** Usage: ** ** net_write sock, data_buf, data_len ** ** Formal parameters: ** ** sock - (IN) the socket number to be written to. ** data_buf - (IN) address of the data buffer from which the ** data is to be written. ** data_len - (IN) number of bytes to be written from data buffer. ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** n - The number of characters written from the buffer ** ** Side Effects: ** ** None ** */ int net_write ( int sock, char *data_buf, unsigned int data_len ) { #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __save #pragma __required_pointer_size 32 #endif char *temp_buf; char *temp_ptr; #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __restore #endif int sent_len = 0; #if __INITIAL_POINTER_SIZE == 64 temp_buf = _malloc32 (data_len); memcpy (temp_buf, data_buf, data_len); #else temp_buf = data_buf; #endif for (temp_ptr = temp_buf; data_len; temp_ptr += sent_len, data_len -= sent_len) { sent_len = send (sock, temp_ptr, data_len, 0); if (sent_len < 0) { if (errno == EINTR) continue; #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return (sent_len); } else if (sent_len == 0) { #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } } /* ** Free the temporary buffer */ #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } /* ** ** net_read - read a data buffer over a given socket ** ** Functional Description: ** ** This routine reads a data buffer over a given socket. If the ** code is compiled on Alpha, then the data is read into a 32 bit ** address to accommodate the socket read. ** ** Usage: ** ** net_read sock, data_buf, data_len ** ** Formal parameters: ** ** sock - (IN) the socket number to be read from. ** data_buf - (OUT) address of the data buffer into which the ** data is to be read. ** data_len - (IN) number of bytes to be read into data buffer. ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** n - The number of characters read into the buffer ** ** Side Effects: ** ** None ** */ int net_read ( int sock, char *data_buf, unsigned int data_len ) { #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __save #pragma __required_pointer_size 32 #endif char *temp_ptr; char *temp_buf; #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __restore #endif int sent_len = 0; #if __INITIAL_POINTER_SIZE == 64 temp_buf = _malloc32 (data_len); #else temp_buf = data_buf; #endif for (temp_ptr = temp_buf; data_len; temp_ptr += sent_len, data_len -= sent_len) { sent_len = recv(sock, temp_ptr, data_len, 0); if (sent_len < 0) { if (errno == EINTR) continue; #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return (sent_len); } else if (sent_len == 0) { #if __INITIAL_POINTER_SIZE == 64 memcpy (data_buf, temp_buf, (int) (temp_ptr - temp_buf)); free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } } #if __INITIAL_POINTER_SIZE == 64 memcpy (data_buf, temp_buf, (int) (temp_ptr - temp_buf)); free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } /* ** ** put_message - Print the formated message text to standard output ** ** Functional Description: ** ** This routine prints the major & minor status message along with ** any additional message text. ** ** Usage: ** ** put_message prog_name, major_status, minor_status, msg_fmt, ... ** ** Formal parameters: ** ** prog_name - (IN) address of the program name string ** major_status - (IN) value of the major status ** minor_status - (IN) value of the minor status ** msg_fmt - (IN) address of additional message format text ** ... - (IN) optional message arguments ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** None ** ** Side Effects: ** ** None ** */ void put_message ( char *prog_name, OM_uint32 major_status, OM_uint32 minor_status, char *msg_fmt, ... ) { volatile va_list msg_args; /* ** Display the major status message */ _put_message (prog_name, major_status, GSS_C_GSS_CODE, msg_fmt, msg_args); /* ** Display the minor status message if provided */ if (minor_status) _put_message (prog_name, minor_status, GSS_C_MECH_CODE, msg_fmt, msg_args); } /* ** ** _put_message - Print the formated message text to standard output ** ** Functional Description: ** ** This routine prints the appropriate formatted message for the ** given status. ** ** Usage: ** ** _put_message prog_name, msg_status, msg_type, msg_fmt, ... ** ** Formal parameters: ** ** prog_name - (IN) address of the program name string ** msg_status - (IN) value of the message status ** msg_type - (IN) value of the message type ** msg_fmt - (IN) address of additional message format text ** ... - (IN) optional message arguments ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** None ** ** Side Effects: ** ** None ** */ static void _put_message ( char *prog_name, OM_uint32 msg_status, int msg_type, char *msg_fmt, va_list msg_args ) { gss_buffer_desc msg_desc; OM_uint32 msg_ctx = 0; char msg_buf[1024]; OM_uint32 status, minor_status; /* ** Loop thru the message context until we're done with this message */ do { if (prog_name) sprintf (msg_buf, "%s: ", prog_name); else strcpy (msg_buf, ""); memset (&msg_desc, 0, sizeof (msg_desc)); if (msg_status) status = gss_display_status (&minor_status, msg_status, msg_type, GSS_C_NULL_OID, &msg_ctx, &msg_desc); if (msg_fmt) vsprintf (msg_buf + strlen (msg_buf), msg_fmt, msg_args); if (msg_desc.value) sprintf (msg_buf + strlen (msg_buf), (msg_fmt ? " %s" : "%s"), (char *) msg_desc.value); status = gss_release_buffer (&minor_status, &msg_desc); fprintf (stderr, "%s\n", msg_buf); } while (msg_ctx); }