tests/krb5: Add tests for constrained delegation to NO_AUTH_DATA_REQUIRED service
[Samba.git] / python / samba / common.py
bloba8faa90065da53c0f4ebed795139f10ab0fbd069
1 # Samba common functions
3 # Copyright (C) Matthieu Patou <mat@matws.net>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from samba.compat import PY3
22 if PY3:
23 # cmp() exists only in Python 2
24 def cmp(a, b):
25 return (a > b) - (a < b)
27 raw_input = input
30 def confirm(msg, forced=False, allow_all=False):
31 """confirm an action with the user
33 :param msg: A string to print to the user
34 :param forced: Are the answer forced
35 """
36 if forced:
37 print("%s [YES]" % msg)
38 return True
40 mapping = {
41 'Y': True,
42 'YES': True,
43 '': False,
44 'N': False,
45 'NO': False,
48 prompt = '[y/N]'
50 if allow_all:
51 mapping['ALL'] = 'ALL'
52 mapping['NONE'] = 'NONE'
53 prompt = '[y/N/all/none]'
55 while True:
56 v = raw_input(msg + ' %s ' % prompt)
57 v = v.upper()
58 if v in mapping:
59 return mapping[v]
60 print("Unknown response '%s'" % v)
63 def normalise_int32(ivalue):
64 '''normalise a ldap integer to signed 32 bit'''
65 if int(ivalue) & 0x80000000 and int(ivalue) > 0:
66 return str(int(ivalue) - 0x100000000)
67 return str(ivalue)