Lines Matching refs:cctx

99 static errno_t get_client_cred(struct cli_ctx *cctx)
104 cctx->creds = talloc_zero(cctx, struct cli_creds);
105 if (!cctx->creds) return ENOMEM;
110 cctx->creds->ucred.uid = -1;
111 cctx->creds->ucred.gid = -1;
112 cctx->creds->ucred.pid = -1;
114 ret = getsockopt(cctx->cfd, SOL_SOCKET, SO_PEERCRED, &cctx->creds->ucred,
130 cctx->creds->ucred.uid, cctx->creds->ucred.gid,
131 cctx->creds->ucred.pid);
134 ret = SELINUX_getpeercon(cctx->cfd, &secctx);
144 cctx->creds->selinux_ctx = SELINUX_context_new(secctx);
256 static void client_send(struct cli_ctx *cctx)
261 pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
263 ret = sss_packet_send(pctx->creq->out, cctx->cfd);
270 talloc_free(cctx);
275 TEVENT_FD_NOT_WRITEABLE(cctx->cfde);
276 TEVENT_FD_READABLE(cctx->cfde);
281 static int client_cmd_execute(struct cli_ctx *cctx, struct sss_cmd_table *sss_cmds)
286 pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
288 return sss_cmd_execute(cctx, cmd, sss_cmds);
291 static void client_recv(struct cli_ctx *cctx)
296 pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
299 pctx->creq = talloc_zero(cctx, struct cli_request);
303 talloc_free(cctx);
314 talloc_free(cctx);
319 ret = sss_packet_recv(pctx->creq->in, cctx->cfd);
323 TEVENT_FD_NOT_READABLE(cctx->cfde);
325 ret = client_cmd_execute(cctx, cctx->rctx->sss_cmds);
329 talloc_free(cctx);
331 /* past this point cctx can be freed at any time by callbacks
342 talloc_free(cctx);
347 talloc_free(cctx);
352 talloc_free(cctx);
447 static errno_t setup_client_idle_timer(struct cli_ctx *cctx);
449 static int cli_ctx_destructor(struct cli_ctx *cctx)
451 if (cctx->creds == NULL) {
455 if (cctx->creds->selinux_ctx == NULL) {
459 SELINUX_context_free(cctx->creds->selinux_ctx);
460 cctx->creds->selinux_ctx = NULL;
479 struct cli_ctx *cctx;
504 cctx = talloc_zero(rctx, struct cli_ctx);
505 if (!cctx) {
521 talloc_set_destructor(cctx, cli_ctx_destructor);
523 len = sizeof(cctx->addr);
524 cctx->cfd = accept(fd, (struct sockaddr *)&cctx->addr, &len);
525 if (cctx->cfd == -1) {
527 talloc_free(cctx);
531 cctx->priv = accept_ctx->is_private;
533 ret = get_client_cred(cctx);
540 if (client_euid(cctx->creds) == -1) {
545 close(cctx->cfd);
546 talloc_free(cctx);
550 ret = check_allowed_uids(client_euid(cctx->creds), rctx->allowed_uids_count,
556 client_euid(cctx->creds));
560 close(cctx->cfd);
561 talloc_free(cctx);
566 ret = accept_ctx->connection_setup(cctx);
568 close(cctx->cfd);
569 talloc_free(cctx);
576 cctx->cfde = tevent_add_fd(ev, cctx, cctx->cfd,
577 TEVENT_FD_READ, cctx->cfd_handler,
578 cctx);
579 if (!cctx->cfde) {
580 close(cctx->cfd);
581 talloc_free(cctx);
587 tevent_fd_set_close_fn(cctx->cfde, client_close_fn);
589 cctx->ev = ev;
590 cctx->rctx = rctx;
593 ret = reset_client_idle_timer(cctx);
601 ret = setup_client_idle_timer(cctx);
622 struct cli_ctx *cctx = talloc_get_type(data, struct cli_ctx);
624 if (cctx->last_request_time > now) {
630 if ((now - cctx->last_request_time) > cctx->rctx->client_idle_timeout) {
634 cctx, cctx->cfd);
637 talloc_free(cctx);
642 setup_client_idle_timer(cctx);
645 errno_t reset_client_idle_timer(struct cli_ctx *cctx)
647 cctx->last_request_time = time(NULL);
652 static errno_t setup_client_idle_timer(struct cli_ctx *cctx)
655 tevent_timeval_current_ofs(cctx->rctx->client_idle_timeout/2, 0);
657 talloc_zfree(cctx->idle);
659 cctx->idle = tevent_add_timer(cctx->ev, cctx, tv, client_idle_handler, cctx);
660 if (!cctx->idle) return ENOMEM;
664 cctx, cctx->cfd);
964 void (*recv_fn) (struct cli_ctx *cctx),
965 void (*send_fn) (struct cli_ctx *cctx),
969 struct cli_ctx *cctx = talloc_get_type(ptr, struct cli_ctx);
972 cctx->rctx->last_request_time = time(NULL);
975 ret = reset_client_idle_timer(cctx);
984 recv_fn(cctx);
989 send_fn(cctx);
994 int sss_connection_setup(struct cli_ctx *cctx)
996 cctx->protocol_ctx = talloc_zero(cctx, struct cli_protocol);
997 if (!cctx->protocol_ctx) {
1001 cctx->cfd_handler = client_fd_handler;