54 if args[0] == '--read-only': |
57 if args[0] == '--read-only': |
55 readonly = True |
58 readonly = True |
56 args.pop(0) |
59 args.pop(0) |
57 else: |
60 else: |
58 break |
61 break |
59 allowed_paths = [os.path.normpath(os.path.join(cwd, |
62 allowed_paths = [ |
60 os.path.expanduser(path))) |
63 os.path.normpath(os.path.join(cwd, os.path.expanduser(path))) |
61 for path in args] |
64 for path in args |
|
65 ] |
62 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?') |
66 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?') |
63 try: |
67 try: |
64 cmdargv = shlex.split(orig_cmd) |
68 cmdargv = shlex.split(orig_cmd) |
65 except ValueError as e: |
69 except ValueError as e: |
66 sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e)) |
70 sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e)) |
73 cmd = [b'-R', pycompat.fsencode(repo), b'serve', b'--stdio'] |
77 cmd = [b'-R', pycompat.fsencode(repo), b'serve', b'--stdio'] |
74 req = dispatch.request(cmd) |
78 req = dispatch.request(cmd) |
75 if readonly: |
79 if readonly: |
76 if not req.ui: |
80 if not req.ui: |
77 req.ui = uimod.ui.load() |
81 req.ui = uimod.ui.load() |
78 req.ui.setconfig(b'hooks', b'pretxnopen.hg-ssh', |
82 req.ui.setconfig( |
79 b'python:__main__.rejectpush', b'hg-ssh') |
83 b'hooks', |
80 req.ui.setconfig(b'hooks', b'prepushkey.hg-ssh', |
84 b'pretxnopen.hg-ssh', |
81 b'python:__main__.rejectpush', b'hg-ssh') |
85 b'python:__main__.rejectpush', |
|
86 b'hg-ssh', |
|
87 ) |
|
88 req.ui.setconfig( |
|
89 b'hooks', |
|
90 b'prepushkey.hg-ssh', |
|
91 b'python:__main__.rejectpush', |
|
92 b'hg-ssh', |
|
93 ) |
82 dispatch.dispatch(req) |
94 dispatch.dispatch(req) |
83 else: |
95 else: |
84 sys.stderr.write('Illegal repository "%s"\n' % repo) |
96 sys.stderr.write('Illegal repository "%s"\n' % repo) |
85 sys.exit(255) |
97 sys.exit(255) |
86 else: |
98 else: |
87 sys.stderr.write('Illegal command "%s"\n' % orig_cmd) |
99 sys.stderr.write('Illegal command "%s"\n' % orig_cmd) |
88 sys.exit(255) |
100 sys.exit(255) |
89 |
101 |
|
102 |
90 def rejectpush(ui, **kwargs): |
103 def rejectpush(ui, **kwargs): |
91 ui.warn((b"Permission denied\n")) |
104 ui.warn((b"Permission denied\n")) |
92 # mercurial hooks use unix process conventions for hook return values |
105 # mercurial hooks use unix process conventions for hook return values |
93 # so a truthy return means failure |
106 # so a truthy return means failure |
94 return True |
107 return True |
95 |
108 |
|
109 |
96 if __name__ == '__main__': |
110 if __name__ == '__main__': |
97 main() |
111 main() |