|
1 // cap.c - POSIX.1e (POSIX.6) capability set manipulation |
|
2 // |
|
3 // © Portions Copyright (c) Symbian Software Ltd 2007. All rights reserved. |
|
4 // |
|
5 /* |
|
6 * This file is part of zsh, the Z shell. |
|
7 * |
|
8 * Copyright (c) 1997 Andrew Main |
|
9 * All rights reserved. |
|
10 * |
|
11 * Permission is hereby granted, without written agreement and without |
|
12 * license or royalty fees, to use, copy, modify, and distribute this |
|
13 * software and to distribute modified versions of this software for any |
|
14 * purpose, provided that the above copyright notice and the following |
|
15 * two paragraphs appear in all copies of this software. |
|
16 * |
|
17 * In no event shall Andrew Main or the Zsh Development Group be liable |
|
18 * to any party for direct, indirect, special, incidental, or consequential |
|
19 * damages arising out of the use of this software and its documentation, |
|
20 * even if Andrew Main and the Zsh Development Group have been advised of |
|
21 * the possibility of such damage. |
|
22 * |
|
23 * Andrew Main and the Zsh Development Group specifically disclaim any |
|
24 * warranties, including, but not limited to, the implied warranties of |
|
25 * merchantability and fitness for a particular purpose. The software |
|
26 * provided hereunder is on an "as is" basis, and Andrew Main and the |
|
27 * Zsh Development Group have no obligation to provide maintenance, |
|
28 * support, updates, enhancements, or modifications. |
|
29 * |
|
30 */ |
|
31 #include "cap.mdh" |
|
32 #include "cap.pro" |
|
33 |
|
34 #ifdef __SYMBIAN32__ |
|
35 #ifdef __WINSCW__ |
|
36 #pragma warn_unusedarg off |
|
37 #endif//__WINSCW__ |
|
38 #endif//__SYMBIAN32__ |
|
39 |
|
40 #ifdef HAVE_CAP_GET_PROC |
|
41 |
|
42 static int |
|
43 bin_cap(char *nam, char **argv, Options ops, int func) |
|
44 { |
|
45 int ret = 0; |
|
46 cap_t caps; |
|
47 if(*argv) { |
|
48 caps = cap_from_text(*argv); |
|
49 if(!caps) { |
|
50 zwarnnam(nam, "invalid capability string", NULL, 0); |
|
51 return 1; |
|
52 } |
|
53 if(cap_set_proc(caps)) { |
|
54 zwarnnam(nam, "can't change capabilites: %e", NULL, errno); |
|
55 ret = 1; |
|
56 } |
|
57 } else { |
|
58 char *result = NULL; |
|
59 ssize_t length; |
|
60 caps = cap_get_proc(); |
|
61 if(caps) |
|
62 result = cap_to_text(caps, &length); |
|
63 if(!caps || !result) { |
|
64 zwarnnam(nam, "can't get capabilites: %e", NULL, errno); |
|
65 ret = 1; |
|
66 } else |
|
67 puts(result); |
|
68 } |
|
69 cap_free(caps); |
|
70 return ret; |
|
71 } |
|
72 |
|
73 static int |
|
74 bin_getcap(char *nam, char **argv, Options ops, int func) |
|
75 { |
|
76 int ret = 0; |
|
77 |
|
78 do { |
|
79 char *result = NULL; |
|
80 ssize_t length; |
|
81 cap_t caps = cap_get_file(*argv); |
|
82 if(caps) |
|
83 result = cap_to_text(caps, &length); |
|
84 if (!caps || !result) { |
|
85 zwarnnam(nam, "%s: %e", *argv, errno); |
|
86 ret = 1; |
|
87 } else |
|
88 printf("%s %s\n", *argv, result); |
|
89 cap_free(caps); |
|
90 } while(*++argv); |
|
91 return ret; |
|
92 } |
|
93 |
|
94 static int |
|
95 bin_setcap(char *nam, char **argv, Options ops, int func) |
|
96 { |
|
97 cap_t caps; |
|
98 int ret = 0; |
|
99 |
|
100 caps = cap_from_text(*argv++); |
|
101 if(!caps) { |
|
102 zwarnnam(nam, "invalid capability string", NULL, 0); |
|
103 return 1; |
|
104 } |
|
105 |
|
106 do { |
|
107 if(cap_set_file(*argv, caps)) { |
|
108 zwarnnam(nam, "%s: %e", *argv, errno); |
|
109 ret = 1; |
|
110 } |
|
111 } while(*++argv); |
|
112 cap_free(caps); |
|
113 return ret; |
|
114 } |
|
115 |
|
116 #else /* !HAVE_CAP_GET_PROC */ |
|
117 |
|
118 # define bin_cap bin_notavail |
|
119 # define bin_getcap bin_notavail |
|
120 # define bin_setcap bin_notavail |
|
121 |
|
122 #endif /* !HAVE_CAP_GET_PROC */ |
|
123 |
|
124 /* module paraphernalia */ |
|
125 |
|
126 static struct builtin bintab[] = { |
|
127 BUILTIN("cap", 0, bin_cap, 0, 1, 0, NULL, NULL), |
|
128 BUILTIN("getcap", 0, bin_getcap, 1, -1, 0, NULL, NULL), |
|
129 BUILTIN("setcap", 0, bin_setcap, 2, -1, 0, NULL, NULL), |
|
130 }; |
|
131 |
|
132 /**/ |
|
133 int |
|
134 setup_(UNUSED(Module m)) |
|
135 { |
|
136 return 0; |
|
137 } |
|
138 |
|
139 /**/ |
|
140 int |
|
141 boot_(Module m) |
|
142 { |
|
143 return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); |
|
144 } |
|
145 |
|
146 /**/ |
|
147 int |
|
148 cleanup_(Module m) |
|
149 { |
|
150 deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); |
|
151 return 0; |
|
152 } |
|
153 |
|
154 /**/ |
|
155 int |
|
156 finish_(UNUSED(Module m)) |
|
157 { |
|
158 return 0; |
|
159 } |