]>
Commit | Line | Data |
---|---|---|
825a14d8 | 1 | Index: mysql_conn.erl |
2 | =================================================================== | |
3 | --- mysql_conn.erl (revision 853) | |
4 | +++ mysql_conn.erl (working copy) | |
5 | @@ -64,6 +64,7 @@ | |
6 | %% External exports | |
7 | %%-------------------------------------------------------------------- | |
8 | -export([start/6, | |
9 | + start/7, | |
10 | start_link/6, | |
11 | fetch/3, | |
12 | fetch/4 | |
13 | @@ -96,12 +97,14 @@ | |
14 | ||
15 | %%-------------------------------------------------------------------- | |
16 | %% Function: start(Host, Port, User, Password, Database, LogFun) | |
17 | +%% Function: start(Host, Port, User, Password, Database, UserFlags, LogFun) | |
18 | %% Function: start_link(Host, Port, User, Password, Database, LogFun) | |
19 | %% Host = string() | |
20 | %% Port = integer() | |
21 | %% User = string() | |
22 | %% Password = string() | |
23 | %% Database = string() | |
24 | +%% UserFlags = list() | |
25 | %% LogFun = undefined | function() of arity 3 | |
26 | %% Descrip.: Starts a mysql_conn process that connects to a MySQL | |
27 | %% server, logs in and chooses a database. | |
28 | @@ -109,19 +112,21 @@ | |
29 | %% Pid = pid() | |
30 | %% Reason = string() | |
31 | %%-------------------------------------------------------------------- | |
32 | -start(Host, Port, User, Password, Database, LogFun) when is_list(Host), is_integer(Port), is_list(User), | |
33 | - is_list(Password), is_list(Database) -> | |
34 | +start(Host, Port, User, Password, Database, LogFun) -> | |
35 | + start(Host, Port, User, Password, Database, [], LogFun). | |
36 | +start(Host, Port, User, Password, Database, UserFlags, LogFun) when is_list(Host), is_integer(Port), is_list(User), | |
37 | + is_list(Password), is_list(Database), is_list(UserFlags) -> | |
38 | ConnPid = self(), | |
39 | Pid = spawn(fun () -> | |
40 | - init(Host, Port, User, Password, Database, LogFun, ConnPid) | |
41 | + init(Host, Port, User, Password, Database, UserFlags, LogFun, ConnPid) | |
42 | end), | |
43 | post_start(Pid, LogFun). | |
44 | ||
45 | start_link(Host, Port, User, Password, Database, LogFun) when is_list(Host), is_integer(Port), is_list(User), | |
46 | - is_list(Password), is_list(Database) -> | |
47 | + is_list(Password), is_list(Database) -> | |
48 | ConnPid = self(), | |
49 | Pid = spawn_link(fun () -> | |
50 | - init(Host, Port, User, Password, Database, LogFun, ConnPid) | |
51 | + init(Host, Port, User, Password, Database, [], LogFun, ConnPid) | |
52 | end), | |
53 | post_start(Pid, LogFun). | |
54 | ||
55 | @@ -220,13 +225,14 @@ | |
56 | %%==================================================================== | |
57 | ||
58 | %%-------------------------------------------------------------------- | |
59 | -%% Function: init(Host, Port, User, Password, Database, LogFun, | |
60 | +%% Function: init(Host, Port, User, Password, Database, UserFlags, LogFun, | |
61 | %% Parent) | |
62 | %% Host = string() | |
63 | %% Port = integer() | |
64 | %% User = string() | |
65 | %% Password = string() | |
66 | %% Database = string() | |
67 | +%% UserFlags = list() | |
68 | %% LogFun = undefined | function() of arity 3 | |
69 | %% Parent = pid() of process starting this mysql_conn | |
70 | %% Descrip.: Connect to a MySQL server, log in and chooses a database. | |
71 | @@ -234,10 +240,10 @@ | |
72 | %% we were successfull. | |
73 | %% Returns : void() | does not return | |
74 | %%-------------------------------------------------------------------- | |
75 | -init(Host, Port, User, Password, Database, LogFun, Parent) -> | |
76 | +init(Host, Port, User, Password, Database, UserFlags, LogFun, Parent) -> | |
77 | case mysql_recv:start_link(Host, Port, LogFun, self()) of | |
78 | {ok, RecvPid, Sock} -> | |
79 | - case mysql_init(Sock, RecvPid, User, Password, LogFun) of | |
80 | + case mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun) of | |
81 | {ok, Version} -> | |
82 | case do_query(Sock, RecvPid, LogFun, "use " ++ Database, Version) of | |
83 | {error, MySQLRes} -> | |
84 | @@ -309,16 +315,16 @@ | |
85 | %% Returns : ok | {error, Reason} | |
86 | %% Reason = string() | |
87 | %%-------------------------------------------------------------------- | |
88 | -mysql_init(Sock, RecvPid, User, Password, LogFun) -> | |
89 | +mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun) -> | |
90 | case do_recv(LogFun, RecvPid, undefined) of | |
91 | {ok, Packet, InitSeqNum} -> | |
92 | {Version, Salt1, Salt2, Caps} = greeting(Packet, LogFun), | |
93 | AuthRes = | |
94 | case Caps band ?SECURE_CONNECTION of | |
95 | ?SECURE_CONNECTION -> | |
96 | - mysql_auth:do_new_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, Salt1, Salt2, LogFun); | |
97 | + mysql_auth:do_new_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, UserFlags, Salt1, Salt2, LogFun); | |
98 | _ -> | |
99 | - mysql_auth:do_old_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, Salt1, LogFun) | |
100 | + mysql_auth:do_old_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, UserFlags, Salt1, LogFun) | |
101 | end, | |
102 | case AuthRes of | |
103 | {ok, <<0:8, _Rest/binary>>, _RecvNum} -> | |
104 | Index: mysql_auth.erl | |
105 | =================================================================== | |
106 | --- mysql_auth.erl (revision 853) | |
107 | +++ mysql_auth.erl (working copy) | |
108 | @@ -17,8 +17,8 @@ | |
109 | %% External exports (should only be used by the 'mysql_conn' module) | |
110 | %%-------------------------------------------------------------------- | |
111 | -export([ | |
112 | - do_old_auth/7, | |
113 | - do_new_auth/8 | |
114 | + do_old_auth/8, | |
115 | + do_new_auth/9 | |
116 | ]). | |
117 | ||
118 | %%-------------------------------------------------------------------- | |
119 | @@ -50,9 +50,9 @@ | |
120 | %% Descrip.: Perform old-style MySQL authentication. | |
121 | %% Returns : result of mysql_conn:do_recv/3 | |
122 | %%-------------------------------------------------------------------- | |
123 | -do_old_auth(Sock, RecvPid, SeqNum, User, Password, Salt1, LogFun) -> | |
124 | +do_old_auth(Sock, RecvPid, SeqNum, User, Password, UserFlags, Salt1, LogFun) -> | |
125 | Auth = password_old(Password, Salt1), | |
126 | - Packet2 = make_auth(User, Auth), | |
127 | + Packet2 = make_auth(User, Auth, UserFlags), | |
128 | do_send(Sock, Packet2, SeqNum, LogFun), | |
129 | mysql_conn:do_recv(LogFun, RecvPid, SeqNum). | |
130 | ||
131 | @@ -70,9 +70,9 @@ | |
132 | %% Descrip.: Perform MySQL authentication. | |
133 | %% Returns : result of mysql_conn:do_recv/3 | |
134 | %%-------------------------------------------------------------------- | |
135 | -do_new_auth(Sock, RecvPid, SeqNum, User, Password, Salt1, Salt2, LogFun) -> | |
136 | +do_new_auth(Sock, RecvPid, SeqNum, User, Password, UserFlags, Salt1, Salt2, LogFun) -> | |
137 | Auth = password_new(Password, Salt1 ++ Salt2), | |
138 | - Packet2 = make_new_auth(User, Auth, none), | |
139 | + Packet2 = make_new_auth(User, Auth, none, UserFlags), | |
140 | do_send(Sock, Packet2, SeqNum, LogFun), | |
141 | case mysql_conn:do_recv(LogFun, RecvPid, SeqNum) of | |
142 | {ok, Packet3, SeqNum2} -> | |
143 | @@ -104,8 +104,11 @@ | |
144 | end, L)). | |
145 | ||
146 | %% part of do_old_auth/4, which is part of mysql_init/4 | |
147 | -make_auth(User, Password) -> | |
148 | - Caps = ?LONG_PASSWORD bor ?LONG_FLAG bor ?TRANSACTIONS, | |
149 | +make_auth(User, Password, UserFlags) -> | |
150 | + Flags = lists:append(UserFlags, [?LONG_PASSWORD, ?LONG_FLAG, ?TRANSACTIONS]), | |
151 | + Caps = lists:foldl(fun(Flag, TCaps) when is_integer(Flag) -> | |
152 | + TCaps bor Flag | |
153 | + end, 0, Flags), | |
154 | Maxsize = 0, | |
155 | UserB = list_to_binary(User), | |
156 | PasswordB = Password, | |
157 | @@ -113,15 +116,19 @@ | |
158 | PasswordB/binary>>. | |
159 | ||
160 | %% part of do_new_auth/4, which is part of mysql_init/4 | |
161 | -make_new_auth(User, Password, Database) -> | |
162 | +make_new_auth(User, Password, Database, UserFlags) -> | |
163 | DBCaps = case Database of | |
164 | none -> | |
165 | 0; | |
166 | _ -> | |
167 | ?CONNECT_WITH_DB | |
168 | end, | |
169 | - Caps = ?LONG_PASSWORD bor ?LONG_FLAG bor ?TRANSACTIONS bor | |
170 | - ?PROTOCOL_41 bor ?SECURE_CONNECTION bor DBCaps, | |
171 | + | |
172 | + Flags = lists:append(UserFlags, [?LONG_PASSWORD, ?LONG_FLAG, ?TRANSACTIONS, ?PROTOCOL_41, ?SECURE_CONNECTION]), | |
173 | + Caps = lists:foldl(fun(Flag, TCaps) when is_integer(Flag) -> | |
174 | + TCaps bor Flag | |
175 | + end, DBCaps, Flags), | |
176 | + | |
177 | Maxsize = ?MAX_PACKET_SIZE, | |
178 | UserB = list_to_binary(User), | |
179 | PasswordL = size(Password), |