r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / nsswitch / winbindd_sockinit.c
bloba1ae476883910d4e69ae09edf8d19a91bbf21aa0
1 /*
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "winbindd.h"
24 #include "smb_launchd.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_WINBIND
29 /* Open the winbindd socket */
31 static int _winbindd_socket = -1;
32 static int _winbindd_priv_socket = -1;
33 static BOOL unlink_winbindd_socket = True;
35 static int open_winbindd_socket(void)
37 if (_winbindd_socket == -1) {
38 _winbindd_socket = create_pipe_sock(
39 WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME, 0755);
40 DEBUG(10, ("open_winbindd_socket: opened socket fd %d\n",
41 _winbindd_socket));
44 return _winbindd_socket;
47 static int open_winbindd_priv_socket(void)
49 if (_winbindd_priv_socket == -1) {
50 _winbindd_priv_socket = create_pipe_sock(
51 get_winbind_priv_pipe_dir(), WINBINDD_SOCKET_NAME, 0750);
52 DEBUG(10, ("open_winbindd_priv_socket: opened socket fd %d\n",
53 _winbindd_priv_socket));
56 return _winbindd_priv_socket;
59 /* Close the winbindd socket */
61 static void close_winbindd_socket(void)
63 if (_winbindd_socket != -1) {
64 DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n",
65 _winbindd_socket));
66 close(_winbindd_socket);
67 _winbindd_socket = -1;
69 if (_winbindd_priv_socket != -1) {
70 DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n",
71 _winbindd_priv_socket));
72 close(_winbindd_priv_socket);
73 _winbindd_priv_socket = -1;
77 BOOL winbindd_init_sockets(int *public_sock, int *priv_sock,
78 int *idle_timeout_sec)
80 struct smb_launch_info linfo;
82 if (smb_launchd_checkin_names(&linfo, "WinbindPublicPipe",
83 "WinbindPrivilegedPipe", NULL)) {
84 if (linfo.num_sockets != 2) {
85 DEBUG(0, ("invalid launchd configuration, "
86 "expected 2 sockets but got %d\n",
87 linfo.num_sockets));
88 return False;
91 *public_sock = _winbindd_socket = linfo.socket_list[0];
92 *priv_sock = _winbindd_priv_socket = linfo.socket_list[1];
93 *idle_timeout_sec = linfo.idle_timeout_secs;
95 unlink_winbindd_socket = False;
97 smb_launchd_checkout(&linfo);
98 return True;
99 } else {
100 *public_sock = open_winbindd_socket();
101 *priv_sock = open_winbindd_priv_socket();
102 *idle_timeout_sec = -1;
104 if (*public_sock == -1 || *priv_sock == -1) {
105 DEBUG(0, ("failed to open winbindd pipes: %s\n",
106 errno ? strerror(errno) : "unknown error"));
107 return False;
110 return True;
114 void winbindd_release_sockets(void)
116 pstring path;
118 close_winbindd_socket();
120 /* Remove socket file */
121 if (unlink_winbindd_socket) {
122 pstr_sprintf(path, "%s/%s",
123 WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
124 unlink(path);