Jan-24-2022, 11:05 AM
(This post was last modified: Jan-24-2022, 11:05 AM by wardancer84.)
hi,
thanks for answering. you are right, this needs more explaination.
First, i use python-sudoers for parsing sudoers files.
So this is part of the procedure of parsing various aspects of a sudoers file into python structures.
wbr chris
thanks for answering. you are right, this needs more explaination.
First, i use python-sudoers for parsing sudoers files.
So this is part of the procedure of parsing various aspects of a sudoers file into python structures.
for key in sudo_obj.host_aliases: host_alias_list = [] host_alias_list.append((key, list(sudo_obj.host_aliases[key]))) results['hostalias'].append(host_alias_list)this ist the output from the parsing library and represents a complete sudoers files. i added items= tablenames for clarification.
[['aixacodbt']] = sudohost [[['root']]] = users [[['ALL']]] = hosts [[(['root'], ['ALL'], [{'run_as': ['ALL'], 'tags': None, 'command': 'ALL'}])]] = commandsthe next part prints out a complete insert statement...
qmarks = ",".join('?' * len(results)) qry = "INSERT INTO rules (%s) VALUES (%s)" % (qmarks, qmarks) qvals = *results.keys(), *results.values() qvals_stringed = ','.join(map(str, qvals)) print(type(qvals_stringed)) print(qry, qvals_stringed)
<class 'str'> INSERT INTO rules (?,?,?,?) VALUES (?,?,?,?) sudohost,users,hosts,commands,[['aixacodbt']],[[['root']]],[[['ALL']]],[[(['root'], ['ALL'], [{'run_as': ['ALL'], 'tags': None, 'command': 'ALL'}])]]updated original post with slightly modified script and outputs from a more simple sudoers file.
wbr chris