diff options
author | Andrew G. Morgan <morgan@kernel.org> | 2008-02-05 00:00:20 -0800 |
---|---|---|
committer | Andrew G. Morgan <morgan@kernel.org> | 2008-02-05 00:00:20 -0800 |
commit | e57378c88b6144ff9c06777ff0e0c9d722eeefd3 (patch) | |
tree | 24cae941d7d3e817f6fd9f86d2c68b2439ab7a00 | |
parent | d3ea8da3c1acaabf5accbec15a29919ed0170598 (diff) | |
download | libcap-e57378c88b6144ff9c06777ff0e0c9d722eeefd3.tar.gz |
We don't need to export _cap_names[] any more.
I've added perfect hash generation support for looking
up names (if you have gperf installed).
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r-- | doc/Makefile | 1 | ||||
-rw-r--r-- | doc/_cap_names.3 | 1 | ||||
-rw-r--r-- | doc/cap_from_text.3 | 13 | ||||
-rw-r--r-- | libcap/Makefile | 17 | ||||
-rw-r--r-- | libcap/_makenames.c | 4 | ||||
-rw-r--r-- | libcap/cap_text.c | 22 | ||||
-rw-r--r-- | libcap/include/sys/capability.h | 1 | ||||
-rwxr-xr-x | progs/quicktest.sh | 2 |
8 files changed, 41 insertions, 20 deletions
diff --git a/doc/Makefile b/doc/Makefile index 2c1898a..1fa270d 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -12,7 +12,6 @@ MAN3S = cap_init.3 cap_free.3 cap_dup.3 \ cap_get_file.3 cap_get_fd.3 cap_set_file.3 cap_set_fd.3 \ cap_copy_ext.3 cap_size.3 cap_copy_int.3 \ cap_from_text.3 cap_to_text.3 cap_from_name.3 cap_to_name.3 \ - _cap_names.3 \ capsetp.3 capgetp.3 MAN8S = getcap.8 setcap.8 diff --git a/doc/_cap_names.3 b/doc/_cap_names.3 deleted file mode 100644 index 83ec8b5..0000000 --- a/doc/_cap_names.3 +++ /dev/null @@ -1 +0,0 @@ -.so man3/cap_from_text.3 diff --git a/doc/cap_from_text.3 b/doc/cap_from_text.3 index cb33db5..e4a3e76 100644 --- a/doc/cap_from_text.3 +++ b/doc/cap_from_text.3 @@ -3,7 +3,7 @@ .\" .TH CAP_FROM_TEXT 3 "21th Jan 2008" "" "Linux Programmer's Manual" .SH NAME -cap_from_text, cap_to_text, cap_to_name, cap_from_name, _cap_names \- capability state textual representation translation +cap_from_text, cap_to_text, cap_to_name, cap_from_name \- capability state textual representation translation .SH SYNOPSIS .B #include <sys/capability.h> .sp @@ -14,8 +14,6 @@ cap_from_text, cap_to_text, cap_to_name, cap_from_name, _cap_names \- capability .BI "int cap_from_text(const char *" name ", cap_value_t *" cap_p ); .sp .BI "char *cap_to_text(cap_value_t " cap ); -.sp -.B extern char const *_cap_names[]; .SH USAGE .br .B cc ... -lcap @@ -85,10 +83,6 @@ converts a capability index value, .B cap , to a libcap allocated textual string. This string should be deallocated with .B "cap_free" . -.PP -.B _cap_names -is an array of textual names for capability numbers. Unnamed capabilities -have a NULL entry. (This array is not defined by POSIX.1e.) .SH "TEXTUAL REPRESENTATION" A textual representation of capability sets consists of one or more whitespace-separated @@ -171,10 +165,9 @@ or and .B cap_to_text are specified by the withdrawn POSIX.1e draft. -.B cap_from_name , -.B cap_to_name +.B cap_from_name and -.B "_cap_names" +.B cap_to_name are a Linux extension. .SH "SEE ALSO" .IR cap_clear (3), diff --git a/libcap/Makefile b/libcap/Makefile index 52927c4..fdb9ae2 100644 --- a/libcap/Makefile +++ b/libcap/Makefile @@ -16,20 +16,28 @@ INCLS=libcap.h cap_names.h $(INCS) OBJS=$(addsuffix .o, $(FILES)) MAJLIBNAME=$(LIBNAME).$(VERSION) MINLIBNAME=$(MAJLIBNAME).$(MINOR) +GPERF_OUTPUT = _caps_output.gperf LDFLAGS+=-lattr all: $(MINLIBNAME) $(STALIBNAME) +ifeq ($(shell gperf --version > /dev/null 2>&1 && echo yes),yes) +USE_GPERF_OUTPUT = $(GPERF_OUTPUT) +INCLUDE_GPERF_OUTPUT = -include $(GPERF_OUTPUT) +endif + _makenames: _makenames.c cap_names.sed $(CC) $(CFLAGS) $< -o $@ cap_names.h: _makenames ./_makenames > cap_names.h +$(GPERF_OUTPUT): cap_names.sed + sed -e 's/[\{\"]//g' -e 's/\}.*//' -e '1istruct __cap_token_s { const char *name; int index; };\n%{\nconst struct __cap_token_s *__cap_lookup_name(const char *, unsigned int);\n%}\n%%' $< | gperf --ignore-case --language=ANSI-C --readonly --null-strings --global-table --hash-function-name=__cap_hash_name --lookup-function-name="__cap_lookup_name" -c -t -m20 | indent -kr > $@ + cap_names.sed: Makefile $(KERNEL_HEADERS)/linux/capability.h @echo "=> making cap_names.c from <linux/capability.h>" - @sed -ne '/^#define[ \t]CAP[_A-Z]\+[ \t]\+[0-9]\+/{s/^#define \([^ \t]*\)[ \t]*\([^ \t]*\)/ \{ \2, \"\1\" \},/;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;p;}' < $(KERNEL_HEADERS)/linux/capability.h | fgrep -v 0x > cap_names.sed -# @sed -ne '/^#define[ \t]CAP[_A-Z]\+[ \t]\+[0-9]\+/{s/^#define CAP_\([^ \t]*\)[ \t]*\([^ \t]*\)/ \{ \2, \"\1\" \},/;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;p;}' < /usr/include/linux/capability.h | fgrep -v 0x > cap_names.sed + @sed -ne '/^#define[ \t]CAP[_A-Z]\+[ \t]\+[0-9]\+/{s/^#define \([^ \t]*\)[ \t]*\([^ \t]*\)/\{\"\1\",\2\},/;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;p;}' < $(KERNEL_HEADERS)/linux/capability.h | fgrep -v 0x > $@ $(STALIBNAME): $(OBJS) ar rcs $(STALIBNAME) $(OBJS) @@ -43,6 +51,9 @@ $(MINLIBNAME): $(OBJS) %.o: %.c $(INCLS) $(CC) $(CFLAGS) -c $< -o $@ +cap_text.o: cap_text.c $(USE_GPERF_OUTPUT) + $(CC) $(CFLAGS) $(INCLUDE_GPERF_OUTPUT) -c $< -o $@ + install: all mkdir -p -m 0755 $(INCDIR)/sys install -m 0644 include/sys/capability.h $(INCDIR)/sys @@ -56,5 +67,5 @@ install: all clean: $(LOCALCLEAN) rm -f $(OBJS) $(LIBNAME)* $(STALIBNAME) - rm -f cap_names.h cap_names.sed _makenames + rm -f cap_names.h cap_names.sed _makenames $(GPERF_OUTPUT) cd include/sys && $(LOCALCLEAN) diff --git a/libcap/_makenames.c b/libcap/_makenames.c index 212f0b4..4e8939e 100644 --- a/libcap/_makenames.c +++ b/libcap/_makenames.c @@ -14,11 +14,11 @@ */ struct { - int index; const char *name; + int index; } const list[] = { #include "cap_names.sed" - {-1, NULL} + {NULL, -1} }; /* this should be more than big enough (factor of three at least) */ diff --git a/libcap/cap_text.c b/libcap/cap_text.c index 8c78977..6874153 100644 --- a/libcap/cap_text.c +++ b/libcap/cap_text.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997-8,2007 Andrew G Morgan <morgan@kernel.org> + * Copyright (c) 1997-8,2007-8 Andrew G Morgan <morgan@kernel.org> * Copyright (c) 1997 Andrew Main <zefram@dcs.warwick.ac.uk> * * This file deals with exchanging internal and textual @@ -77,6 +77,22 @@ static int lookupname(char const **strp) *strp = str.constp; return n; } else { +#ifdef GPERF_DOWNCASE + const struct __cap_token_s *token_info; + int c; + unsigned len; + + for (len=0; (c = str.constp[len]); ++len) { + if (!(isalpha(c) || (c == '_'))) { + break; + } + } + token_info = __cap_lookup_name(str.constp, len); + if (token_info != NULL) { + *strp = str.constp + len; + return token_info->index; + } +#else /* ie., ndef GPERF_DOWNCASE */ char const *s; int n; for (n = __CAP_BITS; n--; ) @@ -84,7 +100,9 @@ static int lookupname(char const **strp) *strp = s; return n; } - return -1; +#endif /* def GPERF_DOWNCASE */ + + return -1; /* No definition available */ } } diff --git a/libcap/include/sys/capability.h b/libcap/include/sys/capability.h index 0e4ba37..72964e4 100644 --- a/libcap/include/sys/capability.h +++ b/libcap/include/sys/capability.h @@ -111,7 +111,6 @@ extern int capset(cap_user_header_t header, cap_user_data_t data); extern int capget(cap_user_header_t header, const cap_user_data_t data); extern int capgetp(pid_t pid, cap_t cap_d); extern int capsetp(pid_t pid, cap_t cap_d); -extern char const *_cap_names[]; #ifdef __cplusplus } diff --git a/progs/quicktest.sh b/progs/quicktest.sh index 47d2800..bf0dc08 100755 --- a/progs/quicktest.sh +++ b/progs/quicktest.sh @@ -67,3 +67,5 @@ fail_capsh --drop=cap_net_raw,cap_chown --secbits=0x2f --print -- -c "./ping -c1 pass_capsh --secbits=47 --inh=cap_net_raw --drop=cap_net_raw \ --uid=500 --print -- -c "./ping -c1 localhost" + +rm -f ./ping |