By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

readlines and break apart based on letters

P: n/a
Hi,

While trying to better understand security descriptors on Windows. I've
been examining text-based security descriptors. I have the security
descriptors on individual lines stored in a text file. I want to break
these lines apart based on owner, group, dacl and sacl. These areas are
demarcated by O: G: D: and S:

There are no spaces in the lines. How can I read each line so that each
area is broken out? I'd like output like this:

O: details
G: details or NONE
D: details or NONE
S: details or NONE

Here is an example SD:
O:owner_sidG:group_sidD:dacl_flags(string_ace1)(st ring_ace2)...(string_acen)S:sacl_flags(string_ace1 )(string_ace2)...(string_acen)

I want to read this and break it apart like this:
O:owner_sid
G:group_sid
D:dacl_flags(string_ace1)(string_ace2)...(string_a cen)
S:sacl_flags(string_ace1)(string_ace2)...(string_a cen)

Any tips?
Brad

Feb 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I got this to work... just FYI:

s =
'O:owner_sidG:group_sidD:dacl_flags(string_ace1)(s tring_ace2)...(string_acen)S:sacl_flags(string_ace 1)(string_ace2)...(string_acen)'

SD = {}

S = str.split(s, 'S:')
SD['S_ACL'] = S[1]
D = str.split(S[0], 'D:')
SD['D_ACL'] = D[1]
G = str.split(D[0], 'G:')
SD['G_SID'] = G[1]
O = str.split(G[0], 'O:')
SD['O_SID'] = O[1]

for k,v in SD.iteritems():
print k,v
Feb 14 '06 #2

P: n/a
rtilley wrote:
Hi,

While trying to better understand security descriptors on Windows. I've
been examining text-based security descriptors. I have the security
descriptors on individual lines stored in a text file. I want to break
these lines apart based on owner, group, dacl and sacl. These areas are
demarcated by O: G: D: and S:

There are no spaces in the lines. How can I read each line so that each
area is broken out? I'd like output like this:

O: details
G: details or NONE
D: details or NONE
S: details or NONE

Here is an example SD:
O:owner_sidG:group_sidD:dacl_flags(string_ace1)(st ring_ace2)...(string_acen)S:sacl_flags(string_ace1 )(string_ace2)...(string_acen)


It's a pretty simple regex:
import re
s='O:owner_sidG:group_sidD:dacl_flags(string_ace1) (string_ace2)...(string_acen)S:sacl_flags(string_a ce1)(string_ace2)...(string_acen)'
m=re.search(r'O:(.*?)G:(.*?)D:(.*?)S:(.*)', s)
m.group(1,2,3,4)

('owner_sid', 'group_sid',
'dacl_flags(string_ace1)(string_ace2)...(string_ac en)',
'sacl_flags(string_ace1)(string_ace2)...(string_ac en)')
Feb 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.