예제 #1
0
/** fill result from parsed message, on error fills servfail */
void
libworker_enter_result(struct ub_result* res, ldns_buffer* buf,
	struct regional* temp, enum sec_status msg_security)
{
	struct query_info rq;
	struct reply_info* rep;
	res->rcode = LDNS_RCODE_SERVFAIL;
	rep = parse_reply(buf, temp, &rq);
	if(!rep) {
		log_err("cannot parse buf");
		return; /* error parsing buf, or out of memory */
	}
	if(!fill_res(res, reply_find_answer_rrset(&rq, rep), 
		reply_find_final_cname_target(&rq, rep), &rq))
		return; /* out of memory */
	/* rcode, havedata, nxdomain, secure, bogus */
	res->rcode = (int)FLAGS_GET_RCODE(rep->flags);
	if(res->data && res->data[0])
		res->havedata = 1;
	if(res->rcode == LDNS_RCODE_NXDOMAIN)
		res->nxdomain = 1;
	if(msg_security == sec_status_secure)
		res->secure = 1;
	if(msg_security == sec_status_bogus)
		res->bogus = 1;
}
예제 #2
0
static int handle_new_data(struct sr_dev_inst *sdi)
{
	int len;
	struct dev_context *devc;
	struct sr_serial_dev_inst *serial;

	devc = sdi->priv;
	serial = sdi->conn;

	len = serial_read_blocking(serial, devc->buf + devc->buflen, 1, 0);
	if (len < 1)
		return SR_ERR;

	devc->buflen += len;
	devc->buf[devc->buflen] = '\0';

	/* Wait until we received an "OK\r" (among other bytes). */
	if (!g_str_has_suffix(devc->buf, "OK\r"))
		return SR_OK;

	parse_reply(sdi);

	devc->buf[0] = '\0';
	devc->buflen = 0;

	devc->reply_pending = FALSE;

	return SR_OK;
}
예제 #3
0
파일: adns.c 프로젝트: Estella/wraith
//static int dns_on_read(void *client_data, int idx, char *buf, int len)
static void dns_on_read(int idx, char *buf, int atr)
{
        dcc[idx].timeval = now;

//	if (resend_on_read) {
//		resend_on_read = 0;
//		dns_resend_queries();
//		return;
//	}

        atr = read(dcc[idx].sock, buf, 512);

        if (atr == -1) {
          if (errno == EAGAIN)
            atr = read(dcc[idx].sock, buf, 512);
          if (atr == -1) {
            dns_on_eof(idx);
            return;
          }
        }
        sdprintf("SETTING TIMEOUT to 0");
        dns_handler.timeout_val = 0;
	if (parse_reply(buf, atr))
          dns_on_eof(idx);
	return;
}
예제 #4
0
파일: redis.hpp 프로젝트: csj561/c_plusplus
  bool parse_reply(const redisReply * reply,listStr & _list)
  {
  	switch(reply->type) 
	{
    case REDIS_REPLY_INTEGER:
		do{
			char buf[32];
			snprintf(buf,sizeof(buf),"%lld",reply->integer);
			_list.push_back(buf);
		}while(0);
        break;
    case REDIS_REPLY_ARRAY:
        if (reply->element != NULL) {
            for (int j = 0; j < reply->elements; j++)
                if (reply->element[j] != NULL)
                {
                	parse_reply(reply->element[j],_list);
                }
        }
        break;
	case REDIS_REPLY_STRING:
		if(reply->str)
			_list.push_back(std::string(reply->str,reply->len));
		break;
	default:
        break;
	return true;
  	}   
  }
예제 #5
0
파일: http_tr_if.c 프로젝트: Koushien/btpd
static void
http_cb(struct http_req *req, struct http_response *res, void *arg)
{
    struct httptr_req *treq = arg;
    struct tr_response tres = {0, NULL, -1 };
    switch (res->type) {
    case HTTP_T_ERR:
        tres.type = TR_RES_BAD;
        tr_result(treq->tr, &tres);
        httptr_free(treq);
        break;
    case HTTP_T_DATA:
        if (treq->buf.off + res->v.data.l > MAX_DOWNLOAD) {
            tres.type = TR_RES_BAD;
            tr_result(treq->tr, &tres);
            httptr_cancel(treq);
            break;
        }
        if (!iobuf_write(&treq->buf, res->v.data.p, res->v.data.l))
            btpd_err("Out of memory.\n");
        break;
    case HTTP_T_DONE:
        if (treq->event == TR_EV_STOPPED) {
            tres.type = TR_RES_OK;
            tr_result(treq->tr, &tres);
        } else {
            parse_reply(treq->tp, &tres, treq->buf.buf, treq->buf.off);
            tr_result(treq->tr, &tres);
        }
        httptr_free(treq);
        break;
    default:
        break;
    }
}
예제 #6
0
int
main(int argc, char **argv)
{
#ifndef HAVE_MMAP
    return 77;			/* signal to automake that this test
                                   cannot be run */
#else /* HAVE_MMAP */
    int ret;
    int i;
    struct sigaction sa;

    sigemptyset (&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = segv_handler;
    sigaction (SIGSEGV, &sa, NULL);

    for (i = 0; val == 0 && i < sizeof(tests)/sizeof(tests[0]); ++i) {
	const struct testcase *t = &tests[i];
	unsigned char *p1, *p2;
	int flags;
	int fd;
	size_t pagesize = getpagesize();
	unsigned char *buf;

#ifdef MAP_ANON
	flags = MAP_ANON;
	fd = -1;
#else
	flags = 0;
	fd = open ("/dev/zero", O_RDONLY);
	if(fd < 0)
	    err (1, "open /dev/zero");
#endif
	flags |= MAP_PRIVATE;

	p1 = (unsigned char *)mmap(0, 2 * pagesize, PROT_READ | PROT_WRITE,
		  flags, fd, 0);
	if (p1 == (unsigned char *)MAP_FAILED)
	    err (1, "mmap");
	p2 = p1 + pagesize;
	ret = mprotect ((void *)p2, pagesize, 0);
	if (ret < 0)
	    err (1, "mprotect");
	buf = p2 - t->buf_len;
	memcpy (buf, t->buf, t->buf_len);
	parse_reply (buf, t->buf_len);
	ret = munmap ((void *)p1, 2 * pagesize);
	if (ret < 0)
	    err (1, "munmap");
    }
    return val;
#endif /* HAVE_MMAP */
}
예제 #7
0
// PINを使ってアクセスキーとアクセスシークレットを取得
int twitter_setpincode( char *tkey_buf , int code )
{
	
		static const char *access_token_uri = "http://api.twitter.com/oauth/access_token";

		std::string c_key; //< consumer key
		std::string c_secret; //< consumer secret
		
		std::string t_key;
		std::string t_secret;
		
		std::string req_url;
		std::string postarg;
		std::string reply;
		
		//コンシューマーキーとコンシューマーシークレットを代入
		c_key = consumer_key;
		c_secret = consumer_secret;

		// アクセストークンを取得し、t_key,t_secretに格納
		{
			char buffer[256];
			label1->Text=label1->Text+"Access token..\n";
			
			std::string url = access_token_uri;
			url += "?oauth_verifier=";
			url +=  itoa( code , buffer , 10 );

			std::string req_url = oauth_sign_url2(url.c_str(), 0, OA_HMAC, 0, c_key.c_str(), 0, t_key.c_str(), 0);
			std::string reply = oauth_http_get(req_url.c_str(), postarg.c_str());

			// 反応がなかった場合
			if (!parse_reply(reply.c_str(), &t_key, &t_secret))
       		{

				MessageBox (NULL,"failed to get request token.", "ERROR!",MB_OK);
        		return FALSE;
        	}
		}

		 // 't_key' と 't_secret' を表示
		label1->Text=label1->Text+"access key: "+ t_key.c_str()+"\n";
		label1->Text=label1->Text+"access secret: "+ t_secret.c_str()+"\n";

		//とりあえずファイルに書き出す
		{
        	FILE *fp;
        	fp = fopen("access.txt","a");
        	fprintf( fp , "%s\r\n%s\r\n" , t_key.c_str() , t_secret.c_str() );
        	fclose( fp );
   		}
   		return TRUE;
}
예제 #8
0
// アプリケーション認証にアクセスし、PINコードを取得
int twitter_getpincode( char *tkey_buf , int size )
{
	static const char *request_token_uri = "http://api.twitter.com/oauth/request_token";
	static const char *authorize_uri = "http://api.twitter.com/oauth/authorize";
	static const char *access_token_uri = "http://api.twitter.com/oauth/access_token";

	std::string c_key; //< consumer key
	std::string c_secret; //< consumer secret

	std::string t_key;
	std::string t_secret;

	std::string req_url;
	std::string postarg;
	std::string reply;

	// アプリケーションのキーを代入
	c_key = consumer_key;
	c_secret = consumer_secret;

	// メッセージを表示
	label1->Text="Request token..\n";

    // 認証ページにアクセス
    {
        std::string reply;
        std::string req_url = oauth_sign_url2(request_token_uri, &postarg, OA_HMAC, 0, c_key.c_str(), c_secret.c_str(), 0, 0);
        reply = oauth_http_post(req_url.c_str(),postarg.c_str());

		// 反応がなかった場合
		if (!parse_reply(reply.c_str(), &t_key, &t_secret))
        {
			MessageBox (NULL,"failed to get request token.", "ERROR!",MB_OK);
            return FALSE;
        }
    }

	//

	// メッセージを表示
	label1->Text=label1->Text+"Authorize..\n";

	// PINを表示
	{
		std::string req_url = oauth_sign_url2(authorize_uri, 0, OA_HMAC, 0, c_key.c_str(), c_secret.c_str(), t_key.c_str(), t_secret.c_str());

		label1->Text=label1->Text+"Opening...\n";
		puts(req_url.c_str());
		ShellExecute(0, 0, req_url.c_str(), 0, 0, SW_SHOW); // ウェブブラウザを起動する
	}
	return TRUE;
}
예제 #9
0
파일: redis.hpp 프로젝트: csj561/c_plusplus
  bool cmd(const char *_cmd,listStr & _list)
  {
  	_list.clear();
  	if(_cmd)
  		this->_reply = (redisReply*)redisCommand(this->_connect, _cmd);
    if(this->_reply)
    {
		parse_reply(this->_reply,_list);
    	freeReplyObject(this->_reply);
		this->_reply=NULL;
    }
    true;;
  }
예제 #10
0
struct carrier_data *__near_agent_handover_request_data(
					enum ho_agent_carrier carrier,
					struct carrier_data *data)
{
	DBusMessage *message;
	DBusMessage *reply;
	DBusError error;
	struct carrier_data *data_reply;
	struct near_handover_agent *agent = NULL;

	agent = g_hash_table_lookup(ho_agent_hash,
				GINT_TO_POINTER(carrier));
	if (!agent)
		return NULL;

	message = dbus_message_new_method_call(agent->sender,
			agent->path, NFC_HANDOVER_AGENT_INTERFACE,
			"RequestOOB");
	if (!message)
		return NULL;

	prepare_data(message, data);

	dbus_error_init(&error);

	reply = dbus_connection_send_with_reply_and_block(connection, message,
					DBUS_TIMEOUT_USE_DEFAULT, &error);

	dbus_message_unref(message);

	if (!reply) {
		if (dbus_error_is_set(&error)) {
			near_error("RequestOOB failed: %s", error.message);
			dbus_error_free(&error);
		} else {
			near_error("RequestOOB failed");
		}
		return NULL;
	}

	data_reply = parse_reply(reply);

	dbus_message_unref(reply);

	DBG("OOB data %p", data_reply);

	return data_reply;
}
예제 #11
0
void AP_Mount_SToRM32_serial::read_incoming() {
    uint8_t data;
    int16_t numc;

    numc = _port->available();

    if (numc < 0 ){
        return;
    }

    for (int16_t i = 0; i < numc; i++) {        // Process bytes received
        data = _port->read();
        if (_reply_type == ReplyType_UNKNOWN) {
            continue;
        }

        _buffer[_reply_counter++] = data;
        if (_reply_counter == _reply_length) {
            parse_reply();

            switch (_reply_type) {
                case ReplyType_ACK:
                    _reply_type = ReplyType_DATA;
                    _reply_length = get_reply_size(_reply_type);
                    _reply_counter = 0;
                    break;
                case ReplyType_DATA:
                    _reply_type = ReplyType_UNKNOWN;
                    _reply_length = get_reply_size(_reply_type);
                    _reply_counter = 0;
                    break;
                default:
                    _reply_length = get_reply_size(_reply_type);
                    _reply_counter = 0;
                    break;
            }
        }
    }
}
예제 #12
0
파일: redis.hpp 프로젝트: csj561/c_plusplus
  bool cmd(int _argc,const char**_argv,listStr & _list)
  {
  	_list.clear();
	size_t *_argv_len=new size_t[_argc+1];
	for(int i=0;i<_argc;i++)
		_argv_len[i]=strlen(_argv[i]);
  	this->_reply = (redisReply*)redisCommandArgv(this->_connect,_argc+1,_argv,_argv_len);
	delete []_argv_len;
	do
	{
		if(this->_reply)
	    {
	    	if(REDIS_REPLY_ERROR == _reply->type)
				break;
			parse_reply(this->_reply,_list);
	    	freeReplyObject(this->_reply);
			this->_reply=NULL;
			return true;
	    }
	}while(0);
	std::cout<<"ERR::"<<_connect->err<<std::endl;
    false;;
  }
예제 #13
0
void main_loop(int icmp_sock, __u8 *packet, int packlen)
{
	char addrbuf[128];
	char ans_data[4096];
	struct iovec iov;
	struct msghdr msg;
	struct cmsghdr *c;
	int cc;
	int next;
	int polling;

	iov.iov_base = (char *)packet;

	for (;;) {
		/* Check exit conditions. */
		if (exiting)
			break;
		if (npackets && nreceived + nerrors >= npackets)
			break;
		if (deadline && nerrors)
			break;
		/* Check for and do special actions. */
		if (status_snapshot)
			status();

		/* Send probes scheduled to this time. */
		do {
			next = pinger();
			next = schedule_exit(next);
		} while (next <= 0);

		/* "next" is time to send next probe, if positive.
		 * If next<=0 send now or as soon as possible. */

		/* Technical part. Looks wicked. Could be dropped,
		 * if everyone used the newest kernel. :-)
		 * Its purpose is:
		 * 1. Provide intervals less than resolution of scheduler.
		 *    Solution: spinning.
		 * 2. Avoid use of poll(), when recvmsg() can provide
		 *    timed waiting (SO_RCVTIMEO). */
		polling = 0;
		if ((options & (F_ADAPTIVE|F_FLOOD_POLL)) || next<SCHINT(interval)) {
			int recv_expected = in_flight();

			/* If we are here, recvmsg() is unable to wait for
			 * required timeout. */
			if (1000 % HZ == 0 ? next <= 1000 / HZ : (next < INT_MAX / HZ && next * HZ <= 1000)) {
				/* Very short timeout... So, if we wait for
				 * something, we sleep for MININTERVAL.
				 * Otherwise, spin! */
				if (recv_expected) {
					next = MININTERVAL;
				} else {
					next = 0;
					/* When spinning, no reasons to poll.
					 * Use nonblocking recvmsg() instead. */
					polling = MSG_DONTWAIT;
					/* But yield yet. */
					sched_yield();
				}
			}

			if (!polling &&
			    ((options & (F_ADAPTIVE|F_FLOOD_POLL)) || interval)) {
				struct pollfd pset;
				pset.fd = icmp_sock;
				pset.events = POLLIN|POLLERR;
				pset.revents = 0;
				if (poll(&pset, 1, next) < 1 ||
				    !(pset.revents&(POLLIN|POLLERR)))
					continue;
				polling = MSG_DONTWAIT;
			}
		}

		for (;;) {
			struct timeval *recv_timep = NULL;
			struct timeval recv_time;
			int not_ours = 0; /* Raw socket can receive messages
					   * destined to other running pings. */

			iov.iov_len = packlen;
			memset(&msg, 0, sizeof(msg));
			msg.msg_name = addrbuf;
			msg.msg_namelen = sizeof(addrbuf);
			msg.msg_iov = &iov;
			msg.msg_iovlen = 1;
			msg.msg_control = ans_data;
			msg.msg_controllen = sizeof(ans_data);

			cc = recvmsg(icmp_sock, &msg, polling);
			polling = MSG_DONTWAIT;

			if (cc < 0) {
				if (errno == EAGAIN || errno == EINTR)
					break;
				if (!receive_error_msg()) {
					if (errno) {
						perror("ping: recvmsg");
						break;
					}
					not_ours = 1;
				}
			} else {

#ifdef SO_TIMESTAMP
				for (c = CMSG_FIRSTHDR(&msg); c; c = CMSG_NXTHDR(&msg, c)) {
					if (c->cmsg_level != SOL_SOCKET ||
					    c->cmsg_type != SO_TIMESTAMP)
						continue;
					if (c->cmsg_len < CMSG_LEN(sizeof(struct timeval)))
						continue;
					recv_timep = (struct timeval*)CMSG_DATA(c);
				}
#endif

				if ((options&F_LATENCY) || recv_timep == NULL) {
					if ((options&F_LATENCY) ||
					    ioctl(icmp_sock, SIOCGSTAMP, &recv_time))
						gettimeofday(&recv_time, NULL);
					recv_timep = &recv_time;
				}

				not_ours = parse_reply(&msg, cc, addrbuf, recv_timep);
			}

			/* See? ... someone runs another ping on this host. */
			if (not_ours && !using_ping_socket)
				install_filter();

			/* If nothing is in flight, "break" returns us to pinger. */
			if (in_flight() == 0)
				break;

			/* Otherwise, try to recvmsg() again. recvmsg()
			 * is nonblocking after the first iteration, so that
			 * if nothing is queued, it will receive EAGAIN
			 * and return to pinger. */
		}
	}
	finish();
}
예제 #14
0
int post_auth_handler(worker_st * ws, unsigned http_ver)
{
	int ret = -1, sd = -1;
	struct http_req_st *req = &ws->req;
	const char *reason = "Authentication failed";
	char *username = NULL;
	char *password = NULL;
	char *groupname = NULL;
	char *msg = NULL;
	unsigned def_group = 0;

	if (req->body_length > 0) {
		oclog(ws, LOG_HTTP_DEBUG, "POST body: '%.*s'", (int)req->body_length,
		      req->body);
	}

	if (ws->sid_set && ws->auth_state == S_AUTH_INACTIVE)
		ws->auth_state = S_AUTH_INIT;

	if (ws->auth_state == S_AUTH_INACTIVE) {
		SecAuthInitMsg ireq = SEC_AUTH_INIT_MSG__INIT;

		ret = parse_reply(ws, req->body, req->body_length,
				GROUPNAME_FIELD, sizeof(GROUPNAME_FIELD)-1,
				GROUPNAME_FIELD_XML, sizeof(GROUPNAME_FIELD_XML)-1,
				&groupname);
		if (ret < 0) {
			ret = parse_reply(ws, req->body, req->body_length,
					GROUPNAME_FIELD2, sizeof(GROUPNAME_FIELD2)-1,
					GROUPNAME_FIELD_XML, sizeof(GROUPNAME_FIELD_XML)-1,
					&groupname);
		}

		if (ret < 0) {
			oclog(ws, LOG_HTTP_DEBUG, "failed reading groupname");
		} else {
			if (ws->config->default_select_group != NULL &&
				   strcmp(groupname, ws->config->default_select_group) == 0) {
				def_group = 1;
			} else {
				strlcpy(ws->groupname, groupname, sizeof(ws->groupname));
				ireq.group_name = ws->groupname;
			}
		}
		talloc_free(groupname);

		if (ws->selected_auth->type & AUTH_TYPE_GSSAPI) {
			if (req->authorization == NULL || req->authorization_size == 0)
				return basic_auth_handler(ws, http_ver, NULL);

			if (req->authorization_size > 10) {
				ireq.user_name = req->authorization + 10;
				ireq.auth_type |= AUTH_TYPE_GSSAPI;
			} else {
				oclog(ws, LOG_HTTP_DEBUG, "Invalid authorization data: %.*s", req->authorization_size, req->authorization);
				goto auth_fail;
			}
		}

		if (ws->selected_auth->type & AUTH_TYPE_USERNAME_PASS) {

			ret = parse_reply(ws, req->body, req->body_length,
					USERNAME_FIELD, sizeof(USERNAME_FIELD)-1,
					NULL, 0,
					&username);
			if (ret < 0) {
				oclog(ws, LOG_HTTP_DEBUG, "failed reading username");
				goto ask_auth;
			}

			strlcpy(ws->username, username, sizeof(ws->username));
			talloc_free(username);
			ireq.user_name = ws->username;
			ireq.auth_type |= AUTH_TYPE_USERNAME_PASS;
		}

		if (ws->selected_auth->type & AUTH_TYPE_CERTIFICATE) {
			if (ws->cert_auth_ok == 0) {
				reason = MSG_NO_CERT_ERROR;
				oclog(ws, LOG_INFO,
				      "no certificate provided for authentication");
				goto auth_fail;
			} else {
				ret = get_cert_info(ws);
				if (ret < 0) {
					reason = MSG_CERT_READ_ERROR;
					oclog(ws, LOG_ERR,
					      "failed reading certificate info");
					goto auth_fail;
				}
			}

			if (def_group == 0 && ws->cert_groups_size > 0 && ws->groupname[0] == 0) {
				oclog(ws, LOG_HTTP_DEBUG, "user has not selected a group");
				return get_auth_handler2(ws, http_ver, "Please select your group");
			}

			ireq.tls_auth_ok = ws->cert_auth_ok;
			ireq.cert_user_name = ws->cert_username;
			ireq.cert_group_names = ws->cert_groups;
			ireq.n_cert_group_names = ws->cert_groups_size;
			ireq.auth_type |= AUTH_TYPE_CERTIFICATE;
		}

		ireq.hostname = req->hostname;
		ireq.ip = ws->remote_ip_str;

		sd = connect_to_secmod(ws);
		if (sd == -1) {
			reason = MSG_INTERNAL_ERROR;
			oclog(ws, LOG_ERR, "failed connecting to sec mod");
			goto auth_fail;
		}

		ret = send_msg_to_secmod(ws, sd, SM_CMD_AUTH_INIT,
					 &ireq, (pack_size_func)
					 sec_auth_init_msg__get_packed_size,
					 (pack_func) sec_auth_init_msg__pack);
		if (ret < 0) {
			reason = MSG_INTERNAL_ERROR;
			oclog(ws, LOG_ERR,
			      "failed sending auth init message to sec mod");
			goto auth_fail;
		}

		ws->auth_state = S_AUTH_INIT;
	} else if (ws->auth_state == S_AUTH_INIT
		   || ws->auth_state == S_AUTH_REQ) {
		SecAuthContMsg areq = SEC_AUTH_CONT_MSG__INIT;

		areq.ip = ws->remote_ip_str;

		if (ws->selected_auth->type & AUTH_TYPE_GSSAPI) {
			if (req->authorization == NULL || req->authorization_size <= 10) {
				if (req->authorization != NULL)
					oclog(ws, LOG_HTTP_DEBUG, "Invalid authorization data: %.*s", req->authorization_size, req->authorization);
				goto auth_fail;
			}
			areq.password = req->authorization + 10;
		}

		if (areq.password == NULL && ws->selected_auth->type & AUTH_TYPE_USERNAME_PASS) {
			ret = parse_reply(ws, req->body, req->body_length,
					PASSWORD_FIELD, sizeof(PASSWORD_FIELD)-1,
					NULL, 0,
					&password);
			if (ret < 0) {
				reason = MSG_NO_PASSWORD_ERROR;
				oclog(ws, LOG_ERR, "failed reading password");
				goto auth_fail;
			}

			areq.password = password;
		}

		if (areq.password != NULL) {
			if (ws->sid_set != 0) {
				areq.sid.data = ws->sid;
				areq.sid.len = sizeof(ws->sid);
			}

			sd = connect_to_secmod(ws);
			if (sd == -1) {
				reason = MSG_INTERNAL_ERROR;
				oclog(ws, LOG_ERR,
				      "failed connecting to sec mod");
				goto auth_fail;
			}

			ret =
			    send_msg_to_secmod(ws, sd, SM_CMD_AUTH_CONT, &areq,
					       (pack_size_func)
					       sec_auth_cont_msg__get_packed_size,
					       (pack_func)
					       sec_auth_cont_msg__pack);
			talloc_free(password);

			if (ret < 0) {
				reason = MSG_INTERNAL_ERROR;
				oclog(ws, LOG_ERR,
				      "failed sending auth req message to main");
				goto auth_fail;
			}

			ws->auth_state = S_AUTH_REQ;
		} else
			goto auth_fail;
	} else {
		oclog(ws, LOG_ERR, "unexpected POST request in auth state %u",
		      (unsigned)ws->auth_state);
		goto auth_fail;
	}

	ret = recv_auth_reply(ws, sd, &msg);
	if (sd != -1) {
		close(sd);
		sd = -1;
	}

	if (ret == ERR_AUTH_CONTINUE) {
		oclog(ws, LOG_DEBUG, "continuing authentication for '%s'",
		      ws->username);
		ws->auth_state = S_AUTH_REQ;

		if (ws->selected_auth->type & AUTH_TYPE_GSSAPI) {
			ret = basic_auth_handler(ws, http_ver, msg);
		} else {
			ret = get_auth_handler2(ws, http_ver, msg);
		}
		goto cleanup;
	} else if (ret < 0) {
		if (ws->selected_auth->type & AUTH_TYPE_GSSAPI) {
			/* Fallback from GSSAPI to USERNAME-PASSWORD */
			ws_disable_auth(ws, AUTH_TYPE_GSSAPI);
			oclog(ws, LOG_ERR, "failed gssapi authentication");
			if (ws_switch_auth_to(ws, AUTH_TYPE_USERNAME_PASS) == 0)
				goto auth_fail;

			ws->auth_state = S_AUTH_INACTIVE;
			ws->sid_set = 0;
			goto ask_auth;
		} else {
			oclog(ws, LOG_ERR, "failed authentication for '%s'",
			      ws->username);
			goto auth_fail;
		}
	}

	oclog(ws, LOG_HTTP_DEBUG, "user '%s' obtained cookie", ws->username);
	ws->auth_state = S_AUTH_COOKIE;

	ret = post_common_handler(ws, http_ver, msg);
	goto cleanup;

 ask_auth:

	return get_auth_handler(ws, http_ver);

 auth_fail:

	if (sd != -1)
		close(sd);
	oclog(ws, LOG_HTTP_DEBUG, "HTTP sending: 401 Unauthorized");
	cstp_printf(ws,
		   "HTTP/1.%d 401 Unauthorized\r\nContent-Length: 0\r\nX-Reason: %s\r\n\r\n",
		   http_ver, reason);
	cstp_fatal_close(ws, GNUTLS_A_ACCESS_DENIED);
	talloc_free(msg);
	exit_worker(ws);
 cleanup:
 	talloc_free(msg);
 	return ret;
}
예제 #15
0
파일: getprefix.c 프로젝트: jjsarton/nins
int main(int argc, char **argv)
{
    char *prgName = NULL;
    int c;
    char *iface = NULL;
    if ( (prgName=strrchr(argv[0],'/')) )
        prgName++;
    else
        prgName = argv[0];

    while( (c = getopt(argc, argv, "i:h")) > 0)
    {
        switch(c)
        {
            case 'i':
                iface = optarg;
            break;
            case 'h':
                usage(prgName);
                return 1;
            break;
        }
    }
    if ( iface == NULL )
    {
        usage(prgName);
        return 1;
    }

    /* open socket */
    int fd = icmp_socket(iface);
    if ( fd == -1 ) return 1;
    /* send a router solicitation */
    unsigned char buf[2048];
    if ((c = send_ra_solicit(fd, buf))< 0 ) return 1;
    /* listen for router advertisement */
    struct pollfd pollfd;
    pollfd.fd = fd;
    pollfd.events = POLLIN;
    pollfd.revents = 0;
    int rp = poll(&pollfd, 1, 2000); /* wait max 2 sec. */
    if ( rp > 0 )
    {
        /* print prefix on stdout */
        char ans_data[4096];
        struct iovec iov;
        struct msghdr msg;
        int cc;
        iov.iov_len = sizeof(ans_data);
        iov.iov_base = ans_data;
        memset(&msg, 0, sizeof(msg));
        msg.msg_name = NULL;
        msg.msg_namelen = 0;
        msg.msg_iov = &iov;
        msg.msg_iovlen = 1;
        msg.msg_control = ans_data;
        msg.msg_controllen = sizeof(ans_data);
        cc = recvmsg(fd, &msg, MSG_DONTWAIT);
        if (cc < 0)
        {
            perror("recvmsg:");
            return 1;
        }
        else
        {
            parse_reply(&msg, cc);
        }
        
    }
    else
    {
        return 1;
    }
    return 0;
}