1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import time
18 import sys
19 from rhn.connections import idn_puny_to_unicode
20
21 from spacewalk.common.rhnLog import log_debug
22 from spacewalk.common.rhnConfig import CFG
23 from spacewalk.common.rhnException import rhnFault
24 from spacewalk.common.rhnTranslate import _
25 from spacewalk.server.rhnHandler import rhnHandler
26 from spacewalk.server import rhnLib
27 from spacewalk.server import rhnSQL
28
29
31
32 """ Simple authentication based on hostname and configured slaves """
33
42
44 if CFG.DISABLE_ISS:
45 raise rhnFault(2005, _('ISS is disabled on this satellite.'))
46
47 if not rhnSQL.fetchone_dict("select 1 from rhnISSSlave where slave = :hostname and enabled = 'Y'",
48 hostname=idn_puny_to_unicode(self.remote_hostname)):
49 raise rhnFault(2004,
50 _('Server "%s" is not enabled for ISS.')
51 % self.remote_hostname)
52 return self.remote_hostname
53
54 - def check(self, system_id_ignored):
55 """xmlrpc authentication.
56 """
57 log_debug(3)
58
59
60 try:
61 self.auth_system()
62 except rhnFault:
63 e = sys.exc_info()[1]
64 if e.code == 2002:
65
66 return 0
67
68 raise
69
70 return 1
71
72
73 - def login(self, system_id, extra_data={}):
74 """Return a dictionary of session token/channel information.
75 Also sets this information in the headers.
76 """
77 log_debug(5, self.remote_hostname)
78
79 self.auth_system()
80
81
82 log_debug(1, self.remote_hostname)
83
84 rhnServerTime = str(time.time())
85 expireOffset = str(CFG.SATELLITE_AUTH_TIMEOUT)
86 signature = rhnLib.computeSignature(CFG.SECRET_KEY,
87 self.remote_hostname,
88 rhnServerTime,
89 expireOffset)
90
91 loginDict = {
92 'X-RHN-Server-Hostname': self.remote_hostname,
93 'X-RHN-Auth': signature,
94 'X-RHN-Auth-Server-Time': rhnServerTime,
95 'X-RHN-Auth-Expire-Offset': expireOffset,
96 }
97
98
99 log_debug(5, "loginDict", loginDict)
100
101 return loginDict
102