r13840: Mark some functions as public.
[samba.git] / source4 / lib / util / capability.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Jeremy Allison 1998-2002
6    
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.
11    
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.
16    
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.
20 */
21
22 /**
23  * @file
24  * @brief Capabilities functions
25  **/
26
27 /*
28   capabilities fns - will be needed when we enable kernel oplocks
29 */
30
31 #include "includes.h"
32 #include "system/network.h"
33 #include "system/wait.h"
34 #include "system/filesys.h"
35
36
37 #if defined(HAVE_IRIX_SPECIFIC_CAPABILITIES)
38 /**************************************************************************
39  Try and abstract process capabilities (for systems that have them).
40 ****************************************************************************/
41 static BOOL set_process_capability( uint32_t cap_flag, BOOL enable )
42 {
43         if(cap_flag == KERNEL_OPLOCK_CAPABILITY) {
44                 cap_t cap = cap_get_proc();
45
46                 if (cap == NULL) {
47                         DEBUG(0,("set_process_capability: cap_get_proc failed. Error was %s\n",
48                                 strerror(errno)));
49                         return False;
50                 }
51
52                 if(enable)
53                         cap->cap_effective |= CAP_NETWORK_MGT;
54                 else
55                         cap->cap_effective &= ~CAP_NETWORK_MGT;
56
57                 if (cap_set_proc(cap) == -1) {
58                         DEBUG(0,("set_process_capability: cap_set_proc failed. Error was %s\n",
59                                 strerror(errno)));
60                         cap_free(cap);
61                         return False;
62                 }
63
64                 cap_free(cap);
65
66                 DEBUG(10,("set_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n"));
67         }
68         return True;
69 }
70
71 /**************************************************************************
72  Try and abstract inherited process capabilities (for systems that have them).
73 ****************************************************************************/
74
75 static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable )
76 {
77         if(cap_flag == KERNEL_OPLOCK_CAPABILITY) {
78                 cap_t cap = cap_get_proc();
79
80                 if (cap == NULL) {
81                         DEBUG(0,("set_inherited_process_capability: cap_get_proc failed. Error was %s\n",
82                                 strerror(errno)));
83                         return False;
84                 }
85
86                 if(enable)
87                         cap->cap_inheritable |= CAP_NETWORK_MGT;
88                 else
89                         cap->cap_inheritable &= ~CAP_NETWORK_MGT;
90
91                 if (cap_set_proc(cap) == -1) {
92                         DEBUG(0,("set_inherited_process_capability: cap_set_proc failed. Error was %s\n", 
93                                 strerror(errno)));
94                         cap_free(cap);
95                         return False;
96                 }
97
98                 cap_free(cap);
99
100                 DEBUG(10,("set_inherited_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n"));
101         }
102         return True;
103 }
104 #endif
105
106 /****************************************************************************
107  Gain the oplock capability from the kernel if possible.
108 ****************************************************************************/
109
110 _PUBLIC_ void oplock_set_capability(BOOL this_process, BOOL inherit)
111 {
112 #if HAVE_KERNEL_OPLOCKS_IRIX
113         set_process_capability(KERNEL_OPLOCK_CAPABILITY,this_process);
114         set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY,inherit);
115 #endif
116 }
117