Date: Fri, 17 May 2002 18:40:57 -0400 (EDT) From: "Geoffrey C. Speicher" <geoff@sea-incorporated.com> To: freebsd-stable@freebsd.org Cc: "Matthew D. Fuller" <fullermd@over-yonder.net>, Matt Simerson <freebsd@blockads.com> Subject: bug in pw, -STABLE [patch] Message-ID: <Pine.BSF.4.10.10205171825320.67053-300000@sea-incorporated.com>
next in thread | raw e-mail | index | archive | help
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. --0-824176124-1021675257=:67053 Content-Type: TEXT/PLAIN; charset=US-ASCII All: I posted a message the other day to -hackers with a patch for pw(8). The patch corrects a bug where running multiple instances of pw quickly leads to corruption of master.passwd. I just now realized that I copy-n-pasted those patches into my email, so they are not very useful. Besides that, I wasn't really sure where the post should go anyway, so I'm reposting here with good patches attached and the original message (slightly modified) below. I have a patched binary on a production server with several thousand accounts, and it is working flawlessly. I need a committer to take a peek at these patches and either commit them or tell me what needs to be changed before they can be committed. Some points for consideration are: 1. The lock isn't very fine-grained. We grab one giant lock before doing any operations at all, and let it go right before we exit. The alternative is to lock for /etc/master.passwd and /etc/group individually as necessary, but I saw no point in going that far since pw seems to spend most of its time updating those files anyway. 2. The lockfile is /var/run/pw.lock and it always contains the pid of the pw process that most recently grabbed the lock. 3. The lockfile is never deleted, because doing so seemed to cause a race condition between the time the file was closed and unlinked, leading to password file corruption again. If anyone has a solution to this, please speak up. 4. To test, backup your /etc/master.passwd and /etc/group, and then try something like this, several times with the old pw binary to verify consistent breakage, and then several times with the patched binary to verify that it doesn't break anymore. In one terminal, run this first: #!/bin/sh i=0 while [ $i -le 1000 ]; do pw add user testuser$i i=$(($i+1)) done In another terminal, wait about 10-15 seconds and then run this (or tail -f /etc/master.passwd and run it when testuser500 shows up): #!/bin/sh i=0 while [ $i -le 500 ]; do pw del user testuser$i i=$(($i+1)) done Geoff --0-824176124-1021675257=:67053 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="pw.c.patch" Content-Transfer-Encoding: BASE64 Content-ID: <Pine.BSF.4.10.10205171840570.67053@sea-incorporated.com> Content-Description: Content-Disposition: attachment; filename="pw.c.patch" LS0tIHNyYy91c3Iuc2Jpbi9wdy9wdy5jLm9yaWcJV2VkIE1heSAxNSAxMzoz NToyMSAyMDAyDQorKysgc3JjL3Vzci5zYmluL3B3L3B3LmMJV2VkIE1heSAx NSAxMzozNzo1MyAyMDAyDQpAQCAtOTgsMTAgKzk4LDEyIEBADQogbWFpbihp bnQgYXJnYywgY2hhciAqYXJndltdKQ0KIHsNCiAJaW50ICAgICAgICAgICAg IGNoOw0KKwlpbnQJCWxvY2tmZDsNCiAJaW50ICAgICAgICAgICAgIG1vZGUg PSAtMTsNCiAJaW50ICAgICAgICAgICAgIHdoaWNoID0gLTE7DQogCWNoYXIJ CSpjb25maWcgPSBOVUxMOw0KIAlzdHJ1Y3QgdXNlcmNvbmYgKmNuZjsNCisJ Y2hhcgkJKnBpZHN0cjsNCiANCiAJc3RhdGljIGNvbnN0IGNoYXIgKm9wdHNb V19OVU1dW01fTlVNXSA9DQogCXsNCkBAIC0yMDIsNiArMjA0LDE3IEBADQog CQllcnJ4KEVYX05PUEVSTSwgInlvdSBtdXN0IGJlIHJvb3QgdG8gcnVuIHRo aXMgcHJvZ3JhbSIpOw0KIA0KIAkvKg0KKwkgKiBHYWluIGV4Y2x1c2l2ZSBs b2NrIGJlZm9yZSB1cGRhdGluZyBhbnkgZmlsZXMNCisJICovDQorCWxvY2tm ZCA9IG9wZW4oX1BXTE9DSywgT19XUk9OTFkgfCBPX0NSRUFUIHwgT19FWExP Q0ssIF9MT0NLX0ZJTEVfTU9ERSk7DQorCWlmIChsb2NrZmQgPT0gLTEpDQor CQllcnIoRVhfVU5BVkFJTEFCTEUsICIlcyIsIF9QV0xPQ0spOw0KKw0KKwlm dHJ1bmNhdGUobG9ja2ZkLDApOw0KKwl3cml0ZShsb2NrZmQsIHBpZHN0ciwg YXNwcmludGYoJnBpZHN0ciwgIiVkIiwgZ2V0cGlkKCkpKTsNCisJZnJlZShw aWRzdHIpOw0KKw0KKwkvKg0KIAkgKiBXZSBzaG91bGQgaW1tZWRpYXRlbHkg bG9vayBmb3IgdGhlIC1xICdxdWlldCcgc3dpdGNoIHNvIHRoYXQgd2UNCiAJ ICogZG9uJ3QgYm90aGVyIHdpdGggZXh0cmFuZW91cyBlcnJvcnMNCiAJICov DQpAQCAtMjI2LDcgKzIzOSw3IEBADQogCQkJc2V0Z3JkaXIoZXRjcGF0aCk7 DQogCQl9DQogCX0NCi0gICAgDQorDQogCS8qDQogCSAqIE5vdywgbGV0J3Mg ZG8gdGhlIGNvbW1vbiBpbml0aWFsaXNhdGlvbg0KIAkgKi8NCkBAIC0yNTks NiArMjcyLDEyIEBADQogCQkJCXB3X2xvZyhjbmYsIG1vZGUsIHdoaWNoLCAi TklTIG1hcHMgdXBkYXRlZCIpOw0KIAkJfQ0KIAl9DQorDQorCS8qDQorCSAq IFJlbGVhc2UgdGhlIGxvY2sNCisJICovDQorCWNsb3NlKGxvY2tmZCk7DQor DQogCXJldHVybiBjaDsNCiB9DQogDQo= --0-824176124-1021675257=:67053 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="pwupd.h.patch" Content-Transfer-Encoding: BASE64 Content-ID: <Pine.BSF.4.10.10205171840571.67053@sea-incorporated.com> Content-Description: Content-Disposition: attachment; filename="pwupd.h.patch" LS0tIHNyYy91c3Iuc2Jpbi9wdy9wd3VwZC5oLm9yaWcJVHVlIE1heSAxNCAy MjowNjozNyAyMDAyDQorKysgc3JjL3Vzci5zYmluL3B3L3B3dXBkLmgJV2Vk IE1heSAxNSAxMzozNToxNCAyMDAyDQpAQCAtMTEwLDYgKzExMCwxMiBAQA0K ICNpZm5kZWYgX0dST1VQDQogI2RlZmluZSBfR1JPVVAJCSJncm91cCINCiAj ZW5kaWYNCisjaWZuZGVmIF9QV0xPQ0sNCisjZGVmaW5lIF9QV0xPQ0sJCSIv dmFyL3J1bi9wdy5sb2NrIg0KKyNlbmRpZg0KKyNpZm5kZWYgX0xPQ0tfRklM RV9NT0RFDQorI2RlZmluZSBfTE9DS19GSUxFX01PREUJKFNfSVJVU1IgfCBT X0lXVVNSKQ0KKyNlbmRpZg0KIA0KIF9fQkVHSU5fREVDTFMNCiBpbnQgYWRk cHdlbnQgX19QKChzdHJ1Y3QgcGFzc3dkICogcHdkKSk7DQo= --0-824176124-1021675257=:67053-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10205171825320.67053-300000>