Lines Matching defs:cctx
94 static errno_t get_client_cred(struct cli_ctx *cctx)
99 cctx->creds = talloc(cctx, struct cli_creds);
100 if (!cctx->creds) return ENOMEM;
105 cctx->creds->ucred.uid = -1;
106 cctx->creds->ucred.gid = -1;
107 cctx->creds->ucred.pid = -1;
109 ret = getsockopt(cctx->cfd, SOL_SOCKET, SO_PEERCRED, &cctx->creds->ucred,
125 cctx->creds->ucred.uid, cctx->creds->ucred.gid,
126 cctx->creds->ucred.pid);
129 ret = SELINUX_getpeercon(cctx->cfd, &secctx);
139 cctx->creds->selinux_ctx = SELINUX_context_new(secctx);
251 static void client_send(struct cli_ctx *cctx)
256 pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
258 ret = sss_packet_send(pctx->creq->out, cctx->cfd);
265 talloc_free(cctx);
270 TEVENT_FD_NOT_WRITEABLE(cctx->cfde);
271 TEVENT_FD_READABLE(cctx->cfde);
276 static int client_cmd_execute(struct cli_ctx *cctx, struct sss_cmd_table *sss_cmds)
281 pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
283 return sss_cmd_execute(cctx, cmd, sss_cmds);
286 static void client_recv(struct cli_ctx *cctx)
291 pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
294 pctx->creq = talloc_zero(cctx, struct cli_request);
298 talloc_free(cctx);
309 talloc_free(cctx);
314 ret = sss_packet_recv(pctx->creq->in, cctx->cfd);
318 TEVENT_FD_NOT_READABLE(cctx->cfde);
320 ret = client_cmd_execute(cctx, cctx->rctx->sss_cmds);
324 talloc_free(cctx);
326 /* past this point cctx can be freed at any time by callbacks
337 talloc_free(cctx);
342 talloc_free(cctx);
347 talloc_free(cctx);
358 struct cli_ctx *cctx = talloc_get_type(ptr, struct cli_ctx);
361 ret = reset_idle_timer(cctx);
370 client_recv(cctx);
374 client_send(cctx);
393 struct cli_ctx *cctx;
418 cctx = talloc_zero(rctx, struct cli_ctx);
419 if (!cctx) {
435 len = sizeof(cctx->addr);
436 cctx->cfd = accept(fd, (struct sockaddr *)&cctx->addr, &len);
437 if (cctx->cfd == -1) {
439 talloc_free(cctx);
443 cctx->priv = accept_ctx->is_private;
445 ret = get_client_cred(cctx);
452 if (client_euid(cctx->creds) == -1) {
457 close(cctx->cfd);
458 talloc_free(cctx);
462 ret = check_allowed_uids(client_euid(cctx->creds), rctx->allowed_uids_count,
468 client_euid(cctx->creds));
472 close(cctx->cfd);
473 talloc_free(cctx);
478 ret = accept_ctx->connection_setup(cctx);
480 close(cctx->cfd);
481 talloc_free(cctx);
488 cctx->cfde = tevent_add_fd(ev, cctx, cctx->cfd,
489 TEVENT_FD_READ, cctx->cfd_handler,
490 cctx);
491 if (!cctx->cfde) {
492 close(cctx->cfd);
493 talloc_free(cctx);
499 tevent_fd_set_close_fn(cctx->cfde, client_close_fn);
501 cctx->ev = ev;
502 cctx->rctx = rctx;
505 ret = reset_idle_timer(cctx);
520 errno_t reset_idle_timer(struct cli_ctx *cctx)
523 tevent_timeval_current_ofs(cctx->rctx->client_idle_timeout, 0);
525 talloc_zfree(cctx->idle);
527 cctx->idle = tevent_add_timer(cctx->ev, cctx, tv, idle_handler, cctx);
528 if (!cctx->idle) return ENOMEM;
532 cctx, cctx->cfd);
543 struct cli_ctx *cctx =
548 cctx, cctx->cfd);
551 talloc_free(cctx);
835 int sss_connection_setup(struct cli_ctx *cctx)
837 cctx->protocol_ctx = talloc_zero(cctx, struct cli_protocol);
838 if (!cctx->protocol_ctx) {
842 cctx->cfd_handler = client_fd_handler;