Univention Bugzilla – Attachment 4691 Details for
Bug 28496
endless loop in modules/univention/admin/handlers/users/user.py # logonHoursUnmap()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix logonHoursMap and logonHoursUnMap
28496_samba-logonhour.diff (text/plain), 3.65 KB, created by
Philipp Hahn
on 2012-09-28 09:50:05 CEST
(
hide
)
Description:
Fix logonHoursMap and logonHoursUnMap
Filename:
MIME Type:
Creator:
Philipp Hahn
Created:
2012-09-28 09:50:05 CEST
Size:
3.65 KB
patch
obsolete
>diff --git a/branches/ucs-3.1/ucs/management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py b/branches/ucs-3.1/ucs/management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py >index 5ff0b4f..7eee99b 100644 >--- a/branches/ucs-3.1/ucs/management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py >+++ b/branches/ucs-3.1/ucs/management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py >@@ -1008,77 +1008,28 @@ def sambaWorkstationsUnmap(workstations): > return string.split(workstations[0],',') > > def logonHoursMap(logontimes): >- "converts the bitfield 001110010110...100 to the respective string" >- >- # convert list of bit numbers to bit-string >- # bitstring = '0' * 168 >- bitstring = ''.join( map( lambda x: x in logontimes and '1' or '0', range( 168 ) ) ) >- >- # for idx in logontimes: >- # bitstring[ idx ] = '1' >- >- logontimes = bitstring >- >+ """Converts array of bits set to an hex-string.""" >+ octets = [0] * (24 * 7 / 8) > # the order of the bits of each byte has to be reversed. The reason for this is that >- # consecutive bytes mean consecutive 8-hrs-intervals, but the leftmost bit stands for >- # the last hour in that interval, the 2nd but leftmost bit for the second-but-last >+ # consecutive bytes mean consecutive 8-hrs-intervals, but the MSB stands for >+ # the last hour in that interval, the 2nd leftmost bit for the second-to-last > # hour and so on. We want to hide this from anybody using this feature. >- # See http://ma.ph-freiburg.de/tng/tng-technical/2003-04/msg00015.html for details. >- >- newtimes = "" >- for i in range(0,21): >- bitlist=list(logontimes[(i*8):(i*8)+8]) >- bitlist.reverse() >- newtimes+="".join(bitlist) >- logontimes = newtimes >- >- # create a hexnumber from each 8-bit-segment >- ret="" >- for i in range(0,21): >- val=0 >- exp=7 >- for j in range((i*8), (i*8)+8): >- if not (logontimes[j]=="0"): >- val+=2**exp >- exp-=1 >- # we now have: 0<=val<=255 >- hx=hex(val)[2:4] >- if len(hx)==1: hx="0"+hx >- ret+=hx >- >- return ret >+ # See <http://ma.ph-freiburg.de/tng/tng-technical/2003-04/msg00015.html> for details. >+ for hour in logontimes: >+ idx, bit = divmod(hour, 8) >+ octets[idx] |= 1 << bit >+ return ''.join(['%02x' % _ for _ in octets]) > > def logonHoursUnmap(logontimes): >- "converts the string to a bit array" >- >- times=logontimes[0][:42] >- while len(times)<42: >- times=times >- ret="" >- for i in range(0,42,2): >- val=int(times[i:i+2],16) >- ret+=intToBinary(val) >- >- # reverse order of the bits in each byte. See above for details >- newtime = "" >- for i in range(0, 21): >- bitlist=list(ret[(i*8):(i*8)+8]) >- bitlist.reverse() >- newtime+="".join(bitlist) >- >- # convert bit-string to list >- return filter( lambda i: newtime[ i ] == '1', range( 168 ) ) >- >-def intToBinary(val): >- ret="" >- while val>0: >- ret=str(val&1)+ret >- val=val>>1 >- # pad with leading 0s until length is n*8 >- if ret=="": ret="0" >- while not (len(ret)%8==0): >- ret="0"+ret >- return ret >+ """Converts hex-string to an array of bits set.""" >+ times = logontimes[0].ljust(42, '0')[:42] >+ assert len(times) == 24 * 7 / 4 >+ octets = [int(times[i : i + 2], 16) for i in range(0, len(times), 2)] >+ assert len(octets) == 24 * 7 / 8 >+ return [idx * 8 + bit >+ for (idx, value) in enumerate(octets) >+ for bit in range(8) >+ if value & (1 << bit)] > > def GMTOffset(): > # returns the difference in hours between local time and GMT (is -1 for CET and CEST)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 28496
: 4691