Commit graph

114 commits

Author SHA1 Message Date
kay.sievers@vrfy.org e964c2c05d [PATCH] udev - safer string handling - part three
Here we truncate our input strings from the environment to our
defined limit. It's a bit theroretical but better check for it.

It cleans up some magic length definitions and removes the code
duplication in udev, udevtest and udevsend.

udevd needs to be killed after installation, cause the message size
is changed with this patch.
Should we do this with the 'make install', like we do with the '.udevdb'?
2005-04-26 21:32:30 -07:00
kay.sievers@vrfy.org 831f800da3 [PATCH] udev - safer string handling - part two
As promised, here is the next round. We provide in addition to the
already used macros:

  strfieldcpy(to, from)
  strfieldcat(to, from)

the corresponding friends, if the size of the target is not known and
must be provided by the caller:

  strnfieldcpy(to, from, maxsize)
  strnfieldcat(to, from, maxsize)

and switch nearly all possibly unsafe users of strcat(), strncat(),
strcpy() and strncpy() to these safer macros.

The last known remaining issue seems the use of sprintf() and
snprintf(). I will take on it later today or tomorrow.
2005-04-26 21:32:30 -07:00
kay.sievers@vrfy.org c472e3c89b [PATCH] udev - safer string handling all over the place
On Tue, Feb 24, 2004 at 11:50:52PM +0100, Kay Sievers wrote:
> Here is the first step towards a safer string handling.
> More will follow, but for now only the easy ones :)
>
> Thanks to all who pointed this out. strncat() isn't a nice function. We
> all should remember that the destination string is not terminated if the
> given lenght is shorter than the strlen of the source string.
>
> And shame on the various implementers of strfieldcat() I found in the
> unapplied patches on this list, it's not really better than strncpy()
> and hides the real problem.

Hmm, bk didn't checked in one file, maybe I edited it again as root.
Nevermind, here is the more complete version.
2005-04-26 21:32:30 -07:00
greg@kroah.com c80da5085f [PATCH] force udev to include the internal version of libsysfs and never the external one.
Should fix some more build bugs...
2005-04-26 21:32:29 -07:00
patmans@us.ibm.com 0bad3406c1 [PATCH] udev use new libsysfs header file location
Use the new location of libsysfs header files.
2005-04-26 21:32:29 -07:00
greg@kroah.com 961e47847c [PATCH] add support for UDEV_NO_SLEEP env variable so Gentoo people will be happy.
Actually, I'm happy to, startup time is much smaller...
2005-04-26 21:32:28 -07:00
kay.sievers@vrfy.org 88f09368b3 [PATCH] udev - switch callout part selector to {attribute}
Here we change the magic callout part number selector to the new
atribute syntax. The syntax to select the second part of the callout string:

 '%2c' is now '%c{2}'

I think it's more clear and we no longer misuse the length argument.

The old syntax is still supported, but we should remove it some
time in the future.
2005-04-26 21:32:28 -07:00
kay.sievers@vrfy.org 50e5de03d1 [PATCH] udev - create all partitions of blockdevice
Here is the first try to create all partitons of a blockdevice, since
removable media devices may need to acces the expected partition to
revalidate the media.

It uses the attribute syntax introduced with the last %s{file} patch.
I'm using this with my multi-slot-flash-card-reader:

  SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia"
  SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash"
  SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick"
  SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia"

and I get:

  tree /udev/
  /udev/
  |-- memorystick
  |-- memorystick1
  |-- memorystick10
  |-- memorystick11
  |-- memorystick12
  |-- memorystick13
  |-- memorystick14
  |-- memorystick15
  |-- memorystick2
  |-- memorystick3
  |-- memorystick4
  |-- memorystick5
  |-- memorystick6
  |-- memorystick7
  |-- memorystick8
  |-- memorystick9
  |-- multimedia
  |-- multimedia1
  |-- multimedia10
  |-- multimedia11
  |-- multimedia12
  |-- multimedia13
  |-- multimedia14
  |-- multimedia15
  |-- multimedia2
  |-- multimedia3
  |-- multimedia4
  |-- multimedia5
  |-- multimedia6
  |-- multimedia7
  |-- multimedia8
  |-- multimedia9
  ...


If needed, we can make the number of partions to create
adjustable with the attribute?
2005-04-26 21:32:28 -07:00
kay.sievers@vrfy.org a27cd06c6d [PATCH] Adding '%s' format specifier to NAME and SYMLINK
On Thu, Feb 12, 2004 at 05:34:57PM -0800, Greg KH wrote:
> On Tue, Feb 10, 2004 at 09:14:20AM +0100, Hannes Reinecke wrote:
> > Hi all,
> >
> > this patch makes the format for NAME and SYMLINK a bit more flexible:
> > I've added a new format specifier '%s{<SYSFS_var>}', which allows for
> > the value of any sysfs entry found for this device to be inserted.
> > Example (for our S/390 fcp adapter):
> >
> > BUS="ccw", SYSFS_devtype="1732/03", NAME="%k" \
> > SYMLINK="zfcp-%s{hba_id}-%s{wwpn}:%s{fcp_lun}"
> >
> > I know this could also be done with an external program, but having this
> > incorporated into udev makes life easier, especially if run from
> > initramfs. Plus it makes the rules easier to follow, as the result is
> > directly visible and need not to be looked up in some external program.
> >
> > Comments etc. welcome.
>
> Oops, sorry I missed this for the 017 release.  I'll look at it tomorrow
> and get back to you.  At first glance it looks like a good thing.
>
> Oh, you forgot to update the documentation, that's important to do if
> you want this change to make it in :)

I took a part of the code and made a version that uses already implemented
attribute finding logic.

The parsing of the format length '%3x' and the '%x{attribute}' is a fuction now,
maybe there are more possible users in the future.

I've also added the test to udev-test.pl.
2005-04-26 21:32:28 -07:00
greg@kroah.com 7a4877bf6f [PATCH] Fix bug where we did not use the "converted" kernel name if we had no rule.
This fixes the bug with names that have a ! in them and no rule to match.
2005-04-26 21:32:27 -07:00
greg@kroah.com ba053b91e1 [PATCH] fix bug in permission handling. 2005-04-26 21:32:27 -07:00
greg@kroah.com bb051f6657 [PATCH] fix problem where usb devices can be either the main device or the interface
This fixes the bug of a long delay for mouse devices
2005-04-26 21:32:27 -07:00
patmans@us.ibm.com 3a8c51a771 [PATCH] udev add wild card compare for ID
Allow wild card comparison of the ID.

Using strcmp_pattern here also means we on longer match partial values,
for example, a scsi rule like this won't match anymore:

	BUS="scsi", ID=":0", NAME="sdfoo-short-bus_id-1"

But this now works:

	BUS="scsi", ID="*:0", NAME="sdfoo-bus_id-wild-card-1"
2005-04-26 21:32:26 -07:00
patmans@us.ibm.com 5a42932b9a [PATCH] udev kill extra bus_id compares in match_id
Kill the extra bus_id check in match_id. This is wrong, especially since
we check for rule matches with the parent devices on a given devices path.

For example, given a device path of:

	/sys/devices/pci0000:01/0000:01:0c.0/host5/5:0:2:0

With this patch, the following rule will no longer match:

	BUS="scsi", ID="host5", NAME="sd-bus_id-host5"
2005-04-26 21:32:26 -07:00
greg@kroah.com 1b9410278e [PATCH] Handle the '!' character that some block devices have. 2005-04-26 21:32:26 -07:00
kay.sievers@vrfy.org c5118442a1 [PATCH] udev - fix "ignore method"
On Sun, Feb 08, 2004 at 04:36:01PM +0100, Kay Sievers wrote:
> We don't handle NAME="" the right way. Thanks to Emil None <emil71se@yahoo.com>
> for pointing this out. Here is a fix for it and a trivial style cleanup.

Changed the ignore dbg() to info().
2005-04-26 21:32:26 -07:00
kay.sievers@vrfy.org 8a08e4b190 [PATCH] fix possible buffer overflow
On Tue, Jan 27, 2004 at 11:02:25AM -0800, Greg KH wrote:
> On Mon, Jan 26, 2004 at 07:28:03PM -0500, Adrian Drzewiecki wrote:
> > Looking over the code, I noticed something odd in
> > namedev.c:strcmp_pattern() --
> >
> > 	while (*p && (*p != ']'))
> > 		p ++;
> > 	return strcmp_pattern(p+1, s+1);
> >
> > If the pattern string is invalid, and is not terminated by a ']', then 'p'
> > will point at \0 and p+1 will be beyond the string.
>
> Yes, I think you are correct.
>
> Hm, Kay, any idea of the proper way to fix this?  I've attached a patch
> below, but I don't think it is correct.
>
>  					while (*p && (*p != ']'))
>  						p++;
> -					return strcmp_pattern(p+1, s+1);
> +					if (*p)
> +						return strcmp_pattern(p+1, s+1);
> +					else
> +						return 1;
>  				}
>  			}


Sure, it's perfectly correct. I'm wondering how Adrian found this.

We can use the return 1 at the end of the whole function, and asking
for the closing ']' is more descriptive, but it does the same.

-					return strcmp_pattern(p+1, s+1);
+					if (*p == ']')
+						return strcmp_pattern(p+1, s+1);

Patch is attached, that also replaces all the *s with s[0].
2005-04-26 21:13:20 -07:00
kay.sievers@vrfy.org 2a25816ff0 [PATCH] udev - trivial style cleanup
Trivial style cleanup, to be consistent.

And add chdir("/") to the daemon so one can umout its filesystem,
while we are running :)
2005-04-26 21:13:19 -07:00
greg@kroah.com 724257d97b [PATCH] add support for figuring out which device on the sysfs "chain" the rule applies to.
This should fix one of the more annoying things to me about udev, and
gets rid of a TODO item.
2005-04-26 21:13:17 -07:00
greg@kroah.com 267f534d1c [PATCH] misc code cleanups. 2005-04-26 21:13:17 -07:00
kay.sievers@vrfy.org 765cbd9759 [PATCH] set default owner/group in db - update
I've edited the man page today, so this is alreay included :)

Also a few more trivials:
  o added the defaults to udev.conf.in
  o removed class_dev from get_default_mode(), to match with Hanna's
  o changed size of mode_str to MODE_SIZE
  o changed a few char compares from from 0x00 to '\0'
2005-04-26 21:13:17 -07:00
hannal@us.ibm.com 74c73ef994 [PATCH] set default owner/group in db.
This patch fixes a bug where the udev database stored empty strings
for Owner and Group if they were default. This patch stores the default
value into the database if not set otherwise. See example output:


crw-------    1 root     root       4,  65 Jan 16 11:13 ttyS1

P: /class/tty/ttyS1
N: ttyS1
S:
O: root
G: root

This is a bit of a hack. However, until udev supports setting the
o/g values they will be root/root anyway so the database might as
well reflect the truth instead of empty strings.
2005-04-26 21:13:17 -07:00
kay.sievers@vrfy.org 54988802b7 [PATCH] add udev logging to info log
On Thu, Jan 15, 2004 at 05:14:16AM +0100, Kay Sievers wrote:
> On Wed, Jan 14, 2004 at 01:10:43PM -0800, Greg KH wrote:
> > On Wed, Jan 14, 2004 at 02:34:26PM -0600, Clay Haapala wrote:
> > > On Wed, 14 Jan 2004, Chris Friesen spake thusly:
> > > >
> > > > Maybe for ones with a matching rule, you could print something like:
> > > >
> > > >
> > > Is the act of printing/syslogging a rule in an of itself?
> >
> > No, as currently the only way stuff ends up in the syslog is if
> > DEBUG=true is used on the build line.
> >
> > But it's sounding like we might want to change that... :)
>
> How about this in the syslog after connect/disconnect?
>
>   Jan 15 05:07:45 pim udev[28007]: configured rule in '/etc/udev/udev.rules' at line 17 applied, 'video*' becomes 'video/webcam%n'
>   Jan 15 05:07:45 pim udev[28007]: creating device node '/udev/video/webcam0'
>   Jan 15 05:07:47 pim udev[28015]: removing device node '/udev/video/webcam0'

Here is a slightly better version. I've created a logging.h file and
moved the debug macros from udev.h in there.

If you type:

  'make'            - you will get a binary that prints one or two lines to syslog
                      if a device node is created or deleted

  'make LOG=false'  - you get a binary that prints asolutely nothing

  'make DEBUG=true' - the same as today, it will print all debug lines
2005-04-26 21:13:17 -07:00
greg@kroah.com 18f0045bc8 [PATCH] remove the %D modifier as it is not longer needed. 2005-04-26 21:13:16 -07:00
ananthmg@rediffmail.com 616a707807 [PATCH] libsysfs update for refresh + namedev.c changes
Please find inlined a patch which contains updates to libsysfs
(pre-release) for refresh and also changes to namedev.c to take
advantage of it.
2005-04-26 21:13:16 -07:00
kay.sievers@vrfy.org 8ffb636f01 [PATCH] udev - introduce format escape char
This patch adds a '%' to the format char list, so that a external
program may called with a non expanded '%' like:

  PROGRAM="/bin/date +%%s"

Olaf Hering asked for the feature.
A tricky test is also added :)
2005-04-26 21:13:16 -07:00
kay.sievers@vrfy.org 7e5f7397f9 [PATCH] udev - CALLOUT is PROGRAM now
replace CALLOUT by PROGRAM and fix old rule format
2005-04-26 21:13:16 -07:00
kay.sievers@vrfy.org a2505f4d1d [PATCH] udev - simple debug tweak
change the empty debug string:
  Jan 13 00:55:42 pim udev[2849]: namedev_name_device: found matching rule, 'video*' becomes ''

to something useful:
  Jan 13 01:00:23 pim udev[3234]: namedev_name_device: found matching rule, 'video*' becomes 'video/webcam%n'
2005-04-26 21:13:15 -07:00
greg@kroah.com 1f7148c7df [PATCH] fix a few stale comments in namedev.c 2005-04-26 21:13:15 -07:00
greg@kroah.com b7824727a0 [PATCH] add bus test for usb-serial bus. 2005-04-26 21:13:15 -07:00
kay.sievers@vrfy.org ac28b86d63 [PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
>   o the "<METHOD>, " at the beginning of the line should be removed
>
>   o the result of the externel program is matched with RESULT= instead if ID=
>     the PROGRAM= key is only valid if the program exits with zero
>     (just exit with nozero in a script if the rule should not match)
>
>   o rules are processed in order they appear in the file, no priority
>
>   o if NAME="" is given, udev is instructed to ignore this device,
>     no node will be created
>
>
>   EXAMPLE:
>
>   # combined BUS, SYSFS and KERNEL
>   BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
>   # exec script only for the first ide drive (hda), all other will be skipped
>   BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>


Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.


EXAMPLE:
  We have 7 rules with RESULT and 2 with PROGRAM.
  Only the 5th rule matches with the callout result from the exec in the 4th rule.

RULES:
  PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
  KERNEL="video*", RESULT="123", NAME="web-no-3"
  KERNEL="video*", RESULT="123", NAME="web-no-4"
  PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
  KERNEL="video*", RESULT="123", NAME="web-yes"


RESULT:
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
  Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
  Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
  Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
  Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
  Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2005-04-26 21:13:15 -07:00
kay.sievers@vrfy.org 41397661c6 [PATCH] udev - make exec_callout() reusable
Here is a patch that switches exec_callout() to be reusable.
I want it to be callable in a different context.
2005-04-26 21:13:15 -07:00
kay.sievers@vrfy.org 2794d24917 [PATCH] udev - exec status fix for klibc
Here is a patch to remove the ifdef's and fix klibc instead.
2005-04-26 21:13:14 -07:00
christophe@saout.de f1db055ab2 [PATCH] add IGNORE rule type
On Wed, Dec 31, 2003 at 11:24:53AM -0800, Greg KH wrote:

> > There should be a possibility to tell udev not to create a device node.
> >
> > device-mapper: Usually set up by libdevmapper (or EVMS tools) which
> > creates the device node on its own under /dev/mapper/<name>.
> >
> > With udev a second device is created named /dev/dm-<minor> which is not
> > really needed.
>
> Good point.  Ok, I'll agree with you.  Care to make up a patch for this
> kind of feature?

Yes, I can try.

There was no way to tell not to do anything so I created one. Errors
are signalled via negative return values, so I thought that a positive,
non-zero one could mean to ignore the device. I don't like it but
perhaps you have a better solution.
2005-04-26 21:13:14 -07:00
greg@kroah.com 843d1a84b9 [PATCH] replace list_for_each with list_for_each_entry, saving a few lines of code. 2005-04-26 21:13:14 -07:00
azarah@nosferatu.za.org 8ed89229bc [PATCH] Fix udev gcc-2.95.4 compat
Two liner to get gcc-2.95.4 to compile udev.
2005-04-26 21:13:12 -07:00
kay.sievers@vrfy.org 647c8fc43e [PATCH] fix for apply_format()
fix possible NULL pointer in '%c' callout substitution
and cleanup '%D' debug text
2005-04-26 21:13:12 -07:00
kay.sievers@vrfy.org 2441c20743 [PATCH] 'ide' missing in bus_files[]
my syslog want's to contact you :)

  Dec 25 20:37:48 pim udev[2274]: wait_for_device_to_initialize: Did not find bus type 'ide' on list of bus_id_files, contact greg@kroah.com

We need to put 'ide' to the bus_files array,
don't know which file to use...
2005-04-26 21:13:11 -07:00
greg@kroah.com a7402175da [PATCH] If a LABEL rule has a BUS id, then we must check to see if the device is on a bus. 2005-04-26 21:13:11 -07:00
greg@kroah.com 1d936fbca0 [PATCH] If a CALLOUT rule has a BUS id, then we must check to see if the device is on a bus.
Thanks to Martin Schlemmer <azarah@nosferatu.za.org> for pointing this out.
2005-04-26 21:13:11 -07:00
greg@kroah.com 480763324d [PATCH] add pci to the bus_files list. 2005-04-26 21:13:10 -07:00
greg@kroah.com 07562d6ecf [PATCH] fix long delay for all devices in namedev
Now we only sleep if we can't find the device file, and we have
a hack to sleep for 1 second if we are on a partition.  This will be
removed when the libsysfs change gets made...
2005-04-26 21:13:10 -07:00
greg@kroah.com ca593541e6 [PATCH] fix complier warning in namedev.c 2005-04-26 21:13:10 -07:00
greg@kroah.com a8b01705c6 [PATCH] add ability to have up to 5 SYSFS_ file/value pairs for the LABEL rule. 2005-04-26 21:13:10 -07:00
kay.sievers@vrfy.org 958479a0de [PATCH] add any valid device 2005-04-26 21:13:09 -07:00
kay.sievers@vrfy.org 3e54036862 [PATCH] introduce format char 'k' for kernel-name
Attached is a patch that introduces the format char 'k' to be replaced with
the kernel name. I like to have it in a callout script.

I've moved the build_kernel_name() back to namedev_name_device() since
we don't expect it growing cause of 'sdaj' :)
2005-04-26 21:13:09 -07:00
greg@kroah.com 1edbb8d350 [PATCH] Just live with a sleep(1) in namedev for now until libsysfs is fixed up. 2005-04-26 21:13:09 -07:00
greg@kroah.com dac056aa30 [PATCH] try to wait until the proper device file shows up in sysfs.
this still isn't working correctly for partitions, so don't
think this is the final version...
2005-04-26 21:13:09 -07:00
greg@kroah.com 7ecb8d23f3 [PATCH] remove unneeded TODO and FIXME entry
Thanks to Kay for pointing it out to me.
2005-04-26 21:13:09 -07:00
kay.sievers@vrfy.org b1c5e3339d [PATCH] get part of callout return string
Try this patch if you like, to get special parts of the callout output.
This beast works now:
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", ID="node *", NAME="%1c", SYMLINK="%2c %3c"

The callout returned string is separated by spaces and is
addressed by the "len" value of the 'c' format char.
Since we support symlinks, this my be useful for other uses of callout too.

  introduce 'len number' for format chars
  the first use is 'c'-the callout return to select a part of the output string like:
  CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", ID="node *", NAME="%1c", SYMLINK="%2c %3c"
  (note: first part is requested by len=1, len=0 will return the whole string)
  add a test to udev-test.pl
2005-04-26 21:13:07 -07:00