Bug 11613 - Samba-tool fsmo errors out if no fSMORoleOwner attribute found
Summary: Samba-tool fsmo errors out if no fSMORoleOwner attribute found
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Python (show other bugs)
Version: 4.3.1
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-23 18:39 UTC by Rowland Penny
Modified: 2020-12-11 12:31 UTC (History)
5 users (show)

See Also:


Attachments
make samba-tool fsmo print error message if no fSMORoleOwner attribute found (1.07 KB, patch)
2015-11-23 18:58 UTC, Rowland Penny
no flags Details
git-am fix for 4.3.next (1.39 KB, patch)
2015-12-06 18:19 UTC, Uri Simchoni
jra: review+
Details
Additional patch for v4-4-test (17.72 KB, patch)
2016-06-01 07:27 UTC, Stefan Metzmacher
jra: review+
metze: review? (abartlet)
Details
Additional patch for v4-3-test (17.72 KB, patch)
2016-06-01 07:28 UTC, Stefan Metzmacher
jra: review+
metze: review? (abartlet)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rowland Penny 2015-11-23 18:39:36 UTC
If, for whatever reason, a FSMO role has no fSMORoleOwner attribute, Samba-tool shows an 'uncaught exception'

i.e. 

samba-tool fsmo seize --role=all

ERROR(<type 'exceptions.KeyError'>): uncaught exception - 'No such element'
File "/usr/lib/python2.7/dist-packages/samba/netcmd/__init__.py", line 175, in _run
  return self.run(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.py", line 345, in run
  versionopts, force)
File "/usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.py", line 301, in seize_dns_role
  master_owner = get_fsmo_roleowner(samdb, m.dn)
File "/usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.py", line 42, in get_fsmo_roleowner
  master_owner = res[0]["fSMORoleOwner"][0]

This is caused by this code in fsmo.py:

def get_fsmo_roleowner(samdb, roledn):
    """Gets the owner of an FSMO role

    :param roledn: The DN of the FSMO role
    """
    res = samdb.search(roledn,
                       scope=ldb.SCOPE_BASE, attrs=["fSMORoleOwner"])
    assert len(res) == 1
    master_owner = res[0]["fSMORoleOwner"][0]
    return master_owner

As 'fSMORoleOwner' is a single-valued attribute, it can only exist or not, there cannot be more than one instance, so the last part of the above code should be:

    if len(res) == 0:
        raise Exception('"%s" does not have a FSMO roleowner' % roledn)
    master_owner = res[0]["fSMORoleOwner"][0]
    return master_owner

This will print a message and exit if there is no 'fSMORoleOwner' attribute found.

Patch to follow.
Comment 1 Rowland Penny 2015-11-23 18:58:33 UTC
Created attachment 11611 [details]
make samba-tool fsmo print error message if no fSMORoleOwner attribute found
Comment 2 Uri Simchoni 2015-12-06 18:19:01 UTC
Created attachment 11675 [details]
git-am fix for 4.3.next
Comment 3 Jeremy Allison 2015-12-08 19:17:26 UTC
Comment on attachment 11675 [details]
git-am fix for 4.3.next

LGTM.
Comment 4 Jeremy Allison 2015-12-08 19:17:49 UTC
Re-assigning to Karolin for inclusion in 4.3.next.
Comment 5 Karolin Seeger 2015-12-17 10:00:48 UTC
Pushed to autobuild-v4-3-test.
Comment 6 Karolin Seeger 2016-01-05 08:30:44 UTC
(In reply to Karolin Seeger from comment #5)
Pushed to v4-3-test.
Closing out bug report.

Thanks!
Comment 7 Stefan Metzmacher 2016-06-01 07:23:45 UTC
There're more fixes required...
Comment 8 Stefan Metzmacher 2016-06-01 07:27:55 UTC
Created attachment 12155 [details]
Additional patch for v4-4-test
Comment 9 Stefan Metzmacher 2016-06-01 07:28:22 UTC
Created attachment 12156 [details]
Additional patch for v4-3-test
Comment 10 Karolin Seeger 2016-06-01 07:46:59 UTC
Pushed additional patches to autobuild-v4-[4|3]-test.
Comment 11 Karolin Seeger 2016-06-01 07:48:34 UTC
(In reply to Karolin Seeger from comment #10)
Gnaaa, no review yet, removing and waiting for review first.
Comment 12 Karolin Seeger 2016-06-02 10:21:45 UTC
(In reply to Karolin Seeger from comment #11)
Pushed additional patches to autobuild-v4-[4|3]-test.
Comment 13 Karolin Seeger 2016-06-09 11:08:02 UTC
(In reply to Karolin Seeger from comment #12)
Pushed to both branches.
Closing out bug report.

Thanks!