Home | History | Annotate | Download | only in acls
      1 #include <unistd.h>
      2 #include <stdio.h>
      3 #include <sys/types.h>
      4 #include <errno.h>
      5 #include <sys/syscall.h>
      6 #include <fcntl.h>
      7 #include <sys/xattr.h>
      8 #include <string.h>
      9 
     10 int main(int argc, char *argv[])
     11 {
     12 	ssize_t s;
     13 	char *tok;
     14 	char value[1024];
     15 	char list[1024];
     16 	int rc = 0;
     17 	char *file;
     18 	int fd;
     19 
     20 	if (argc < 2) {
     21 		printf("Please enter a file name as argument.\n");
     22 		return -1;
     23 	}
     24 
     25 	file = argv[1];
     26 
     27 	fd = open(file, O_RDONLY);
     28 	if (fd < 0) {
     29 		printf("Unable to open file %s !", file);
     30 		return -1;
     31 	}
     32 
     33 	if (-1 == (s = flistxattr(fd, list, 1024))) {
     34 		perror("flistxattr");
     35 		return 1;
     36 	}
     37 	if (s == 0) {
     38 		printf("No xattrs defined for %s, further testcase useless\n",
     39 		       file);
     40 		return 1;
     41 	}
     42 	tok = strtok(list, "\0");
     43 	s = fgetxattr(fd, tok, (void *)value, 1024);
     44 	if (s == -1) {
     45 		perror("fgetxattr");
     46 		return 1;
     47 	}
     48 	s = fsetxattr(fd, tok, (void *)value, s, 0);
     49 
     50 	if (s == -1) {
     51 		printf
     52 		    ("User unable to change extended attributes on file %s !\n",
     53 		     argv[1]);
     54 		printf("errno = %i\n", errno);
     55 		rc = 1;
     56 	}
     57 	//s = syscall(237, fd,tok); //fremovexattr
     58 #ifdef __NR_fremovexattr
     59 	s = syscall(__NR_fremovexattr, fd, tok);	//fremovexattr
     60 #else
     61 	s = -1;
     62 	errno = ENOSYS;
     63 #endif
     64 	if (s == -1) {
     65 		printf("User unable to remove extended attributes file %s !\n",
     66 		       argv[1]);
     67 		printf("errno = %i\n", errno);
     68 		rc = 1;
     69 	}
     70 
     71 	close(fd);
     72 	return rc;
     73 }
     74