/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Shared routines for client and server for
* secure read(), write(), getc(), and putc().
* Only one security context, thus only work on one fd at a time!
*/
#include "ftp_var.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
extern struct sockaddr_in hisaddr;
extern struct sockaddr_in myaddr;
extern int dlevel;
extern int auth_type;
extern gss_ctx_id_t gcontext;
static int
{
if (len == 0)
return (0);
do {
if (cc < 0) {
continue;
return (cc);
} else if (cc == 0) {
return (len2);
} else {
}
} while (len > 0);
return (len2);
}
static int
{
do {
if (cc < 0) {
continue;
return (cc); /* errno is already set */
} else if (cc == 0) {
return (len2);
} else {
}
} while (len > 0);
return (len2);
}
static void
{
}
/*
* Given maxbuf as a buffer size, determine how much can we
* really transfer given the overhead of different algorithms
*
* Sets smaxbuf and smaxqueue
*/
static int
{
if (auth_type == AUTHTYPE_GSSAPI) {
if (maj_stat != GSS_S_COMPLETE) {
"GSSAPI fudge determination");
/* Return error how? */
return (ERR);
}
}
return (0);
}
static uchar_t
{
int ret;
if (ret)
return (ret);
}
nout = 0;
}
return (c);
}
/*
* returns:
* 0 on success
* -1 on error (errno set)
* -2 on security error
*/
int
{
int ret;
return (0);
if (nout)
return (ret);
}
/*
* returns:
* >= 0 on success
* -1 on error
* -2 on security error
*/
int
{
}
/*
* returns:
* nbyte on success
* -1 on error (errno set)
* -2 on security error
*/
{
uint_t i;
int c;
return (c);
return (i);
}
/*
* returns:
* 0 on success
* -1 on error, errno set
* -2 on security error
*/
{
int length;
/* Other auth types go here ... */
if (auth_type == AUTHTYPE_GSSAPI) {
int conf_state;
&in_buf, &conf_state,
&out_buf);
if (maj_stat != GSS_S_COMPLETE) {
/*
* generally need to deal
* ie. should loop, but for now just fail
*/
"GSSAPI seal failed" : "GSSAPI sign failed");
return (ERR);
}
if (outbuf)
else {
bufsize = 0;
secure_error("%s (in malloc of PROT buffer)",
return (ERR);
}
}
}
return (-1);
return (-1);
return (0);
}
static int
{
/* number of chars in ucbuf, pointer into ucbuf */
int kerror;
if (nin == 0) {
if ((kerror =
!= sizeof (length)) {
secure_error("Couldn't read PROT buffer length: %d/%s",
"premature EOF");
return (ERR);
}
secure_error("Length (%d) of PROT buffer > PBSZ=%u",
return (ERR);
}
!= length) {
secure_error("Couldn't read %u byte PROT buffer: %s",
return (ERR);
}
/* Other auth types go here ... */
if (auth_type == AUTHTYPE_GSSAPI) {
int conf_state;
if (maj_stat != GSS_S_COMPLETE) {
"failed unsealing ENC message":
"failed unsealing MIC message");
return (ERR);
}
}
/* Other auth types go here ... */
}
}
/*
* returns:
* 0 on success
* -1 on EOF
* -2 on security error
*/
int
{
}
/*
* returns:
* > 0 on success (n == # of bytes read)
* 0 on EOF
* -1 on error, errno set, only for PROT_C
* -2 on security error (ERR = -2)
*/
{
int c, i;
if (goteof)
return (goteof = 0);
switch (c = secure_getbyte(fd)) {
case ERR:
return (c);
case EOF:
goteof = i ? 1 : 0;
return (i);
default:
buf[i++] = c;
}
return (i);
}