3 * Copyright (C)2007-2008 Versabanq Innovations Inc. and contributors.
4 * See the included file named LICENSE for license information.
7 using System
.Data
.Common
;
8 using System
.Collections
;
9 using System
.Collections
.Generic
;
14 public static class VxSqlPool
16 private static WvIni inifile
;
18 public static void SetIniFile(string path
)
20 if (path
.e() || !File
.Exists(path
))
22 (wv
.fmt("Could not find config file '{0}'", path
));
23 inifile
= new WvIni(path
);
26 private static string find_connection_moniker(string connid
)
28 // At the moment, a connection ID is just a username
29 string dbname
= inifile
.get("User Map", connid
);
31 dbname
= inifile
.get("User Map", "*"); // try default
33 throw new VxConfigException(
34 String
.Format("No user '{0}' found.",
37 string cfgval
= inifile
.get("Connections", dbname
);
39 throw new VxConfigException(String
.Format(
40 "No connection found for user {0}", connid
));
45 public static string GetUsernameForCert(string cert
)
47 string username
= inifile
.get("Cert Map", cert
);
49 throw new VxConfigException(String
.Format(
50 "No user found for cert with fingerprint '{0}'.", cert
));
55 static Dictionary
<string, int> userpermissions
=
56 new Dictionary
<string, int>();
58 public static int access_restrictions(string connid
)
61 if (!userpermissions
.TryGetValue(connid
, out security_level
))
63 string iniseclevel
= inifile
.get("Security Level", connid
);
65 // If we found *nothing* perhaps we should evaluate a judgement
66 // on security, see if '*' has values... assuming we're not
67 // already looking for '*''s security.
68 if (iniseclevel
== null)
73 iniseclevel
= inifile
.get("Security Level", "*");
75 if (iniseclevel
!= null &&
76 (iniseclevel
== "0" ||
78 security_level
= Convert
.ToInt32(iniseclevel
);
82 security_level
= !(iniseclevel
== "0" ||
83 iniseclevel
== "1") ? 2 :
84 Convert
.ToInt32(iniseclevel
);
86 userpermissions
[connid
] = security_level
;
88 return security_level
;
91 public static WvDbi
create(string connid
)
95 return WvDbi
.create(find_connection_moniker(connid
));
99 throw new VxConfigException("Connect: " + e
.Message
);