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 if (ctx
->user_finish_handler
)
45 ctx
->user_finish_handler(ctx
);
46 ctx
->finish_handler (ctx
);
47 ctx
->deinit_handler (ctx
);
48 ctx
->deinit_handler
= NULL
;
49 _assuan_release_context (ctx
);
53 /* Return the PID of the peer or -1 if not known. This function works
54 in some situations where assuan_get_ucred fails. */
56 assuan_get_pid (assuan_context_t ctx
)
58 return (ctx
&& ctx
->pid
)? ctx
->pid
: -1;
62 #ifndef HAVE_W32_SYSTEM
63 /* Return user credentials. PID, UID and GID amy be gived as NULL if
64 you are not interested in this value. For getting the pid of the
65 peer the assuan_get_pid is usually better suited. */
67 assuan_get_peercred (assuan_context_t ctx
, pid_t
*pid
, uid_t
*uid
, gid_t
*gid
)
70 return _assuan_error (ASSUAN_Invalid_Value
);
71 if (!ctx
->peercred
.valid
)
72 return _assuan_error (ASSUAN_General_Error
);
74 #ifdef HAVE_SO_PEERCRED
76 *pid
= ctx
->peercred
.pid
;
78 *uid
= ctx
->peercred
.uid
;
80 *gid
= ctx
->peercred
.gid
;
85 #endif /* HAVE_W32_SYSTEM */