1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00
Commit Graph

1200 Commits

Author SHA1 Message Date
Volker Lendecke
7e444e1612 r20614: Dummy-checkin to trigger the build 2007-10-10 12:16:58 -05:00
Andrew Bartlett
e43aa4e03d r20402: Fix spelling: samba bug #4292 debian #402392 2007-10-10 12:16:46 -05:00
Simo Sorce
7167e7b26a r20243: Make lookup_name resolve both the mapped and the real unix group name 2007-10-10 12:16:35 -05:00
Volker Lendecke
902d81becb r20212: Attempt to fix the Solaris build 2007-10-10 12:16:32 -05:00
Simo Sorce
4a81ee9608 r20169: Support for fallback to legacy mapping code was not completely tested.
Add necessary fixes.
2007-10-10 12:16:28 -05:00
Simo Sorce
50cd8bffee r20116: Start merging in the work done to create the new idmap subsystem.
Simo.
2007-10-10 12:16:25 -05:00
Jeremy Allison
0ffca7559e r20090: Fix a class of bugs found by James Peach. Ensure
we never mix malloc and talloc'ed contexts in the
add_XX_to_array() and add_XX_to_array_unique()
calls. Ensure that these calls always return
False on out of memory, True otherwise and always
check them. Ensure that the relevent parts of
the conn struct and the nt_user_tokens are
TALLOC_DESTROYED not SAFE_FREE'd.
James - this should fix your crash bug in both
branches.
Jeremy.
2007-10-10 12:16:24 -05:00
Volker Lendecke
eba404e668 r19945: Fix a segfault -- lookup_rids needs to init the names even on failure 2007-10-10 12:16:14 -05:00
Volker Lendecke
714971b34a r19943: Fix bug 4267 -- Thanks to David! 2007-10-10 12:16:12 -05:00
Gerald Carter
5b3ac400a7 r19579: BUG 4075: patch from Dmitry Butskoy <dmitry@butskoy.name>.
Allow smbd to use winbindd to lookup uids/gids outside the
idmap range if 'winbind trusted domains only = yes'
2007-10-10 12:15:42 -05:00
Gerald Carter
a6366b40b3 r19419: BUG 4109: Patch from Timur Bakeyev. Fix bug causing smbd to turn off
winbindd and fail to disable the _NO_WINBIND environment.
2007-10-10 12:15:34 -05:00
Volker Lendecke
6c4d68d849 r19083: Fix objectclass 2007-10-10 12:15:09 -05:00
Jim McDonough
21abbeaee9 r19058: Implement "user cannot change password", and complete "user must change
password at next logon" code.  The "password last set time" of zero now
means "user must change password", because that's how windows seems to
use it.  The "can change" and "must change" times are now calculated
based on the "last set" time and policies.

We use the "can change" field now to indicate that a user cannot change
a password by putting MAX_TIME_T in it (so long as "last set" time isn't
zero).  Based on this, we set the password-can-change bit in the
faked secdesc.
2007-10-10 12:15:06 -05:00
Jim McDonough
fd5761c9e5 r18722: Fix up password change times. The can change and must change times are
calculated based on the last change time, policies, and acb flags.

Next step will be to not bother storing them.  Right now I'm just trying to
get them reported correctly.
2007-10-10 12:00:52 -05:00
Günther Deschner
7db6ce295a r18703: Fix the annoying effect that happens when nscd is running:
We usually do not get the results from user/group script modifications
immediately. A lot of users do add nscd restart/refresh commands into
their scripts to workaround that while we could flush the nscd caches
directly using libnscd.

Guenther
2007-10-10 12:00:49 -05:00
Gerald Carter
4cea9bfca1 r18684: pdb_get_group_sid() has to use the Get_Pwnam_alloc() call
to ensure it finds the Unix user.
2007-10-10 12:00:47 -05:00
Jelmer Vernooij
5de76767e8 r18654: Rename "struct uuid" => "struct GUID" for consistency. 2007-10-10 11:52:19 -05:00
Volker Lendecke
d72ba9ed12 r18527: Janitor for Jeremy ;-) 2007-10-10 11:51:46 -05:00
Jeremy Allison
f787b9d156 r18483: Ensure all pdb_XXX calls are wrapped in become_root()/unbecome_root()
pairs. Should fix bug #4097.
Jeremy.
2007-10-10 11:51:44 -05:00
Volker Lendecke
fa8b2e2a58 r18313: Nobody said "no" (yet.... gd?), so commit it:
Remove the account_policy_migrated() thingy, and make cache_account_policy_set
use gencache. Account policies are now handled like groups and users are with
respect to "passdb backend".

Volker
2007-10-10 11:51:19 -05:00
Gerald Carter
3da9f80c28 r18271: Big change:
* autogenerate lsa ndr code
* rename 'enum SID_NAME_USE' to 'enum lsa_SidType'
* merge a log more security descriptor functions from
  gen_ndr/ndr_security.c in SAMBA_4_0

The most embarassing thing is the "#define strlen_m strlen"
We need a real implementation in SAMBA_3_0 which I'll work on
after this code is in.
2007-10-10 11:51:18 -05:00
Gerald Carter
fa05708789 r17971: Disable storing SIDs in the S-1-22-1 and S-1-22-2 domain to the SID<->uid/gid cache. FIxes a bug in token creation 2007-10-10 11:39:44 -05:00
Volker Lendecke
70edd716ef r17924: Get rid of warnings now that talloc is merged.
Destructors now take a pointer to the "real" destroyed object as an argument.

Volker
2007-10-10 11:38:59 -05:00
Volker Lendecke
872d1299eb r17831: Attempt to fix the build farm: 0x7fffffffffffffff needs special casing too I
think. This broke 'make test' because the newly created user was set to be
kicked off Mi, 22 Jan 1975 23:55:33 CET (unix time 159663333) with the
setuserinfo21 call.

I'm not 100% sure that 0x7ff... means max time as I do it here, I vaguely
remember it to mean "don't touch".

Does anybody know that for sure?

Jeremy, please check this.

Thanks,

Volker
2007-10-10 11:38:52 -05:00
Gerald Carter
1a5b90f3c1 r17815: Revert Volker's change in 16014. I really do not believe
the this should be necessary.  If there is still a bug,
I believe that setting thr group RID from the passdb is
masking it.  Not fixing it.  It is very likely that
the change was necessary before but is no longer
with the recent changes.  But I'm not taking the chance
of merging it to 3.0.23c. :-)
2007-10-10 11:38:51 -05:00
Gerald Carter
0a3aa8b43a r17813: Remove another instance of manually setting the group SID.
The would have been primaryly used when adding a user to
an smbpasswd file, but could have been introduce to other
backends by using pdbedit -i -e.

The symptom was

[2006/08/09 13:07:43, 0] rpc_parse/parse_samr.c:init_sam_user_info21A(6276)
  init_sam_user_info_21A: User nobody has Primary Group SID S-1-22-2-99,
  which conflicts with the domain sid S-1-5-21-1825997848-4107600307-1754506280.
  Failing operation.
2007-10-10 11:38:51 -05:00
Gerald Carter
dda0b8bce6 r17709: Fix cut-n-paste error with the name of gid_to_unix_group_sid(). 2007-10-10 11:38:46 -05:00
Gerald Carter
0939b6e20c r17673: volker's patch for re-adding Getpwnam() lookups to smbpasswd backend (I hate username level) 2007-10-10 11:38:46 -05:00
Gerald Carter
dde552336c r17669: Remove RID algorithm support from unmapped users and groups
when using smbpasswd
2007-10-10 11:38:45 -05:00
Volker Lendecke
543f77a45f r17592: Remove some unused functions pointed out by John E. Malmberg, make
do_file_lock static to pdb_smbpasswd.c, the only user of it.

Volker
2007-10-10 11:38:41 -05:00
Volker Lendecke
761cbd52f0 r17554: Cleanup 2007-10-10 11:38:38 -05:00
Volker Lendecke
4ebfc30a28 r17468: To minimize the diff later on, pre-commit some changes independently: Change
internal mapping.c functions to return NTSTATUS instead of BOOL.

Volker
2007-10-10 11:38:36 -05:00
Volker Lendecke
244b25ae49 r17465: Get rid of add_initial_entry. In the two places it was called in it seemed a
bit pointless to me.

Volker
2007-10-10 11:38:36 -05:00
Volker Lendecke
f9856f6490 r17463: A bit of cleanup work:
Remove some unused code: pdb_find_alias is not used anymore, and nobody I
think has ever used the pdb_nop operations for group mapping. smbpasswd and
tdb use the default ones and ldap has its own.

Make the functions pdb_getgr* return NTSTATUS instead of BOOL. Nobody right
now really makes use of it, but it feels wrong to throw away information so
early.

Volker
2007-10-10 11:38:36 -05:00
Volker Lendecke
873a5a1211 r17451: Change pdb_getgrsid not to take a DOM_SID but a const DOM_SID * as an
argument.

Volker
2007-10-10 11:38:34 -05:00
Jeremy Allison
b5f0b1b644 r17407: Don't do strchr_m twice when once will do.
Jeremy.
2007-10-10 11:38:32 -05:00
Volker Lendecke
255475901c r17406: We need to do a translation of winbind separator -> '\\' in
lookup_name_smbconf, otherwise

force user = domain+administrator

can not work. Also attempt to fix the 'valid users = domain+group' bug at the
same time.

Volker
2007-10-10 11:38:32 -05:00
Volker Lendecke
250b9f3531 r17404: Is this XP (extreme programming)? :-)
With lp_workgroup we end up with remote names again...

Volker
2007-10-10 11:38:32 -05:00
Gerald Carter
63325b3687 r17403: add a helpful debug msg 2007-10-10 11:38:32 -05:00
Jeremy Allison
1e1fcb5eb2 r17402: Added lookup_name_smbconf() to be called when looking
up names from smb.conf. If the name is unqualified it
causes the lookup to be done in WORKGROUP\name, then
"Unix [users|groups]"\name rather than searching the
domain. Should fix the problems with "force user"
selecting a domain user by preference.
Jeremy.
2007-10-10 11:38:31 -05:00
Gerald Carter
21d69dcb3c r17271: Fix a regression in the ldapsam uri syntax.
Allow multiple LDAP URIs to be grouped by  ""
2007-10-10 11:38:23 -05:00
Gerald Carter
dc4fec1f7d r17246: BUG 3964: lower case username prior to getpwnam() call in smbpasswd 2007-10-10 11:38:22 -05:00
Gerald Carter
bbe11b7a95 r17150: MMC User & group plugins fixes:
* Make sure to lower case all usernames before
  calling the create, delete, or rename hooks.
* Preserve case for usernames in passdb
* Flush the getpwnam cache after renaming a user
* Add become/unbecome root block in _samr_delete_dom_user()
  when trying to verify the account's existence.
2007-10-10 11:38:16 -05:00
Volker Lendecke
03e9924f5c r17075: Even without talloc_steal you can still create memory problems.... ;-) 2007-10-10 11:38:10 -05:00
Jeremy Allison
9dafb7f48c r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
to do the upper layer directories but this is what
everyone is waiting for....

Jeremy.
2007-10-10 11:19:14 -05:00
Volker Lendecke
84913caebd r16866: No idea why I did not see the warning, sorry.... 2007-10-10 11:19:12 -05:00
Volker Lendecke
9ec5ccfe85 r16865: This is a proposal to fix bug 3915. Before sending patches around, this is
what svn is for.

The idea is that we fall back to a pure unix user with S-1-22 SIDs in the
token in case anything weird is going on with the 'force user'.

Volker
2007-10-10 11:19:12 -05:00
Jeremy Allison
8c7e40f2a4 r16683: Fix bug #3900 reported by jason@ncac.gwu.edu.
Jeremy.
2007-10-10 11:19:07 -05:00
Jeremy Allison
1cd9a0ef83 r16681: Fix bug #3899 reported by jason@ncac.gwu.edu.
Jeremy.
2007-10-10 11:19:07 -05:00
Jeremy Allison
5c5ea3152f r16678: Fix bug #3898 reported by jason@ncac.gwu.edu.
Jeremy.
2007-10-10 11:19:07 -05:00
Jeremy Allison
dfdb4ce891 r16663: Fix coverity #301, memleak in error path.
Jeremy.
2007-10-10 11:19:06 -05:00
Jeremy Allison
98a5e20ff4 r16628: Fix bug #3880, reported by jason@ncac.gwu.edu
by ensuring we return the correct enum for sid
type, not a uint32.
Jeremy.
2007-10-10 11:19:04 -05:00
Jeremy Allison
1f52b8b406 r16624: Fix bug #3877, reported by jason@ncac.gwu.edu
Jeremy.
2007-10-10 11:19:04 -05:00
Jeremy Allison
720a917205 r16593: Make the invarient explicit to Klocwork. Bug #2023.
Jeremy.
2007-10-10 11:19:02 -05:00
Jeremy Allison
ce14daf51c r16582: Fix Klocwork #1997 and all generic class of problems
where we don't correctly check the return from memdup.
Jeremy.
2007-10-10 11:19:01 -05:00
Volker Lendecke
adf2dcce09 r16427: Fix bug # 3848. Thanks to Wilco Baan Hofman for testing the release candidate!
Volker
2007-10-10 11:18:53 -05:00
Jeremy Allison
7b68a2acfc r16383: Klocwork #1086. No null deref.
Jeremy.
2007-10-10 11:18:50 -05:00
Jeremy Allison
2e5a881478 r16381: Now samu can't be null don't check it on set. Klockwork
related fix.
Jeremy.
2007-10-10 11:18:50 -05:00
Volker Lendecke
3df0bf7d60 r16360: Fix Klocwork ID 136 520 521 522 523 542 574 575 576 607
in net_rpc.c: 715 716 732 734 735 736 737 738 739 749

in net_rpc_audit.c: 754 755 756

in net_rpc_join.c: 757

in net_rpc_registry: 766 767

in net_rpc_samsync.c: 771 773

in net_sam.c: 797 798

Volker
2007-10-10 11:18:48 -05:00
Günther Deschner
3203ce3b49 r16350: Fix the build.
GUenther
2007-10-10 11:17:37 -05:00
Volker Lendecke
d3f5acb16e r16334: Fix Klocwork ID's 1087, 1095, 1096, 1098, 1099, 1101, 1102, 1105, 1107, 1109,
1111

Volker
2007-10-10 11:17:34 -05:00
Jeremy Allison
a0d368197d r16241: Fix Klocwork #106 and others like it.
Make 2 important changes. pdb_get_methods()
returning NULL is a *fatal* error. Don't try
and cope with it just call smb_panic. This
removes a *lot* of pointless "if (!pdb)" handling
code. Secondly, ensure that if samu_init()
fails we *always* back out of a function. That
way we are never in a situation where the pdb_XXX()
functions need to start with a "if (sampass)"
test - this was just bad design, not defensive
programming.
Jeremy.
2007-10-10 11:17:27 -05:00
Volker Lendecke
963ae5bd14 r16197: Fix Klocwork id 1338 2007-10-10 11:17:24 -05:00
Jeremy Allison
da768bf9c2 r16155: Janitor for jelmer.
Fix typo in DEBUG()
Jeremy.
2007-10-10 11:17:23 -05:00
Günther Deschner
322f1664df r16121: Fix a eDir related memory leak.
Guenther
2007-10-10 11:17:21 -05:00
Jeremy Allison
5cd234a1ff r16076: Fix for machine password timeout overflow from Shlomi Yaakobovich
<Shlomi@exanet.com>.
Jeremy.
2007-10-10 11:17:19 -05:00
Volker Lendecke
8f9ba5f96c r16064: Bug fix for another one Tom Bork has reported:
'valid users = +unixgroup' failed with smbpasswd if 'unixgroup' has a
(non-algorithmic) group mapping.

Thanks a lot!

People out there listening, please test current code, this release is

	   **BIG**

:-)

Volker
2007-10-10 11:17:19 -05:00
Jeremy Allison
da26565a2e r16016: Add debug to be symetrical with reading from
cache.
Jeremy.
2007-10-10 11:17:17 -05:00
Volker Lendecke
40339fdcce r16014: Correctly set the group RID in init_sam_from_buffer.
BIG THANKS to Tom Bork for reporting that Bug!

Volker
2007-10-10 11:17:17 -05:00
Jeremy Allison
4962548dfe r15895: Ensure all new rid allocation goes through
the same function (deals with races).
Jeremy.
2007-10-10 11:17:12 -05:00
Jeremy Allison
9890a31c5f r15888: Fix bug #3804 from jason@ncac.gwu.edu
Invalid comparisons.
Jeremy.
2007-10-10 11:17:12 -05:00
Günther Deschner
b5a5d0b24e r15649: Allow to store 24 password history entries in ldapsam (same limit as on
Windows). Fixes bug #1914.

Guenther
2007-10-10 11:17:05 -05:00
Günther Deschner
1b5a712467 r15633: Minor smbldap/pdb_ldap cleanup
Guenther
2007-10-10 11:17:04 -05:00
Volker Lendecke
ea7cced6bc r15601: Fix segfaults with 'security=share' and 'guest only = yes'
Volker
2007-10-10 11:17:03 -05:00
Volker Lendecke
2cf503d7da r15571: Fix Coverity bug #285 2007-10-10 11:17:02 -05:00
Gerald Carter
7d99e05ee8 r15547: say goodbye to --with-ldapsam (although the ldapsam_compat passdb backend still exists 2007-10-10 11:16:58 -05:00
Günther Deschner
e4734cb99c r15542: Close the LDAP connection and free the struct, regardless whether the
simple bind operation was successful or not.

Guenther
2007-10-10 11:16:57 -05:00
Jeremy Allison
755c272ebf r15444: Fix from Jim to ensure we do a wildcard search for SID's
starting with the global SAM sid, not an exact search.
Jeremy.
2007-10-10 11:16:45 -05:00
Volker Lendecke
898948d654 r15360: Fix bug # 3741. One more place where the algorithmic mapping needs to stay.
Volker
2007-10-10 11:16:37 -05:00
Gerald Carter
b6904e0950 r15310: only store lanman passwords on a change if 'lanman auth = yes' 2007-10-10 11:16:34 -05:00
Paul Green
17774387ad r15283: Oh yeah. The build farm doesn't do much with head. OK, here is the patch to SAMBA_3_0 to declare prototypes for the initialization functions. These are the same changes I just made to head. --paulg 2007-10-10 11:16:31 -05:00
Volker Lendecke
b9c6e3f556 r15101: Little step towards getting Samba4 tdb into 3: tdb_lock_bystring does not
have the timeout argument in Samba4. Add a new routine
tdb_lock_bystring_with_timeout.

Volker
2007-10-10 11:16:23 -05:00
Volker Lendecke
0a7d4f1ab1 r15009: Add a check for NULL 2007-10-10 11:15:56 -05:00
Gerald Carter
021b3dc2db r14868: I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.
I will not write code when changing to Daylight Savings Time.

...

Fix my brain dead inverted logic for turning winbindd on and off
when run on a DC or when calling pdb functions from within winbindd.
2007-10-10 11:15:52 -05:00
Gerald Carter
4ab372f4ca r14855: Various fixes:
* depreacte 'acl group control' after discussion with Jeremy
  and implement functionality as part of 'dos filemode'
* fix winbindd on a non-member server to expand local groups
* prevent code previously only used by smbd from blindly
  turning _NO_WINBINDD back on
2007-10-10 11:15:51 -05:00
Jeremy Allison
1588ce8efe r14780: Fix coverity bug #272, null deref.
Jeremy.
2007-10-10 11:15:48 -05:00
Günther Deschner
25970a5429 r14758: Fix broken LDAP search filter.
Guenther
2007-10-10 11:15:46 -05:00
Günther Deschner
7eefeaad35 r14756: Make smbpasswd -a root work for eDirectory where there is no "account"
structural objectclass.

Guenther
2007-10-10 11:15:46 -05:00
Jelmer Vernooij
c149421ef7 r14696: make pdb_find_backend_entry public (for use by an external "multi" pdb backend) 2007-10-10 11:15:44 -05:00
Gerald Carter
db1162241f r14634: Many bug fixes thanks to train rides and overnight stays in airports
* Finally fix parsing idmap uid/gid ranges not to break with spaces
  surrounding the '-'
* Allow local groups to renamed by adding info level 2 to
  _samr_set_aliasinfo()
* Fix parsing bug in _samr_del_dom_alias() reply
* Prevent root from being deleted via Samba
* Prevent builting groups from being renamed or deleted
* Fix bug in pdb_tdb that broke renaming user accounts
* Make sure winbindd is running when trying to create the Administrators
  and Users BUILTIN groups automatically from smbd (and not just check the
  winbind nexted groups parameter value).
* Have the top level rid allocator verify that the RID it is about to
  grant is not already assigned in our own SAM (retries up to 250 times).
  This fixes passdb with existing SIDs assigned to users from the RID algorithm
  but not monotonically allocating the RIDs from passdb.
2007-10-10 11:15:41 -05:00
Gerald Carter
df53d64910 r14577: BUG Fixes:
* Add back in the import/export support to pdbedit
* Fix segv in pam_smbpass
* Cleanup some error paths in pdb_tdb and pdb_interface
2007-10-10 11:15:37 -05:00
Gerald Carter
d2c1842978 r14457: Add a few more special cases for RID 513 in the samr code.
Now that I know what all the requirements for this group are
I can generalize the code some more and make it cleaner.
But at least this is working with lusrmgr.msc on XP and 2k now.
2007-10-10 11:15:31 -05:00
Gerald Carter
0b7549997a r14452: Sorry. Need more coffee....
* Fix sprintf() args when createing the group search filter.
2007-10-10 11:15:31 -05:00
Gerald Carter
2c0a46d731 r14451: In order to get pdb_ldap searching for SID_NAME_ALIAS
groups in the ${MACHINESID} and S_1-5-32 domains correctly,
I had to add a substr search on sambaSID.

* add substr matching rule to OpenLDAP schema
  (we need to update the other schema as will since this
  is a pretty important change).  Sites will need to
  - install the new schema
  - add 'indea sambaSID   sub' to slapd.conf
  - run slapindex

* remove uses of SID_NAME_WKN_GRP in pdb_ldap.c
2007-10-10 11:15:30 -05:00
Gerald Carter
612979476a r14403: * modifies create_local_nt_token() to create a BUILTIN\Administrators
group IFF sid_to_gid(S-1-5-32-544) fails and 'winbind nested groups = yes'

* Add a SID domain to the group mapping enumeration passdb call
  to fix the checks for local and builtin groups.  The SID can be
  NULL if you want the old semantics for internal maintenance.
  I only updated the tdb group mapping code.

* remove any group mapping from the tdb that have a
  gid of -1 for better consistency with pdb_ldap.c.
  The fixes the problem with calling add_group_map() in
  the tdb code for unmapped groups which might have had
  a record present.

* Ensure that we distinguish between groups in the
  BUILTIN and local machine domains via getgrnam()
  Other wise BUILTIN\Administrators & SERVER\Administrators
  would resolve to the same gid.

* Doesn't strip the global_sam_name() from groups in the
  local machine's domain (this is required to work with
  'winbind default domain' code)

Still todo.

* Fix fallback Administrators membership for root and domain Admins
  if nested groups = no or winbindd is not running

* issues with "su - user -c 'groups'" command

* There are a few outstanding issues with BUILTIN\Users that
  Windows apparently tends to assume.  I worked around this
  presently with a manual group mapping but I do not think
  this is a good solution.  So I'll probably add some similar
  as I did for Administrators.
2007-10-10 11:15:28 -05:00
Volker Lendecke
b880602c4c r14103: Fix a memleak found by valgrind (!!) 2007-10-10 11:11:12 -05:00
Volker Lendecke
56dc19879c r14102: Fix Coverity bug # 70 2007-10-10 11:11:12 -05:00
Jeremy Allison
7f3ace5481 r14088: Fix Coverity bug #20. Don't deref possible null.
Jeremy.
2007-10-10 11:11:11 -05:00
Volker Lendecke
d38e05329a r13979: We've dereferenced my_methods already, so there's no point in checking for
!= NULL. Coverity #149.

Volker
2007-10-10 11:11:02 -05:00
Jeremy Allison
1d710d06a2 r13915: Fixed a very interesting class of realloc() bugs found by Coverity.
realloc can return NULL in one of two cases - (1) the realloc failed,
(2) realloc succeeded but the new size requested was zero, in which
case this is identical to a free() call.

The error paths dealing with these two cases should be different,
but mostly weren't. Secondly the standard idiom for dealing with
realloc when you know the new size is non-zero is the following :

 tmp = realloc(p, size);
 if (!tmp) {
    SAFE_FREE(p);
    return error;
 } else {
    p = tmp;
 }

However, there were *many* *many* places in Samba where we were
using the old (broken) idiom of :

 p = realloc(p, size)
 if (!p) {
    return error;
 }

which will leak the memory pointed to by p on realloc fail.

This commit (hopefully) fixes all these cases by moving to
a standard idiom of :

 p = SMB_REALLOC(p, size)
 if (!p) {
    return error;
 }

Where if the realloc returns null due to the realloc failing
or size == 0 we *guarentee* that the storage pointed to by p
has been freed. This allows me to remove a lot of code that
was dealing with the standard (more verbose) method that required
a tmp pointer. This is almost always what you want. When a
realloc fails you never usually want the old memory, you
want to free it and get into your error processing asap.

For the 11 remaining cases where we really do need to keep the
old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR,
which can be used as follows :

 tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size);
 if (!tmp) {
    SAFE_FREE(p);
    return error;
 } else {
    p = tmp;
 }

SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the
pointer p, even on size == 0 or realloc fail. All this is
done by a hidden extra argument to Realloc(), BOOL free_old_on_error
which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR
macros (and their array counterparts).

It remains to be seen what this will do to our Coverity bug count :-).

Jeremy.
2007-10-10 11:10:59 -05:00