]>
Commit | Line | Data |
---|---|---|
825a14d8 | 1 | Index: mysql_conn.erl |
2 | =================================================================== | |
290990cb | 3 | --- mysql_conn.erl (revision 861) |
825a14d8 | 4 | +++ mysql_conn.erl (working copy) |
5 | @@ -64,6 +64,7 @@ | |
6 | %% External exports | |
7 | %%-------------------------------------------------------------------- | |
8 | -export([start/6, | |
290990cb | 9 | + start/7, |
825a14d8 | 10 | start_link/6, |
11 | fetch/3, | |
290990cb | 12 | fetch/4, |
13 | @@ -99,12 +100,14 @@ | |
825a14d8 | 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. | |
290990cb | 28 | @@ -112,11 +115,13 @@ |
825a14d8 | 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), | |
290990cb | 37 | + is_list(Password), is_list(Database), is_list(UserFlags) -> |
825a14d8 | 38 | ConnPid = self(), |
39 | Pid = spawn(fun () -> | |
40 | - init(Host, Port, User, Password, Database, LogFun, ConnPid) | |
290990cb | 41 | + init(Host, Port, User, Password, Database, UserFlags, LogFun, ConnPid) |
825a14d8 | 42 | end), |
43 | post_start(Pid, LogFun). | |
44 | ||
290990cb | 45 | @@ -124,7 +129,7 @@ |
46 | is_list(Password), is_list(Database) -> | |
825a14d8 | 47 | ConnPid = self(), |
48 | Pid = spawn_link(fun () -> | |
49 | - init(Host, Port, User, Password, Database, LogFun, ConnPid) | |
50 | + init(Host, Port, User, Password, Database, [], LogFun, ConnPid) | |
51 | end), | |
52 | post_start(Pid, LogFun). | |
53 | ||
290990cb | 54 | @@ -243,6 +248,7 @@ |
825a14d8 | 55 | %% User = string() |
56 | %% Password = string() | |
57 | %% Database = string() | |
58 | +%% UserFlags = list() | |
59 | %% LogFun = undefined | function() of arity 3 | |
60 | %% Parent = pid() of process starting this mysql_conn | |
61 | %% Descrip.: Connect to a MySQL server, log in and chooses a database. | |
290990cb | 62 | @@ -250,10 +256,10 @@ |
825a14d8 | 63 | %% we were successfull. |
64 | %% Returns : void() | does not return | |
65 | %%-------------------------------------------------------------------- | |
66 | -init(Host, Port, User, Password, Database, LogFun, Parent) -> | |
67 | +init(Host, Port, User, Password, Database, UserFlags, LogFun, Parent) -> | |
68 | case mysql_recv:start_link(Host, Port, LogFun, self()) of | |
69 | {ok, RecvPid, Sock} -> | |
70 | - case mysql_init(Sock, RecvPid, User, Password, LogFun) of | |
71 | + case mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun) of | |
72 | {ok, Version} -> | |
290990cb | 73 | case do_query(Sock, RecvPid, LogFun, "use " ++ Database, Version, [{result_type, binary}]) of |
825a14d8 | 74 | {error, MySQLRes} -> |
290990cb | 75 | @@ -318,7 +324,7 @@ |
76 | end. | |
77 | ||
78 | %%-------------------------------------------------------------------- | |
79 | -%% Function: mysql_init(Sock, RecvPid, User, Password, LogFun) | |
80 | +%% Function: mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun) | |
81 | %% Sock = term(), gen_tcp socket | |
82 | %% RecvPid = pid(), mysql_recv process | |
83 | %% User = string() | |
84 | @@ -328,16 +334,16 @@ | |
825a14d8 | 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 | =================================================================== | |
290990cb | 106 | --- mysql_auth.erl (revision 861) |
825a14d8 | 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 | %%-------------------------------------------------------------------- | |
290990cb | 119 | @@ -51,9 +51,9 @@ |
825a14d8 | 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 | ||
290990cb | 131 | @@ -71,9 +71,9 @@ |
825a14d8 | 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} -> | |
290990cb | 143 | @@ -105,9 +105,11 @@ |
825a14d8 | 144 | end, L)). |
145 | ||
146 | %% part of do_old_auth/4, which is part of mysql_init/4 | |
147 | -make_auth(User, Password) -> | |
290990cb | 148 | - Caps = ?LONG_PASSWORD bor ?LONG_FLAG |
149 | - bor ?TRANSACTIONS bor ?FOUND_ROWS, | |
825a14d8 | 150 | +make_auth(User, Password, UserFlags) -> |
290990cb | 151 | + Flags = lists:append(UserFlags, [?LONG_PASSWORD, ?LONG_FLAG, ?TRANSACTIONS, ?FOUND_ROWS]), |
825a14d8 | 152 | + Caps = lists:foldl(fun(Flag, TCaps) when is_integer(Flag) -> |
153 | + TCaps bor Flag | |
154 | + end, 0, Flags), | |
155 | Maxsize = 0, | |
156 | UserB = list_to_binary(User), | |
157 | PasswordB = Password, | |
290990cb | 158 | @@ -115,16 +117,18 @@ |
825a14d8 | 159 | PasswordB/binary>>. |
160 | ||
161 | %% part of do_new_auth/4, which is part of mysql_init/4 | |
162 | -make_new_auth(User, Password, Database) -> | |
163 | +make_new_auth(User, Password, Database, UserFlags) -> | |
164 | DBCaps = case Database of | |
165 | none -> | |
166 | 0; | |
167 | _ -> | |
168 | ?CONNECT_WITH_DB | |
169 | end, | |
170 | - Caps = ?LONG_PASSWORD bor ?LONG_FLAG bor ?TRANSACTIONS bor | |
290990cb | 171 | - ?PROTOCOL_41 bor ?SECURE_CONNECTION bor DBCaps |
172 | - bor ?FOUND_ROWS, | |
825a14d8 | 173 | + |
290990cb | 174 | + Flags = lists:append(UserFlags, [?LONG_PASSWORD, ?LONG_FLAG, ?TRANSACTIONS, ?PROTOCOL_41, ?SECURE_CONNECTION, DBCaps, ?FOUND_ROWS]), |
825a14d8 | 175 | + Caps = lists:foldl(fun(Flag, TCaps) when is_integer(Flag) -> |
176 | + TCaps bor Flag | |
177 | + end, DBCaps, Flags), | |
825a14d8 | 178 | Maxsize = ?MAX_PACKET_SIZE, |
179 | UserB = list_to_binary(User), | |
180 | PasswordL = size(Password), |