sshproxy-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sshproxy-dev] Changes to sshproxy/SSHproxy/pwdb/mysql.py


From: Pierre-Yves Rofes
Subject: [sshproxy-dev] Changes to sshproxy/SSHproxy/pwdb/mysql.py
Date: Fri, 23 Sep 2005 11:35:47 -0400

Index: sshproxy/SSHproxy/pwdb/mysql.py
diff -u sshproxy/SSHproxy/pwdb/mysql.py:1.2 sshproxy/SSHproxy/pwdb/mysql.py:1.3
--- sshproxy/SSHproxy/pwdb/mysql.py:1.2 Thu Sep 22 08:58:31 2005
+++ sshproxy/SSHproxy/pwdb/mysql.py     Fri Sep 23 15:35:45 2005
@@ -33,6 +33,7 @@
 
 class MySQLPwDB(simple.SimplePwDB):
     def __init__(self):
+        self.db = db
         q_sites = """
             select id, name, ip_address, port, location
                 from site order by name
@@ -56,10 +57,63 @@
                                               port=port,
                                               location=location,
                                               user_list=user_list))
+           #print 'site ' + name + ' grants access to ' + user_list.__repr__()
 
         simple.SimplePwDB.__init__(self, site_list)
-        db.close()
-
-
 
+    #def __del__(self):
+    #    db.close()
 
+    def get_site(self, sid):
+        user = None
+       if sid.find('@') >= 0:
+           user, sid = sid.split('@')
+        if not user:
+            q_user = """
+            select uid from site,user where site.id = user.site_id and 
site.name = '%s'
+ order by `primary` desc limit 1            
+"""
+            users = db.cursor()
+            users.execute(q_user % sid)
+            user = users.fetchone()
+            if not user or not len(user):
+                return None, None
+            user = user[0]
+            users.close()
+       if not self.can_connect(user, sid):
+           print 'User \'%s\' is not allowed to connect to \'%s\'' % (user, 
sid)
+            return None, None
+       return self.sites[sid].default_user(), self.sites[sid]
+
+    def is_allowed(self, user, passwd):
+        q_access = """
+        select count(*) from login where uid = '%s' and `password` = '%s'"""
+        logins = db.cursor()
+        logins.execute(q_access % (user, passwd))
+        login = logins.fetchone()[0]
+        logins.close()
+        if login:
+            self.login = user
+       return login
+       
+    def can_connect(self, user, site):
+        q_group = """
+        select count(*) 
+        from 
login,login_profile,profile,profile_sgroup,sgroup,sgroup_site,site,user 
+        where login.uid = '%s' 
+          and login.id = login_profile.login_id 
+          and login_profile.profile_id = profile.id 
+          and profile.id = profile_sgroup.profile_id 
+          and profile_sgroup.sgroup_id = sgroup.id
+          and sgroup.id = sgroup_site.sgroup_id
+          and sgroup_site.site_id = site.id
+          and site.name = '%s'
+          and user.site_id = site.id
+          and user.uid = '%s'  
+        """
+       group = db.cursor()
+       group.execute(q_group % (self.login, site, user))
+       gr = group.fetchone()[0]
+        print 'requete can_connect: %d' % gr
+       group.close()
+       return gr




reply via email to

[Prev in Thread] Current Thread [Next in Thread]