-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht_cap_set_file.c
41 lines (32 loc) · 1.38 KB
/
t_cap_set_file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2024. *
* *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation, either version 3 or (at your option) any *
* later version. This program is distributed without any warranty. See *
* the file COPYING.gpl-v3 for details. *
\*************************************************************************/
/* Supplementary program for Chapter 39 */
#include <sys/capability.h>
#include "tlpi_hdr.h"
int
main(int argc, char *argv[])
{
if (argc != 3) {
fprintf(stderr, "%s <textual-cap-set> <pathname>\n", argv[0]);
exit(EXIT_FAILURE);
}
cap_t capSets = cap_from_text(argv[1]);
if (capSets == NULL)
errExit("cap_from_text");
char *textCaps = cap_to_text(capSets, NULL);
if (textCaps == NULL)
errExit("cap_to_text");
printf("caps_to_text() returned \"%s\"\n\n", textCaps);
if (cap_set_file(argv[2], capSets) == -1)
errExit("cap_set_file");
if (cap_free(textCaps) != 0 || cap_free(capSets) != 0)
errExit("cap_free");
exit(EXIT_SUCCESS);
}