7 #include <netinet/in.h> 23 const char *buf,
int len);
28 #define SOCKET_ERRNO errno 29 #define SOCKET_EINTR EINTR 30 #define SOCKET_READ(a,b,c) read(a,b,c) 31 #define SOCKET_WRITE(a,b,c) write(a,b,c) 69 int krb5_net_read(krb5_context ,
int fd,
register char *buf,
register int len)
74 cc = SOCKET_READ((
SOCKET)fd, buf, len);
76 if (SOCKET_ERRNO == SOCKET_EINTR)
129 int krb5_net_write(krb5_context ,
int fd,
register const char *buf,
int len)
134 cc = SOCKET_WRITE((
SOCKET)fd, buf, wrlen);
136 if (SOCKET_ERRNO == SOCKET_EINTR)
140 errno = SOCKET_ERRNO;
163 : fSocket(s), fServer(0), fAuthContext(0)
187 ::Error(
"TKSocket::Connect",
"while initializing krb5 (%d), %s",
188 rc, error_message(rc));
194 ::Error(
"TKSocket::Connect",
"while getting default credential cache (%d), %s",
195 rc, error_message(rc));
202 ::Error(
"TKSocket::Connect",
"while getting client principal from %s (%d), %s",
213 ::SysError(
"TKSocket::Connect",
"Cannot connect to %s:%d", server, port);
220 rc = krb5_sname_to_principal(
fgContext, server,
"host", KRB5_NT_SRV_HST, &ks->
fServer);
222 ::Error(
"TKSocket::Connect",
"while getting server principal (%d), %s",
223 rc, error_message(rc));
228 krb5_data cksum_data;
229 cksum_data.data =
StrDup(server);
230 cksum_data.length = strlen(server);
233 krb5_ap_rep_enc_part *rep_ret;
238 AP_OPTS_MUTUAL_REQUIRED,
241 fgCCDef, &err_ret, &rep_ret, 0);
243 delete [] cksum_data.data;
246 ::Error(
"TKSocket::Connect",
"while sendauth (%d), %s",
247 rc, error_message(rc));
266 if (rc == 0) errno = ECONNABORTED;
269 SysError(
"BlockRead",
"reading descriptor (%d), %s",
270 rc, error_message(rc));
274 type =
static_cast<EEncoding>(ntohs(desc.fType));
277 enc.length = ntohs(desc.fLength);
278 enc.data =
new char[enc.length+1];
281 enc.data[enc.length] = 0;
283 if (rc == 0) errno = ECONNABORTED;
286 SysError(
"BlockRead",
"reading data (%d), %s",
287 rc, error_message(rc));
305 Error(
"BlockWrite",
"unknown encoding type (%d)", type);
311 buf =
new char[out.length+1];
312 memcpy(buf, out.data, out.length);
331 in.data =
const_cast<char*
>(buf);
337 enc.length = in.length;
346 Error(
"BlockWrite",
"unknown encoding type (%d)", type);
350 desc.
fLength = htons(enc.length);
351 desc.
fType = htons(type);
356 Error(
"BlockWrite",
"writing descriptor (%d), %s",
357 rc, error_message(rc));
363 Error(
"BlockWrite",
"writing data (%d), %s",
364 rc, error_message(rc));
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
static krb5_principal fgClient
virtual Bool_t IsValid() const
static krb5_ccache fgCCDef
int krb5_net_read(krb5_context context, int fd, char *buf, int len)
Int_t BlockRead(char *&buf, EEncoding &type)
Read block on information from server.
krb5_auth_context fAuthContext
static krb5_context fgContext
static TKSocket * Connect(const char *server, Int_t port)
Connect to 'server' on 'port'.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * StrDup(const char *str)
Duplicate the string str.
static constexpr double s
virtual Int_t GetDescriptor() const
Int_t BlockWrite(const char *buf, Int_t len, EEncoding type)
Block-send 'length' bytes to server from 'buf'.
int krb5_net_write(krb5_context context, int fd, const char *buf, int len)
TKSocket(TSocket *s=0)
Constructor.