1 /* assuan-connect.c - Establish a connection (client)
2 * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4 * This file is part of Assuan.
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.
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.
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/>.
30 #include <sys/types.h>
31 #ifndef HAVE_W32_SYSTEM
35 #include "assuan-defs.h"
37 /* Disconnect and release the context CTX. */
39 assuan_disconnect (assuan_context_t ctx
)
43 assuan_write_line (ctx
, "BYE");
44 ctx
->finish_handler (ctx
);
45 ctx
->deinit_handler (ctx
);
46 ctx
->deinit_handler
= NULL
;
47 _assuan_release_context (ctx
);
51 /* Return the PID of the peer or -1 if not known. This function works
52 in some situations where assuan_get_ucred fails. */
54 assuan_get_pid (assuan_context_t ctx
)
56 return (ctx
&& ctx
->pid
)? ctx
->pid
: -1;
60 #ifndef HAVE_W32_SYSTEM
61 /* Return user credentials. PID, UID and GID may be given as NULL if
62 you are not interested in a value. For getting the pid of the
63 peer the assuan_get_pid is usually better suited. */
65 assuan_get_peercred (assuan_context_t ctx
, pid_t
*pid
, uid_t
*uid
, gid_t
*gid
)
68 return _assuan_error (ASSUAN_Invalid_Value
);
69 if (!ctx
->peercred
.valid
)
70 return _assuan_error (ASSUAN_General_Error
);
72 #ifdef HAVE_SO_PEERCRED
74 *pid
= ctx
->peercred
.pid
;
76 *uid
= ctx
->peercred
.uid
;
78 *gid
= ctx
->peercred
.gid
;
83 #endif /* HAVE_W32_SYSTEM */