def BinarySIDtoStringSID(sid):
 if (not sid):
  return ''
 str_sid_components = [ord(sid[0])]
 if (len(sid) >= 8):
  subauthority_count = ord(sid[1])
  identifier_authority = struct.unpack('>H', sid[2:4])[0]
  identifier_authority <<= 32
  identifier_authority |= struct.unpack('>L', sid[4:8])[0]
  str_sid_components.append(identifier_authority)
  start = 8
  for i in range(subauthority_count):
   authority = sid[start:(start + 4)]
   if (not authority):
    break
   if (len(authority) < 4):
    raise ValueError("In binary SID '%s', component %d has been truncated. Expected 4 bytes, found %d: (%s)", ','.join([str(ord(c)) for c in sid]), i, len(authority), authority)
   str_sid_components.append(struct.unpack('<L', authority)[0])
   start += 4
 return ('S-%s' % '-'.join([str(x) for x in str_sid_components]))

def BinarySIDtoStringSID ( sid ) : if ( not sid ) : return '' str_sid_components = [ ord ( sid [ 0 ] ) ] if ( len ( sid ) >= 8 ) : subauthority_count = ord ( sid [ 1 ] ) identifier_authority = struct . unpack ( '>H' , sid [ 2 : 4 ] ) [ 0 ] identifier_authority <<= 32 identifier_authority |= struct . unpack ( '>L' , sid [ 4 : 8 ] ) [ 0 ] str_sid_components . append ( identifier_authority ) start = 8 for i in range ( subauthority_count ) : authority = sid [ start : ( start + 4 ) ] if ( not authority ) : break if ( len ( authority ) < 4 ) : raise ValueError ( "In binary SID '%s', component %d has been truncated. Expected 4 bytes, found %d: (%s)" , ',' . join ( [ str ( ord ( c ) ) for c in sid ] ) , i , len ( authority ) , authority ) str_sid_components . append ( struct . unpack ( '<L' , authority ) [ 0 ] ) start += 4 return ( 'S-%s' % '-' . join ( [ str ( x ) for x in str_sid_components ] ) )
converts a binary sid to its string representation .