Created
January 14, 2014 12:03
-
-
Save ir4y/8417279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def checkAccess(target, flag): | |
| global user, groups | |
| if user == "root": | |
| return 1 | |
| try: | |
| return { | |
| 'owner': lambda u: 1 if target['owner'] == u else 0, | |
| 'group': lambda u: 1 if targer['group'] == u else 0, | |
| 'r': lambda u: 0, | |
| 'w': lambda u: 1, | |
| 'x': lambda u: 2}[flag](user) | |
| except KeyError: | |
| return 0 | |
| def translatePermission(arg): | |
| intperm_to_string = { | |
| "0": "---", | |
| "1": "--x", | |
| "2": "-w-", | |
| "3": "-wx", | |
| "4": "r--", | |
| "5": "r-x", | |
| "6": "rw-", | |
| "7": "rwx"} | |
| return ''.join(map(lambda u:intperm_to_string[u], arg[:3])) | |
| #(command, take args) | |
| commands = ( | |
| (cd, True), | |
| (ls, False), | |
| (mkdir, True), | |
| (touch, True), | |
| (su, True), | |
| (useradd, True), | |
| (groupadd, True), | |
| (chmod, True), | |
| (chown, True), | |
| (chgrp, True), | |
| (lsgr, False), | |
| (lsus, False), | |
| (saveJSON, False), | |
| (exit, False), ) | |
| call_dict = {com.__name__: (lambda flag: (lambda arg: | |
| com(arg) if flag | |
| else com()))(flag) | |
| for com, flag in commands} | |
| call_dict[com["com"](com["arg"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment