本文整理汇总了C++中packet_disconnect函数的典型用法代码示例。如果您正苦于以下问题:C++ packet_disconnect函数的具体用法?C++ packet_disconnect怎么用?C++ packet_disconnect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了packet_disconnect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: client_alive_check
static void
client_alive_check(void)
{
static int had_channel = 0;
int id;
id = channel_find_open();
if (id == -1) {
if (!had_channel)
return;
packet_disconnect("No open channels after timeout!");
}
had_channel = 1;
/* timeout, check to see how many we have had */
if (++client_alive_timeouts > options.client_alive_count_max)
packet_disconnect("Timeout, your session not responding.");
/*
* send a bogus channel request with "wantreply",
* we should get back a failure
*/
channel_request_start(id, "[email protected]", 1);
packet_send();
}
示例2: server_input_channel_req
static void
server_input_channel_req(int type, u_int32_t seq, void *ctxt)
{
Channel *c;
int id, reply, success = 0;
char *rtype;
id = packet_get_int();
rtype = packet_get_string(NULL);
reply = packet_get_char();
debug("server_input_channel_req: channel %d request %s reply %d",
id, rtype, reply);
if ((c = channel_lookup(id)) == NULL)
packet_disconnect("server_input_channel_req: "
"unknown channel %d", id);
if (!strcmp(rtype, "[email protected]")) {
packet_check_eom();
chan_rcvd_eow(c);
} else if ((c->type == SSH_CHANNEL_LARVAL ||
c->type == SSH_CHANNEL_OPEN) && strcmp(c->ctype, "session") == 0)
success = session_input_channel_req(c, rtype);
if (reply) {
packet_start(success ?
SSH2_MSG_CHANNEL_SUCCESS : SSH2_MSG_CHANNEL_FAILURE);
packet_put_int(c->remote_id);
packet_send();
}
free(rtype);
}
示例3: input_service_request
/*ARGSUSED*/
static void
input_service_request(int type, u_int32_t seq, void *ctxt)
{
Authctxt *authctxt = ctxt;
u_int len;
int acceptit = 0;
char *service = packet_get_cstring(&len);
packet_check_eom();
if (authctxt == NULL)
fatal("input_service_request: no authctxt");
if (strcmp(service, "ssh-userauth") == 0) {
if (!authctxt->success) {
acceptit = 1;
/* now we can handle user-auth requests */
dispatch_set(SSH2_MSG_USERAUTH_REQUEST, &input_userauth_request);
}
}
/* XXX all other service requests are denied */
if (acceptit) {
packet_start(SSH2_MSG_SERVICE_ACCEPT);
packet_put_cstring(service);
packet_send();
packet_write_wait();
} else {
debug("bad service request %s", service);
packet_disconnect("bad service request %s", service);
}
free(service);
}
示例4: server_request_session
static Channel *
server_request_session(void)
{
Channel *c;
debug("input_session_request");
packet_check_eom();
if (no_more_sessions) {
packet_disconnect("Possible attack: attempt to open a session "
"after additional sessions disabled");
}
/*
* A server session has no fd to read or write until a
* CHANNEL_REQUEST for a shell is made, so we set the type to
* SSH_CHANNEL_LARVAL. Additionally, a callback for handling all
* CHANNEL_REQUEST messages is registered.
*/
c = channel_new("session", SSH_CHANNEL_LARVAL,
-1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
0, "server-session", 1);
if (session_open(the_authctxt, c->self) != 1) {
debug("session open failed, free channel %d", c->self);
channel_free(c);
return NULL;
}
channel_register_cleanup(c->self, session_close_by_channel, 0);
return c;
}
示例5: check_ip_options
/* IPv4 only */
static void
check_ip_options(int socket, char *ipaddr)
{
#ifdef IP_OPTIONS
u_char options[200];
char text[sizeof(options) * 3 + 1];
socklen_t option_size;
int i, ipproto;
struct protoent *ip;
if ((ip = getprotobyname("ip")) != NULL)
ipproto = ip->p_proto;
else
ipproto = IPPROTO_IP;
option_size = sizeof(options);
if (getsockopt(socket, ipproto, IP_OPTIONS, options,
&option_size) >= 0 && option_size != 0) {
text[0] = '\0';
for (i = 0; i < option_size; i++)
snprintf(text + i*3, sizeof(text) - i*3,
" %2.2x", options[i]);
logit("Connection from %.100s with IP options:%.800s",
ipaddr, text);
packet_disconnect("Connection from %.100s with IP options:%.800s",
ipaddr, text);
}
#endif /* IP_OPTIONS */
}
示例6: do_authentication
/*
* Performs authentication of an incoming connection. Session key has already
* been exchanged and encryption is enabled.
*/
Authctxt *
do_authentication(void)
{
Authctxt *authctxt;
u_int ulen;
char *user, *style = NULL;
/* Get the name of the user that we wish to log in as. */
packet_read_expect(SSH_CMSG_USER);
/* Get the user name. */
user = packet_get_string(&ulen);
packet_check_eom();
if ((style = strchr(user, ':')) != NULL)
*style++ = '\0';
authctxt = authctxt_new();
authctxt->user = user;
authctxt->style = style;
/* Verify that the user is a valid user. */
if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
authctxt->valid = 1;
else {
debug("do_authentication: illegal user %s", user);
authctxt->pw = fakepw();
}
setproctitle("%s%s", authctxt->pw ? user : "unknown",
use_privsep ? " [net]" : "");
#ifdef USE_PAM
if (options.use_pam)
PRIVSEP(start_pam(user));
#endif
/*
* If we are not running as root, the user must have the same uid as
* the server. (Unless you are running Windows)
*/
#ifndef HAVE_CYGWIN
if (!use_privsep && getuid() != 0 && authctxt->pw &&
authctxt->pw->pw_uid != getuid())
packet_disconnect("Cannot change user when server not running as root.");
#endif
/*
* Loop until the user has been authenticated or the connection is
* closed, do_authloop() returns only if authentication is successful
*/
do_authloop(authctxt);
/* The user has been authenticated and accepted. */
packet_start(SSH_SMSG_SUCCESS);
packet_send();
packet_write_wait();
return (authctxt);
}
示例7: defined
//.........这里部分代码省略.........
socklen_t sinlen;
char addr_buf[IPLEN];
int sockfd,count;
time_t lasttime,now;
lasttime=time(NULL);
count=0;
while (1) {
sinlen=sizeof(KBS_SOCKADDR_IN);
#ifdef SMTH
if ((now=time(NULL))!=lasttime)
count=0;
else {
if (count>5)
sleep(1);
}
#endif /* SMTH */
sockfd=accept(SOCKFD,(struct sockaddr*)&sin,&sinlen);
count++;
if (sockfd==-1)
continue;
proxy_getpeername(sockfd,(struct sockaddr*)&sin,&sinlen);
#ifdef CHECK_IP_LINK
#ifdef HAVE_IPV6_SMTH
if (check_IP_lists(sin.sin6_addr)==1) {
#else /* ! HAVE_IPV6_SMTH */
if (check_IP_lists(sin.sin_addr.s_addr)==1) {
#endif /* HAVE_IPV6_SMTH */
close(sockfd);
continue;
}
#endif /* CHECK_IP_LINK */
if (!no_fork) {
switch (fork()) {
case -1:
exit(3);
case 0:
break;
default:
close(sockfd);
continue;
}
}
KBS_SET_FROMHOST(sin,addr_buf);
bbslog("0Connect","connect from %d (%d) in port %d",addr_buf,htons(KBS_SIN_MEMBER(sin,port)),mport);
setsid();
if (dup2(sockfd,0)==-1) /* dup tcp link to fd 0 and then in the main_bbs func also to fd 1 */
exit(2);
close(3); /* close listen sock fd in child session */
close(4); /* close pid file fd in child session */
close(sockfd); /* close accept peer fd in child session */
break; /* leave fd 2 still open holding /dev/null */
}
KBS_SET_FROMHOST(sin,getSession()->fromhost);
telnet_init();
return bbs_main(argv);
}
int main(int argc,char **argv) {
char addr[STRLEN];
int ret,inetd,port;
addr[0]=0;inetd=0;port=23;
while ((ret=getopt(argc,argv,"idha:p:"))!=-1) {
switch (ret) {
case 'i':
inetd=1;
break;
case 'd':
no_fork=1;
break;
case 'h':
puts("usage: bbsd [-i] [-d] [-h] [-a <addr>] [-p <port>]");
return 0;
case 'a':
if (optarg[0])
snprintf(addr,STRLEN,"%s",optarg);
break;
case 'p':
if (!isdigit(optarg[0]))
return -1;
port=atoi(optarg);
break;
case '?':
return -1;
}
}
#ifndef HAVE_IPV6_SMTH
inaddr_any.s_addr=htonl(INADDR_ANY);
#endif /* HAVE_IPV6_SMTH */
start_daemon(inetd,port,(!addr[0]?NULL:addr));
main_signals();
return (!inetd?bbs_standalone_main(argv[0]):bbs_inet_main(argv[0]));
}
#else /* SSHBBS */
void ssh_exit(void) {
if (ssh_exiting)
return;
ssh_exiting=1;
abort_bbs(0);
packet_disconnect("sshbbsd exit");
return;
}
示例8: server_alive_check
static void
server_alive_check(void)
{
if (++server_alive_timeouts > options.server_alive_count_max)
packet_disconnect("Timeout, server not responding.");
packet_start(SSH2_MSG_GLOBAL_REQUEST);
packet_put_cstring("[email protected]");
packet_put_char(1); /* boolean: want reply */
packet_send();
}
示例9: respond_to_rsa_challenge
/*
* Computes the proper response to a RSA challenge, and sends the response to
* the server.
*/
static void
respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv)
{
u_char buf[32], response[16];
struct ssh_digest_ctx *md;
int i, len;
/* Decrypt the challenge using the private key. */
/* XXX think about Bleichenbacher, too */
if (rsa_private_decrypt(challenge, challenge, prv) != 0)
packet_disconnect(
"respond_to_rsa_challenge: rsa_private_decrypt failed");
/* Compute the response. */
/* The response is MD5 of decrypted challenge plus session id. */
len = BN_num_bytes(challenge);
if (len <= 0 || (u_int)len > sizeof(buf))
packet_disconnect(
"respond_to_rsa_challenge: bad challenge length %d", len);
memset(buf, 0, sizeof(buf));
BN_bn2bin(challenge, buf + sizeof(buf) - len);
if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
ssh_digest_update(md, buf, 32) < 0 ||
ssh_digest_update(md, session_id, 16) < 0 ||
ssh_digest_final(md, response, sizeof(response)) < 0)
fatal("%s: md5 failed", __func__);
ssh_digest_free(md);
debug("Sending response to host key RSA challenge.");
/* Send the response back to the server. */
packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
for (i = 0; i < 16; i++)
packet_put_char(response[i]);
packet_send();
packet_write_wait();
explicit_bzero(buf, sizeof(buf));
explicit_bzero(response, sizeof(response));
explicit_bzero(&md, sizeof(md));
}
示例10: auth_maxtries_exceeded
void
auth_maxtries_exceeded(Authctxt *authctxt)
{
error("maximum authentication attempts exceeded for "
"%s%.100s from %.200s port %d %s",
authctxt->valid ? "" : "invalid user ",
authctxt->user,
get_remote_ipaddr(),
get_remote_port(),
compat20 ? "ssh2" : "ssh1");
packet_disconnect("Too many authentication failures");
/* NOTREACHED */
}
示例11: auth_maxtries_exceeded
void
auth_maxtries_exceeded(Authctxt *authctxt)
{
struct ssh *ssh = active_state; /* XXX */
error("maximum authentication attempts exceeded for "
"%s%.100s from %.200s port %d ssh2",
authctxt->valid ? "" : "invalid user ",
authctxt->user,
ssh_remote_ipaddr(ssh),
ssh_remote_port(ssh));
packet_disconnect("Too many authentication failures");
/* NOTREACHED */
}
示例12: packet_disconnect
void PTYPars::read_from_packet (CoreConnection* con)
{
u_int len;
int n_bytes;
#if 0 // FIXME
if (s->ttyfd != -1) {
packet_disconnect("Protocol error: you already have a pty.");
return 0;
}
#endif
const char* term2 = con-> packet_get_string(&len);
term = term2;
xfree ((void*) term2);
col = con-> packet_get_int();
row = con-> packet_get_int();
xpixel = con-> packet_get_int();
ypixel = con-> packet_get_int();
#if 0
/* Allocate a pty and open it. */
debug("Allocating pty.");
if (!PRIVSEP(pty_allocate(&s->ptyfd, &s->ttyfd, s->tty,
sizeof(s->tty)))) {
if (s->term)
xfree(s->term);
s->term = NULL;
s->ptyfd = -1;
s->ttyfd = -1;
error("session_pty_req: session %d alloc failed", s->self);
return 0;
}
debug("session_pty_req: session %d alloc %s", s->self, s->tty);
#endif
PTY::tty_parse_modes(con, &n_bytes);
#if 0
/* Set window size from the packet. */
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
#endif
packet_check_eom (con);
}
示例13: dispatch_run
void
dispatch_run(int mode, int *done, void *ctxt)
{
for (;;) {
int type;
u_int32_t seqnr;
if (mode == DISPATCH_BLOCK) {
type = packet_read_seqnr(&seqnr);
} else {
type = packet_read_poll_seqnr(&seqnr);
if (type == SSH_MSG_NONE)
return;
}
if (type > 0 && type < DISPATCH_MAX && dispatch[type] != NULL)
(*dispatch[type])(type, seqnr, ctxt);
else
packet_disconnect("protocol error: rcvd type %d", type);
if (done != NULL && *done)
return;
}
}
示例14: userauth_user_svc_change
void
userauth_user_svc_change(Authctxt *authctxt, char *user, char *service)
{
/*
* NOTE:
*
* SSHv2 services should be abstracted and service changes during
* userauth should be supported as per the userauth draft. In the PAM
* case, support for multiple SSHv2 services means that we have to
* format the PAM service name according to the SSHv2 service *and* the
* SSHv2 userauth being attempted ("passwd", "kbdint" and "other").
*
* We'll cross that bridge when we come to it. For now disallow service
* changes during userauth if using PAM, but allow username changes.
*/
/* authctxt->service must == ssh-connection here */
if (service != NULL && strcmp(service, authctxt->service) != 0) {
packet_disconnect("Change of service not "
"allowed: %s and %s",
authctxt->service, service);
}
if (user != NULL && authctxt->user != NULL &&
strcmp(user, authctxt->user) == 0)
return;
/* All good; update authctxt */
xfree(authctxt->user);
authctxt->user = xstrdup(user);
pwfree(&authctxt->pw);
authctxt->pw = getpwnamallow(user);
authctxt->valid = (authctxt->pw != NULL);
/* Forget method state; abandon postponed userauths */
userauth_reset_methods();
}
示例15: kexgex_server
void
kexgex_server(Kex *kex)
{
BIGNUM *shared_secret = NULL, *dh_client_pub = NULL;
Key *server_host_public, *server_host_private;
DH *dh;
u_char *kbuf, *hash, *signature = NULL, *server_host_key_blob = NULL;
u_int sbloblen, klen, slen, hashlen;
int omin = -1, min = -1, omax = -1, max = -1, onbits = -1, nbits = -1;
int type, kout;
if (kex->load_host_public_key == NULL ||
kex->load_host_private_key == NULL)
fatal("Cannot load hostkey");
server_host_public = kex->load_host_public_key(kex->hostkey_type);
if (server_host_public == NULL)
fatal("Unsupported hostkey type %d", kex->hostkey_type);
server_host_private = kex->load_host_private_key(kex->hostkey_type);
type = packet_read();
switch (type) {
case SSH2_MSG_KEX_DH_GEX_REQUEST:
debug("SSH2_MSG_KEX_DH_GEX_REQUEST received");
omin = min = packet_get_int();
onbits = nbits = packet_get_int();
omax = max = packet_get_int();
min = MAX(DH_GRP_MIN, min);
max = MIN(DH_GRP_MAX, max);
nbits = MAX(DH_GRP_MIN, nbits);
nbits = MIN(DH_GRP_MAX, nbits);
break;
case SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:
debug("SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received");
onbits = nbits = packet_get_int();
/* unused for old GEX */
omin = min = DH_GRP_MIN;
omax = max = DH_GRP_MAX;
break;
default:
fatal("protocol error during kex, no DH_GEX_REQUEST: %d", type);
}
packet_check_eom();
if (omax < omin || onbits < omin || omax < onbits)
fatal("DH_GEX_REQUEST, bad parameters: %d !< %d !< %d",
omin, onbits, omax);
/* Contact privileged parent */
dh = PRIVSEP(choose_dh(min, nbits, max));
if (dh == NULL)
packet_disconnect("Protocol error: no matching DH grp found");
debug("SSH2_MSG_KEX_DH_GEX_GROUP sent");
packet_start(SSH2_MSG_KEX_DH_GEX_GROUP);
packet_put_bignum2(dh->p);
packet_put_bignum2(dh->g);
packet_send();
/* flush */
packet_write_wait();
/* Compute our exchange value in parallel with the client */
dh_gen_key(dh, kex->we_need * 8);
debug("expecting SSH2_MSG_KEX_DH_GEX_INIT");
packet_read_expect(SSH2_MSG_KEX_DH_GEX_INIT);
/* key, cert */
if ((dh_client_pub = BN_new()) == NULL)
fatal("dh_client_pub == NULL");
packet_get_bignum2(dh_client_pub);
packet_check_eom();
#ifdef DEBUG_KEXDH
fprintf(stderr, "dh_client_pub= ");
BN_print_fp(stderr, dh_client_pub);
fprintf(stderr, "\n");
debug("bits %d", BN_num_bits(dh_client_pub));
#endif
#ifdef DEBUG_KEXDH
DHparams_print_fp(stderr, dh);
fprintf(stderr, "pub= ");
BN_print_fp(stderr, dh->pub_key);
fprintf(stderr, "\n");
#endif
if (!dh_pub_is_valid(dh, dh_client_pub))
packet_disconnect("bad client public DH value");
klen = DH_size(dh);
kbuf = xmalloc(klen);
if ((kout = DH_compute_key(kbuf, dh_client_pub, dh)) < 0)
fatal("DH_compute_key: failed");
#ifdef DEBUG_KEXDH
dump_digest("shared secret", kbuf, kout);
#endif
if ((shared_secret = BN_new()) == NULL)
fatal("kexgex_server: BN_new failed");
if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
fatal("kexgex_server: BN_bin2bn failed");
//.........这里部分代码省略.........