2 Unix SMB/CIFS implementation.
3 Copyright (C) Tim Potter 2000-2001
4 Copyright (C) 2001 by Martin Pool <mbp@samba.org>
5 Copyright (C) James Peach 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "smb_launchd.h"
26 #define DBGC_CLASS DBGC_WINBIND
28 /* Open the winbindd socket */
30 static int _winbindd_socket
= -1;
31 static int _winbindd_priv_socket
= -1;
32 static BOOL unlink_winbindd_socket
= True
;
34 static int open_winbindd_socket(void)
36 if (_winbindd_socket
== -1) {
37 _winbindd_socket
= create_pipe_sock(
38 get_winbind_pipe_dir(), WINBINDD_SOCKET_NAME
, 0755);
39 DEBUG(10, ("open_winbindd_socket: opened socket fd %d\n",
43 return _winbindd_socket
;
46 static int open_winbindd_priv_socket(void)
48 if (_winbindd_priv_socket
== -1) {
49 _winbindd_priv_socket
= create_pipe_sock(
50 get_winbind_priv_pipe_dir(), WINBINDD_SOCKET_NAME
, 0750);
51 DEBUG(10, ("open_winbindd_priv_socket: opened socket fd %d\n",
52 _winbindd_priv_socket
));
55 return _winbindd_priv_socket
;
58 /* Close the winbindd socket */
60 static void close_winbindd_socket(void)
62 if (_winbindd_socket
!= -1) {
63 DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n",
65 close(_winbindd_socket
);
66 _winbindd_socket
= -1;
68 if (_winbindd_priv_socket
!= -1) {
69 DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n",
70 _winbindd_priv_socket
));
71 close(_winbindd_priv_socket
);
72 _winbindd_priv_socket
= -1;
76 BOOL
winbindd_init_sockets(int *public_sock
, int *priv_sock
,
77 int *idle_timeout_sec
)
79 struct smb_launch_info linfo
;
81 if (smb_launchd_checkin_names(&linfo
, "WinbindPublicPipe",
82 "WinbindPrivilegedPipe", NULL
)) {
83 if (linfo
.num_sockets
!= 2) {
84 DEBUG(0, ("invalid launchd configuration, "
85 "expected 2 sockets but got %d\n",
90 *public_sock
= _winbindd_socket
= linfo
.socket_list
[0];
91 *priv_sock
= _winbindd_priv_socket
= linfo
.socket_list
[1];
92 *idle_timeout_sec
= linfo
.idle_timeout_secs
;
94 unlink_winbindd_socket
= False
;
96 smb_launchd_checkout(&linfo
);
99 *public_sock
= open_winbindd_socket();
100 *priv_sock
= open_winbindd_priv_socket();
101 *idle_timeout_sec
= -1;
103 if (*public_sock
== -1 || *priv_sock
== -1) {
104 DEBUG(0, ("failed to open winbindd pipes: %s\n",
105 errno
? strerror(errno
) : "unknown error"));
113 void winbindd_release_sockets(void)
117 close_winbindd_socket();
119 /* Remove socket file */
120 if (unlink_winbindd_socket
) {
121 pstr_sprintf(path
, "%s/%s",
122 get_winbind_pipe_dir(), WINBINDD_SOCKET_NAME
);