client.c | client.c | |||
---|---|---|---|---|
/* $Id: client.c,v 1.7 2004/03/09 17:35:32 rjs3 Exp $ */ | /* $Id: client.c,v 1.8 2010/12/01 14:51:53 mel Exp $ */ | |||
/* | /* | |||
* Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved . | * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved . | |||
* | * | |||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | |||
* are met: | * are met: | |||
* | * | |||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | |||
* | * | |||
skipping to change at line 111 | skipping to change at line 111 | |||
*result = buf; | *result = buf; | |||
return SASL_OK; | return SASL_OK; | |||
} | } | |||
static int simple(void *context __attribute__((unused)), | static int simple(void *context __attribute__((unused)), | |||
int id, | int id, | |||
const char **result, | const char **result, | |||
unsigned *len) | unsigned *len) | |||
{ | { | |||
static char buf[1024]; | static char bufU[1024]; | |||
static char bufA[1024]; | ||||
char *b; | ||||
/* paranoia check */ | /* paranoia check */ | |||
if (! result) | if (! result) | |||
return SASL_BADPARAM; | return SASL_BADPARAM; | |||
switch (id) { | switch (id) { | |||
case SASL_CB_USER: | case SASL_CB_USER: | |||
printf("please enter an authorization id: "); | printf("please enter an authorization id: "); | |||
b = bufU; | ||||
break; | break; | |||
case SASL_CB_AUTHNAME: | case SASL_CB_AUTHNAME: | |||
printf("please enter an authentication id: "); | printf("please enter an authentication id: "); | |||
b = bufA; | ||||
break; | break; | |||
default: | default: | |||
return SASL_BADPARAM; | return SASL_BADPARAM; | |||
} | } | |||
fgets(buf, sizeof buf, stdin); | fgets(b, 1024, stdin); | |||
chop(buf); | chop(b); | |||
*result = buf; | *result = b; | |||
if (len) *len = strlen(buf); | if (len) *len = strlen(b); | |||
return SASL_OK; | return SASL_OK; | |||
} | } | |||
#ifndef HAVE_GETPASSPHRASE | #ifndef HAVE_GETPASSPHRASE | |||
static char * | static char * | |||
getpassphrase(const char *prompt) | getpassphrase(const char *prompt) | |||
{ | { | |||
return getpass(prompt); | return getpass(prompt); | |||
} | } | |||
skipping to change at line 319 | skipping to change at line 323 | |||
printf("successful authentication\n"); | printf("successful authentication\n"); | |||
return 0; | return 0; | |||
done_no: | done_no: | |||
printf("authentication failed\n"); | printf("authentication failed\n"); | |||
return -1; | return -1; | |||
} | } | |||
void usage(void) | void usage(void) | |||
{ | { | |||
fprintf(stderr, "usage: client [-p port] [-s service] [-m mech] host\n" ); | fprintf(stderr, "usage: client [-c|-C] [-p port] [-s service] [-m mech] host\n"); | |||
exit(EX_USAGE); | exit(EX_USAGE); | |||
} | } | |||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | |||
{ | { | |||
int c; | int c; | |||
char *host = "localhost"; | char *host = "localhost"; | |||
char *port = "12345"; | char *port = "12345"; | |||
char localaddr[NI_MAXHOST + NI_MAXSERV], | char localaddr[NI_MAXHOST + NI_MAXSERV], | |||
remoteaddr[NI_MAXHOST + NI_MAXSERV]; | remoteaddr[NI_MAXHOST + NI_MAXSERV]; | |||
char *service = "rcmd"; | char *service = "rcmd"; | |||
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; | char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; | |||
int r; | int r; | |||
sasl_conn_t *conn; | sasl_conn_t *conn; | |||
FILE *in, *out; | FILE *in, *out; | |||
int fd; | int fd; | |||
int salen; | int salen; | |||
int niflags, error; | int niflags, error; | |||
struct sockaddr_storage local_ip, remote_ip; | struct sockaddr_storage local_ip, remote_ip; | |||
int cb_flag = 0; | ||||
sasl_channel_binding_t cb; | ||||
while ((c = getopt(argc, argv, "p:s:m:")) != EOF) { | while ((c = getopt(argc, argv, "Ccp:s:m:")) != EOF) { | |||
switch(c) { | switch(c) { | |||
case 'C': | ||||
cb_flag = 2; /* channel bindings are critical */ | ||||
break; | ||||
case 'c': | ||||
cb_flag = 1; /* channel bindings are optional */ | ||||
break; | ||||
case 'p': | case 'p': | |||
port = optarg; | port = optarg; | |||
break; | break; | |||
case 's': | case 's': | |||
service = optarg; | service = optarg; | |||
break; | break; | |||
case 'm': | case 'm': | |||
mech = optarg; | mech = optarg; | |||
skipping to change at line 417 | skipping to change at line 431 | |||
fprintf(stderr, "getnameinfo: %s\n", gai_strerror(error)); | fprintf(stderr, "getnameinfo: %s\n", gai_strerror(error)); | |||
strcpy(hbuf, "unknown"); | strcpy(hbuf, "unknown"); | |||
strcpy(pbuf, "unknown"); | strcpy(pbuf, "unknown"); | |||
} | } | |||
snprintf(remoteaddr, sizeof(remoteaddr), "%s;%s", hbuf, pbuf); | snprintf(remoteaddr, sizeof(remoteaddr), "%s;%s", hbuf, pbuf); | |||
/* client new connection */ | /* client new connection */ | |||
r = sasl_client_new(service, host, localaddr, remoteaddr, NULL, 0, &con n); | r = sasl_client_new(service, host, localaddr, remoteaddr, NULL, 0, &con n); | |||
if (r != SASL_OK) saslfail(r, "allocating connection state"); | if (r != SASL_OK) saslfail(r, "allocating connection state"); | |||
if (cb_flag) { | ||||
cb.name = "sasl-sample"; | ||||
cb.critical = cb_flag > 1; | ||||
cb.data = "this is a test of channel binding"; | ||||
cb.len = strlen(cb.data); | ||||
sasl_setprop(conn, SASL_CHANNEL_BINDING, &cb); | ||||
} | ||||
/* set external properties here | /* set external properties here | |||
sasl_setprop(conn, SASL_SSF_EXTERNAL, &extprops); */ | sasl_setprop(conn, SASL_SSF_EXTERNAL, &extprops); */ | |||
/* set required security properties here | /* set required security properties here | |||
sasl_setprop(conn, SASL_SEC_PROPS, &secprops); */ | sasl_setprop(conn, SASL_SEC_PROPS, &secprops); */ | |||
in = fdopen(fd, "r"); | in = fdopen(fd, "r"); | |||
out = fdopen(fd, "w"); | out = fdopen(fd, "w"); | |||
r = mysasl_negotiate(in, out, conn); | r = mysasl_negotiate(in, out, conn); | |||
skipping to change at line 440 | skipping to change at line 463 | |||
} | } | |||
printf("closing connection\n"); | printf("closing connection\n"); | |||
fclose(in); | fclose(in); | |||
fclose(out); | fclose(out); | |||
close(fd); | close(fd); | |||
sasl_dispose(&conn); | sasl_dispose(&conn); | |||
sasl_done(); | sasl_done(); | |||
return 0; | return r; | |||
} | } | |||
End of changes. 11 change blocks. | ||||
9 lines changed or deleted | 32 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |