Bug 42131 - Reset counter for usernames only possible via ldapmodify for import interface
Reset counter for usernames only possible via ldapmodify for import interface
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.1 R2
Other Linux
: P5 normal (vote)
: UCS@school 4.4 v2
Assigned To: Daniel Tröder
Ole Schwiegert
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-08-25 15:54 CEST by Michel Smidt
Modified: 2019-04-01 00:44 CEST (History)
6 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 2: Improvement: Would be a product improvement
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.046
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Usability, Workaround is available
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michel Smidt 2016-08-25 15:54:42 CEST
According to Feedback on Ticket#2016082421000167 related to the Import-Interface. 

The customer asked for a possibility to reset the counter variables for usernames to 0. He was aware of the functionality of the counters but tested around and would like to reset the counters to 0 to going productive.
I think a UDM-Module for it would be sufficient. Than everyone who wants to reset the counter in  cn=usernameXY,cn=unique-usernames,cn=ucsschool,cn=univention,dc=ldapXY,dc=baseXY can do it at one's own risk. Currently it is only possible via ldapmodify.
Comment 1 Florian Best univentionstaff 2017-06-28 14:56:41 CEST
There is a Customer ID set so I set the flag "School Customer affected".
Comment 2 Valentin Heidelberger univentionstaff 2018-10-22 17:15:20 CEST
Very quick and dirty workaround I used at a customers site.

They did one import, none of the users had logged in so far, and realized that the username scheme was wrong. A second import still resulted in a few duplicates so we did this:


To get the DNs of all unique usernames without LDAP base (in the customers environment the DNs were too long (more than one line) with their base): 

univention-ldapsearch | grep "cn=unique-usernames,cn=ucsschool,cn=univention" | sed 's/dn: //' | sed 's/,dc.*//' | tail -n +2 



To remove all unique usernames:

for i in $(univention-ldapsearch | grep "cn=unique-usernames,cn=ucsschool,cn=univention" | sed 's/dn: //' | sed 's/,dc.*//' | tail -n +2 ); do ldapdelete -D "uid=<ADMIN USER>,cn=users,$(ucr get ldap/base)" -w <PASSWORD> -h localhost -p 7389 "${i},$(ucr get ldap/base)"; done
Comment 3 Daniel Tröder univentionstaff 2018-10-23 09:04:46 CEST
The subtree to search can be set with "-b" and to only search below it (not include the root itself) set the scope (-s): "-s children". To remove the line wrap pipe through ldapsearch-wrapper. As last arguments supply the attributes you want shown (here only "dn"). "-LLL" to remove metadata and statistics:

univention-ldapsearch -LLL -s children -b "cn=unique-usernames,cn=ucsschool,cn=univention,$(ucr get ldap/base)" dn | ldapsearch-wrapper | grep . | cut -d ' ' -f 2

ldapdelete takes a list of DNs as last arguments, so it can be called with all DNs at once, instead of starting it n times. Use "-y" to make it read from a file (if you're on the master and can use cn=admin):

ldapdelete -x -D "cn=admin,$(ucr get ldap/base)" -y /etc/ldap.secret -h localhost -p 7389 $(univention-ldapsearch -LLL -s children -b "cn=unique-usernames,cn=ucsschool,cn=univention,$(ucr get ldap/base)" dn | ldapsearch-wrapper | grep . | cut -d ' ' -f 2)
Comment 4 Sönke Schwardt-Krummrich univentionstaff 2018-11-05 10:42:21 CET
(In reply to Daniel Tröder from comment #3)
> ldapdelete -x -D "cn=admin,$(ucr get ldap/base)" -y /etc/ldap.secret -h
> localhost -p 7389 $(univention-ldapsearch -LLL -s children -b
> "cn=unique-usernames,cn=ucsschool,cn=univention,$(ucr get ldap/base)" dn |
> ldapsearch-wrapper | grep . | cut -d ' ' -f 2)

This might be error prone if the base DN contains whitespace. Improved suggestion:

export IFS=$'\n'
ldapdelete -x -D "cn=admin,$(ucr get ldap/base)" -y /etc/ldap.secret \
  -h $(ucr get ldap/master) -p 7389  \
  $(univention-ldapsearch -LLL -o ldif-wrap=no -s children \
   -b "cn=ucsschool,cn=univention,$(ucr get ldap/base)" dn | sed -nre 's/dn: //p')
Comment 5 Sönke Schwardt-Krummrich univentionstaff 2019-01-28 12:43:18 CET
I implemented a script for a customer, to be able to modify existing counters.
Comment 6 Daniel Tröder univentionstaff 2019-03-12 15:00:06 CET
# /usr/share/ucs-school-import/scripts/reset_username_counter --help
usage: reset_username_counter [-h] [-e] [-p PATTERN] [-w]

UCS@school import unique username/email purge tool

optional arguments:
  -h, --help            show this help message and exit
  -e, --email           Purge unique email address counters instead of
                        usernames [default: False].
  -p PATTERN, --pattern PATTERN
                        Pattern for LDAP filter to lookup username / email
                        address counters to purge [default: *].
  -w, --write           Modify the LDAP. Default is False: make a dry-run.

--------------------------------------------------------------------------

[4.4] 76d0fe4ba Bug #42131: add script to purge username and email counter

ucs-school-import (17.0.5-3)
Comment 7 Daniel Tröder univentionstaff 2019-03-13 10:44:55 CET
The script was renamed to "reset_schema_counter".

[4.4] de870673c Bug #42131: rename counter putrge script
ucs-school-import (17.0.5-4)
Comment 8 Ole Schwiegert univentionstaff 2019-03-18 10:58:26 CET
Changelog: Typo putrge -> purge
Advisory: missing
Package installs: OK
Script exists and working: OK
Comment 9 Daniel Tröder univentionstaff 2019-03-19 10:36:49 CET
Fixed the changelog and added an advisory.

[4.4 ce23e9cd4] Bug #42131: advisory
Comment 10 Ole Schwiegert univentionstaff 2019-03-20 10:59:31 CET
Changelog: OK
Advisory: name of script fixed: OK
Comment 11 Sönke Schwardt-Krummrich univentionstaff 2019-04-01 00:44:11 CEST
UCS@school 4.4 v2 has been released.

https://docs.software-univention.de/changelog-ucsschool-4.4v2-de.html

If this error occurs again, please clone this bug.