0c9c854df786dd8c547a0999f5c3f87be171c94d
[tprouty/samba.git] / source3 / web / diagnose.c
1 /* 
2    Unix SMB/CIFS implementation.
3    diagnosis tools for web admin
4    Copyright (C) Andrew Tridgell 1998
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "web/swat_proto.h"
23
24 #ifdef WITH_WINBIND
25
26 extern struct in_addr loopback_ip;
27
28 NSS_STATUS winbindd_request(int req_type,
29                         struct winbindd_request *request,
30                         struct winbindd_response *response);
31
32 /* check to see if winbind is running by pinging it */
33
34 BOOL winbindd_running(void)
35 {
36         return winbind_ping();
37 }       
38 #endif
39
40 /* check to see if nmbd is running on localhost by looking for a __SAMBA__
41    response */
42 BOOL nmbd_running(void)
43 {
44         int fd, count, flags;
45         struct in_addr *ip_list;
46
47         if ((fd = open_socket_in(SOCK_DGRAM, 0, 3,
48                                  interpret_addr("127.0.0.1"), True)) != -1) {
49                 if ((ip_list = name_query(fd, "__SAMBA__", 0, 
50                                           True, True, loopback_ip,
51                                           &count, &flags, NULL)) != NULL) {
52                         SAFE_FREE(ip_list);
53                         close(fd);
54                         return True;
55                 }
56                 close (fd);
57         }
58
59         return False;
60 }
61
62
63 /* check to see if smbd is running on localhost by trying to open a connection
64    then closing it */
65 BOOL smbd_running(void)
66 {
67         static struct cli_state cli;
68
69         if (!cli_initialise(&cli))
70                 return False;
71
72         if (!cli_connect(&cli, global_myname(), &loopback_ip)) {
73                 cli_shutdown(&cli);
74                 return False;
75         }
76
77         cli_shutdown(&cli);
78         return True;
79 }