[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

system/1561: cap_mkdb is badly broken




>Number:         1561
>Category:       system
>Synopsis:       cap_mkdb is badly broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 13 07:50:02 MST 2000
>Last-Modified:
>Originator:     Rémi Guyomarch
>Organization:
net
>Release:        2.8
>Environment:
	
	System      : OpenBSD 2.8
	Architecture: OpenBSD.i386
	Machine     : i386
>Description:
	Most of the time, cap_mkdb silently produce empty databases from
valid input files. Sometimes this can render the system totaly unusuable.
>How-To-Repeat:
	(the 'cap_mkdb' binary used here was extracted straight from base28.tgz)
	(the 'login.conf' text file was extracted from etc28.tgz)


	First, out of a perfectly valid file, cap_mkdb with its simplest syntax
	produce an empty database. Note that copying the login.conf.db in
	/etc will block any login attempt, even at the console.

	root@satanas ~/src/x # l
	total 3
	1 drwxr-xr-x  2 root  wheel   512 Dec 13 14:00 ./
	1 drwxr-xr-x  6 root  wheel  1024 Dec 13 12:05 ../
	1 -rw-r--r--  1 root  wheel   989 Nov  6 17:56 login.conf
	root@satanas ~/src/x # cap_mkdb login.conf
	root@satanas ~/src/x # l
	total 19
	 1 drwxr-xr-x  2 root  wheel    512 Dec 13 14:20 ./
	 1 drwxr-xr-x  6 root  wheel   1024 Dec 13 12:05 ../
	 1 -rw-r--r--  1 root  wheel    989 Nov  6 17:56 login.conf
	16 -rw-r--r--  1 root  wheel  73728 Dec 13 14:19 login.conf.db
	root@satanas ~/src/x # file login.conf.db
	login.conf.db: Berkeley DB Hash file (Version 2, Little Endian, Bucket Size 4096,
	Bucket Shift 12, Directory Size 256, Segment Size 256, Segment Shift 8, Overflow
	Point 4, Last Freed 2, Max Bucket 15, High Mask 0x1f, Low Mask 0xf, Fill Factor
	16, Number of Keys 0)
	    ^^^^^^^^^^^^^^^^


	Now, let's try with the '-f' option, redirecting the output to an
	alternate file. This time it works :
  
	root@satanas ~/src/x # rm login.conf.db
	remove login.conf.db? y
	root@satanas ~/src/x # cap_mkdb -v -f foo login.conf
	cap_mkdb: 3 capability records
	root@satanas ~/src/x # l
	total 35
	 1 drwxr-xr-x  2 root  wheel    512 Dec 13 14:26 ./
	 1 drwxr-xr-x  6 root  wheel   1024 Dec 13 12:05 ../
	32 -rw-r--r--  1 root  wheel  73728 Dec 13 14:26 foo.db
	 1 -rw-r--r--  1 root  wheel    989 Nov  6 17:56 login.conf
	root@satanas ~/src/x # file foo.db
	foo.db: Berkeley DB Hash file (Version 2, Little Endian, Bucket Size 4096, Bucket
	Shift 12, Directory Size 256, Segment Size 256, Segment Shift 8, Overflow Point
	4, Last Freed 2, Max Bucket 15, High Mask 0x1f, Low Mask 0xf, Fill Factor 16,
	Number of Keys 3)
	^^^^^^^^^^^^^^^^^


	For even more fun, let's try another thing. If there's an existing
	.db database with the same base name, 'cap_mkdb' will fail with and
	without the '-f' option :
	(this means you can't update an existing .db file)
	
	root@satanas ~/src/x # rm foo.db
	remove foo.db? y
	root@satanas ~/src/x # cap_mkdb -v login.conf
	cap_mkdb: 0 capability records
	root@satanas ~/src/x # l
	total 19
	 1 drwxr-xr-x  2 root  wheel    512 Dec 13 14:28 ./
	 1 drwxr-xr-x  6 root  wheel   1024 Dec 13 12:05 ../
	 1 -rw-r--r--  1 root  wheel    989 Nov  6 17:56 login.conf
	16 -rw-r--r--  1 root  wheel  73728 Dec 13 14:28 login.conf.db
	root@satanas ~/src/x # cap_mkdb -v -f foo login.conf
	cap_mkdb: 0 capability records
	root@satanas ~/src/x # l
	total 35
	 1 drwxr-xr-x  2 root  wheel    512 Dec 13 14:28 ./
	 1 drwxr-xr-x  6 root  wheel   1024 Dec 13 12:05 ../
	16 -rw-r--r--  1 root  wheel  73728 Dec 13 14:28 foo.db
	 1 -rw-r--r--  1 root  wheel    989 Nov  6 17:56 login.conf
	16 -rw-r--r--  1 root  wheel  73728 Dec 13 14:28 login.conf.db
	root@satanas ~/src/x # file login.conf.db foo.db
	login.conf.db: Berkeley DB Hash file (Version 2, Little Endian, Bucket Size
	4096, Bucket Shift 12, Directory Size 256, Segment Size 256, Segment Shift 8,
	Overflow Point 4, Last Freed 2, Max Bucket 15, High Mask 0x1f, Low Mask 0xf,
	Fill Factor 16, Number of Keys 0)
	                ^^^^^^^^^^^^^^^^
	
	foo.db:        Berkeley DB Hash file (Version 2, Little Endian, Bucket Size
	4096, Bucket Shift 12, Directory Size 256, Segment Size 256, Segment Shift 8,
	Overflow Point 4, Last Freed 2, Max Bucket 15, High Mask 0x1f, Low Mask 0xf,
	Fill Factor 16, Number of Keys 0)
	                ^^^^^^^^^^^^^^^^^
	

>Fix:
	Rewrite cap_mkdb

>Audit-Trail:
>Unformatted: