]>
git.ipfire.org Git - pakfire.git/blob - src/_pakfire/capabilities.c
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
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 3 of the License, or #
9 # (at your option) any later version. #
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. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
24 #include <sys/capability.h>
26 #include "constants.h"
29 get_capabilities(PyObject
*self
, PyObject
*args
) {
32 char exception
[STRING_SIZE
];
34 if (!PyArg_ParseTuple(args
, "s", &filename
)) {
35 /* XXX raise exception */
39 cap_d
= cap_get_file(filename
);
41 if (errno
== EOPNOTSUPP
) {
42 /* Return nothing, if the operation is not supported. */
44 } else if (errno
!= ENODATA
) {
45 snprintf(exception
, STRING_SIZE
- 1, "Failed to get capabilities of file %s (%s).",
46 filename
, strerror(errno
));
47 PyErr_SetString(PyExc_RuntimeError
, exception
);
53 char *result
= cap_to_text(cap_d
, NULL
);
57 snprintf(exception
, STRING_SIZE
- 1, "Failed to get capabilities of human readable format at %s (%s).",
58 filename
, strerror(errno
));
59 PyErr_SetString(PyExc_RuntimeError
, exception
);
63 // Remove leading two characters '= '.
65 for (i
= 0; i
< 2; i
++) {
69 PyObject
* ret
= Py_BuildValue("s", result
);
76 set_capabilities(PyObject
*self
, PyObject
*args
) {
79 char *exception
= NULL
;
80 char buf
[STRING_SIZE
];
84 if (!PyArg_ParseTuple(args
, "ss", &filename
, &input
)) {
85 /* XXX raise exception */
89 snprintf(buf
, STRING_SIZE
- 1, "= %s", input
);
90 cap_d
= cap_from_text(buf
);
92 PyErr_SetString(PyExc_ValueError
, "Could not read capability string.");
96 ret
= cap_set_file(filename
, cap_d
);
100 snprintf(exception
, STRING_SIZE
- 1, "Failed to set capabilities on file %s (%s).",
101 filename
, strerror(errno
));
102 PyErr_SetString(PyExc_RuntimeError
, exception
);
106 return Py_BuildValue("i", ret
);