| 1 | /* assuan-connect.c - Establish a connection (client) |
| 2 | * Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
| 3 | * |
| 4 | * This file is part of Assuan. |
| 5 | * |
| 6 | * Assuan is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU Lesser General Public License as |
| 8 | * published by the Free Software Foundation; either version 2.1 of |
| 9 | * the License, or (at your option) any later version. |
| 10 | * |
| 11 | * Assuan is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:410:9`! |
| 21 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 22 | #endif |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | #include <signal.h> |
| 28 | #include <unistd.h> |
| 29 | #include <errno.h> |
| 30 | #include <sys/types.h> |
| 31 | #ifndef HAVE_W32_SYSTEM |
| 32 | #include <sys/wait.h> |
| 33 | #endif |
| 34 | |
| 35 | #include "assuan-defs.h"cxx . . $ `<file>/src/assuan/assuan-defs.h`/ |
| 36 | |
| 37 | /* Disconnect and release the context CTX. */ |
| 38 | void |
| 39 | assuan_disconnectcxx . . $ `src/assuan/assuan.h:117:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx) |
| 40 | { |
| 41 | if (ctx) |
| 42 | { |
| 43 | assuan_write_linecxx . . $ `src/assuan/assuan.h:125:9`! (ctx, "BYE"); |
| 44 | ctx->finish_handlercxx . . $ assuan_context_s#finish_handler. (ctx); |
| 45 | ctx->deinit_handlercxx . . $ assuan_context_s#deinit_handler. (ctx); |
| 46 | ctx->deinit_handlercxx . . $ assuan_context_s#deinit_handler. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 47 | _assuan_release_contextcxx . . $ `src/assuan/assuan.h:174:9`! (ctx); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /* Return the PID of the peer or -1 if not known. This function works |
| 52 | in some situations where assuan_get_ucred fails. */ |
| 53 | pid_tcxx . . $ pid_t# |
| 54 | assuan_get_pidcxx . . $ `src/assuan/assuan.h:118:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx) |
| 55 | { |
| 56 | return (ctx && ctx->pidcxx . . $ assuan_context_s#pid.)? ctx->pidcxx . . $ assuan_context_s#pid. : -1; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | #ifndef HAVE_W32_SYSTEM |
| 61 | /* Return user credentials. PID, UID and GID amy be gived as NULL if |
| 62 | you are not interested in this value. For getting the pid of the |
| 63 | peer the assuan_get_pid is usually better suited. */ |
| 64 | assuan_error_tcxx . . $ assuan_error_t# |
| 65 | assuan_get_peercredcxx . . $ `src/assuan/assuan.h:119:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx, pid_tcxx . . $ pid_t# *pid, uid_tcxx . . $ uid_t# *uid, gid_tcxx . . $ gid_t# *gid) |
| 66 | { |
| 67 | if (!ctx) |
| 68 | return _assuan_errorcxx . . $ `src/assuan/assuan.h:189:9`! (ASSUAN_Invalid_Valuecxx . . $ `src/assuan/assuan.h:240:10`!); |
| 69 | if (!ctx->peercredcxx . . $ assuan_context_s#peercred..validcxx . . $ assuan_context_s#$anonymous_type_5#valid.) |
| 70 | return _assuan_errorcxx . . $ `src/assuan/assuan.h:189:9`! (ASSUAN_General_Errorcxx . . $ `src/assuan/assuan.h:238:10`!); |
| 71 | |
| 72 | #ifdef HAVE_SO_PEERCRED |
| 73 | if (pid) |
| 74 | *pid = ctx->peercred.pid; |
| 75 | if (uid) |
| 76 | *uid = ctx->peercred.uid; |
| 77 | if (gid) |
| 78 | *gid = ctx->peercred.gid; |
| 79 | #endif |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | #endif /* HAVE_W32_SYSTEM */ |