summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTim Shimmin <tes@sgi.com>2002-02-27 04:56:14 +0000
committerTim Shimmin <tes@sgi.com>2002-02-27 04:56:14 +0000
commitaf8b9642aa944774812e75e7dbbfbc8cc0fb8329 (patch)
tree1aa761e20cbe17cb02e2392dd2269729dd667d91 /examples
parent17739126bd1d906edd0470a422161b19d335d5be (diff)
downloadacl-af8b9642aa944774812e75e7dbbfbc8cc0fb8329.tar.gz
merging in many of Andreas changes
Merge of xfs-cmds-2.4.18:slinx:112840a by nathans.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile41
-rw-r--r--examples/Makefile.examples10
-rw-r--r--examples/README12
-rw-r--r--examples/copy-acl.c53
-rw-r--r--examples/get-acl.c74
-rw-r--r--examples/set-acl.c47
6 files changed, 237 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000..899d18b
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 2001 Silicon Graphics, Inc. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Further, this software is distributed without any warranty that it is
+# free of the rightful claim of any third person regarding infringement
+# or the like. Any license provided herein, whether implied or
+# otherwise, applies only to this software file. Patent licenses, if
+# any, provided herein do not apply to combinations of this program with
+# other software, or any other product whatsoever.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston MA 02111-1307, USA.
+#
+# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+# Mountain View, CA 94043, or:
+#
+# http://www.sgi.com
+#
+# For further information regarding this notice, see:
+#
+# http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+#
+
+TOPDIR = ..
+include $(TOPDIR)/include/builddefs
+
+LSRCFILES = README Makefile.examples get-acl.c set-acl.c copy-acl.c
+LDIRT = get-acl set-acl copy-acl
+
+include $(BUILDRULES)
+
+default install install-dev install-lib:
diff --git a/examples/Makefile.examples b/examples/Makefile.examples
new file mode 100644
index 0000000..c6e73b3
--- /dev/null
+++ b/examples/Makefile.examples
@@ -0,0 +1,10 @@
+CFLAGS = -g -Wall
+LDFLAGS = -lacl
+
+PROGS = get-acl copy-acl set-acl
+
+all: $(PROGS)
+
+clean:
+ rm -f $(PROGS)
+
diff --git a/examples/README b/examples/README
new file mode 100644
index 0000000..09a3678
--- /dev/null
+++ b/examples/README
@@ -0,0 +1,12 @@
+Simple examples using libacl
+============================
+
+This directory contains very simple examples of how to use the acl
+library. After installing the acl library on your system, you can
+build the examples by typing the following command in this directory:
+
+ make -f Makefile.examples
+
+
+ --Andreas Gruenbacher.
+
diff --git a/examples/copy-acl.c b/examples/copy-acl.c
new file mode 100644
index 0000000..d9a7cc4
--- /dev/null
+++ b/examples/copy-acl.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <libgen.h>
+#include <sys/acl.h>
+
+const char *progname;
+
+int main(int argc, char *argv[])
+{
+ acl_t acl, default_acl;
+ int n, ret = 0;
+
+ progname = basename(argv[0]);
+
+ if (argc < 3) {
+ printf("%s -- copy access control lists between files \n"
+ "Usage: %s file1 file2 ...\n",
+ progname, progname);
+ return 1;
+ }
+
+ acl = acl_get_file(argv[1], ACL_TYPE_ACCESS);
+ if (acl == NULL) {
+ fprintf(stderr, "%s: getting acl of %s: %s\n",
+ progname, argv[1], strerror(errno));
+ return 1;
+ }
+ default_acl = acl_get_file(argv[1], ACL_TYPE_DEFAULT);
+ if (default_acl == NULL) {
+ fprintf(stderr, "%s: getting default acl of %s: %s\n",
+ progname, argv[1], strerror(errno));
+ return 1;
+ }
+
+ for (n = 2; n < argc; n++) {
+ if (acl_set_file(argv[n], ACL_TYPE_ACCESS, acl) != 0) {
+ fprintf(stderr, "%s: setting acl for %s: %s\n",
+ progname, argv[n], strerror(errno));
+ ret = 1;
+ } else if (acl_set_file(argv[n], ACL_TYPE_DEFAULT,
+ default_acl) != 0) {
+ fprintf(stderr, "%s: setting default acl for %s: %s\n",
+ progname, argv[n], strerror(errno));
+ ret = 1;
+ }
+ }
+
+ acl_free(acl);
+ acl_free(default_acl);
+
+ return ret;
+}
diff --git a/examples/get-acl.c b/examples/get-acl.c
new file mode 100644
index 0000000..fdcc68e
--- /dev/null
+++ b/examples/get-acl.c
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <libgen.h>
+#include <sys/stat.h>
+#include <sys/acl.h>
+
+const char *progname;
+
+int main(int argc, char *argv[])
+{
+ int n, ret = 0;
+
+ progname = basename(argv[0]);
+
+ if (argc == 1) {
+ printf("%s -- get access control lists of files\n"
+ "Usage: %s file ...\n",
+ progname, progname);
+ return 1;
+ }
+
+ for (n = 1; n < argc; n++) {
+ struct stat st;
+ acl_t acl, default_acl;
+ char *acl_text, *default_acl_text, *token;
+
+ if (stat(argv[n], &st) != 0) {
+ fprintf(stderr, "%s: %s: %s\n",
+ progname, argv[n], strerror(errno));
+ ret = 1;
+ continue;
+ }
+
+ acl = acl_get_file(argv[n], ACL_TYPE_ACCESS);
+ if (acl == NULL) {
+ fprintf(stderr, "%s: getting acl of %s: %s\n",
+ progname, argv[n], strerror(errno));
+ ret = 1;
+ continue;
+ }
+ acl_text = acl_to_text(acl, NULL);
+ acl_free(acl);
+
+ default_acl = acl_get_file(argv[n], ACL_TYPE_DEFAULT);
+ if (default_acl == NULL) {
+ acl_free(acl_text);
+ fprintf(stderr, "%s: getting default acl of %s: %s\n",
+ progname, argv[n], strerror(errno));
+ ret = 1;
+ continue;
+ }
+ default_acl_text = acl_to_text(default_acl, NULL);
+ acl_free(default_acl);
+
+ printf("# file: %s\n"
+ "# owner: %d\n"
+ "# group: %d\n"
+ "%s",
+ argv[n], st.st_uid, st.st_gid, acl_text);
+
+ token = strtok(default_acl_text, "\n");
+ while (token) {
+ printf("default:%s\n", token);
+ token = strtok(NULL, "\n");
+ }
+ printf("\n");
+
+ acl_free(acl_text);
+ acl_free(default_acl_text);
+ }
+ return ret;
+}
+
diff --git a/examples/set-acl.c b/examples/set-acl.c
new file mode 100644
index 0000000..95c4ee9
--- /dev/null
+++ b/examples/set-acl.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <libgen.h>
+#include <sys/acl.h>
+
+const char *progname;
+
+int main(int argc, char *argv[])
+{
+ acl_t acl;
+ int n, ret = 0;
+
+ progname = basename(argv[0]);
+
+ if (argc < 3) {
+ printf("%s -- set access control list of files\n"
+ "Usage: %s acl file ...\n",
+ progname, progname);
+ return 1;
+ }
+
+ acl = acl_from_text(argv[1]);
+ if (!acl) {
+ fprintf(stderr, "%s: `%s': %s\n",
+ progname, argv[1], strerror(errno));
+ return 1;
+ }
+ if (acl_valid(acl) != 0) {
+ fprintf(stderr, "%s: `%s': invalid/incomplete acl\n",
+ progname, argv[1]);
+ acl_free(acl);
+ return 1;
+ }
+
+ for (n = 2; n < argc; n++) {
+ if (acl_set_file(argv[n], ACL_TYPE_ACCESS, acl) != 0) {
+ fprintf(stderr, "%s: setting acl of %s: %s\n",
+ progname, argv[n], strerror(errno));
+ ret = 1;
+ }
+ }
+
+ acl_free(acl);
+
+ return ret;
+}