Преглед изворни кода

chore: sync ce code added only to ee back to ce

Zaiming Shi пре 4 година
родитељ
комит
325c5e5a97

+ 1 - 1
apps/emqx_auth_pgsql/rebar.config

@@ -1,5 +1,5 @@
 {deps,
- [{epgsql, {git, "https://github.com/epgsql/epgsql", {tag, "4.4.0"}}}
+ [{epgsql, {git, "https://github.com/epgsql/epgsql.git", {tag, "4.4.0"}}}
  ]}.
 
 {erl_opts, [warn_unused_vars,

+ 1 - 1
apps/emqx_exproto/src/emqx_exproto.app.src

@@ -1,6 +1,6 @@
 {application, emqx_exproto,
  [{description, "EMQ X Extension for Protocol"},
-  {vsn, "4.3.2"}, %% strict semver
+  {vsn, "4.3.3"}, %% strict semver
   {modules, []},
   {registered, []},
   {mod, {emqx_exproto_app, []}},

+ 6 - 8
apps/emqx_exproto/src/emqx_exproto.appup.src

@@ -1,12 +1,11 @@
 %% -*-: erlang -*-
 {VSN,
  [
-    {"4.3.1", [
-      {load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []},
-      {load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []},
+    {"4.3.2", [
+      {load_module, emqx_exproto_conn, brutal_purge, soft_purge, []},
       {load_module, emqx_exproto_channel, brutal_purge, soft_purge, []}
     ]},
-    {"4.3.0", [
+    {<<"4.3.[0-1]">>, [
       {load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []},
       {load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []},
       {load_module, emqx_exproto_conn, brutal_purge, soft_purge, []},
@@ -15,12 +14,11 @@
     {<<".*">>, []}
  ],
  [
-    {"4.3.1", [
-      {load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []},
-      {load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []},
+    {"4.3.2", [
+      {load_module, emqx_exproto_conn, brutal_purge, soft_purge, []},
       {load_module, emqx_exproto_channel, brutal_purge, soft_purge, []}
     ]},
-    {"4.3.0", [
+    {<<"4.3.[0-1]">>, [
       {load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []},
       {load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []},
       {load_module, emqx_exproto_conn, brutal_purge, soft_purge, []},

+ 22 - 8
apps/emqx_exproto/src/emqx_exproto_channel.erl

@@ -94,6 +94,9 @@
          awaiting_rel_max
         ]).
 
+-define(CHANMOCK(P), {exproto_anonymous_client, P}).
+-define(CHAN_CONN_TAB, emqx_channel_conn).
+
 %%--------------------------------------------------------------------
 %% Info, Attrs and Caps
 %%--------------------------------------------------------------------
@@ -155,13 +158,20 @@ init(ConnInfo = #{socktype := Socktype,
                        conn_state = connecting,
                        timers = #{}
                       },
-
-    Req = #{conninfo =>
-            peercert(Peercert,
-                     #{socktype => socktype(Socktype),
-                       peername => address(Peername),
-                       sockname => address(Sockname)})},
-    try_dispatch(on_socket_created, wrap(Req), Channel).
+    %% Check license limitation
+    case emqx_hooks:run_fold('client.connect', [NConnInfo], #{}) of
+        {error, _Reason} ->
+            throw(nopermission);
+        _ ->
+            ConnMod = maps:get(conn_mod, NConnInfo),
+            true = ets:insert(?CHAN_CONN_TAB, {?CHANMOCK(self()), ConnMod}),
+            Req = #{conninfo =>
+                    peercert(Peercert,
+                             #{socktype => socktype(Socktype),
+                               peername => address(Peername),
+                               sockname => address(Sockname)})},
+            try_dispatch(on_socket_created, wrap(Req), Channel)
+    end.
 
 %% @private
 peercert(NoSsl, ConnInfo) when NoSsl == nossl;
@@ -283,6 +293,7 @@ handle_call({auth, ClientInfo0, Password},
                 emqx_metrics:inc('client.auth.anonymous'),
             NClientInfo = maps:merge(ClientInfo1, AuthResult),
             NChannel = Channel1#channel{clientinfo = NClientInfo},
+            clean_anonymous_clients(),
             case emqx_cm:open_session(true, NClientInfo, NConnInfo) of
                 {ok, _Session} ->
                     ?LOG(debug, "Client ~s (Username: '~s') authorized successfully!",
@@ -399,12 +410,16 @@ handle_info(Info, Channel) ->
 
 -spec(terminate(any(), channel()) -> channel()).
 terminate(Reason, Channel) ->
+    clean_anonymous_clients(),
     Req = #{reason => stringfy(Reason)},
     try_dispatch(on_socket_closed, wrap(Req), Channel).
 
 is_anonymous(#{anonymous := true}) -> true;
 is_anonymous(_AuthResult)          -> false.
 
+clean_anonymous_clients() ->
+    ets:delete(?CHAN_CONN_TAB, ?CHANMOCK(self())).
+
 %%--------------------------------------------------------------------
 %% Sub/UnSub
 %%--------------------------------------------------------------------
@@ -577,7 +592,6 @@ default_conninfo(ConnInfo) ->
     ConnInfo#{clean_start => true,
               clientid => undefined,
               username => undefined,
-              conn_mod => undefined,
               conn_props => #{},
               connected => true,
               connected_at => erlang:system_time(millisecond),

+ 5 - 1
apps/emqx_exproto/src/emqx_exproto_conn.erl

@@ -233,7 +233,11 @@ init(Parent, WrappedSock, Peername0, Options) ->
     case esockd_wait(WrappedSock) of
         {ok, NWrappedSock} ->
             Peername = esockd_peername(NWrappedSock, Peername0),
-            run_loop(Parent, init_state(NWrappedSock, Peername, Options));
+            try
+                run_loop(Parent, init_state(NWrappedSock, Peername, Options))
+            catch
+                throw : nopermission -> erlang:exit(normal)
+            end;
         {error, Reason} ->
             ok = esockd_close(WrappedSock),
             exit_on_sock_error(Reason)

+ 4 - 2
apps/emqx_stomp/src/emqx_stomp_connection.erl

@@ -91,6 +91,8 @@
 
 -define(ENABLED(X), (X =/= undefined)).
 
+-elvis([{elvis_style, invalid_dynamic_call, #{ignore => [emqx_stomp_connection]}}]).
+
 -dialyzer({nowarn_function, [ ensure_stats_timer/2
                             ]}).
 
@@ -101,7 +103,7 @@
 start_link(Transport, Sock, ProtoEnv) ->
     {ok, proc_lib:spawn_link(?MODULE, init, [[Transport, Sock, ProtoEnv]])}.
 
--spec info(pid()|state()) -> emqx_types:infos().
+-spec info(pid() | state()) -> emqx_types:infos().
 info(CPid) when is_pid(CPid) ->
     call(CPid, info);
 info(State = #state{pstate = PState}) ->
@@ -123,7 +125,7 @@ info(sockstate, #state{sockstate = SockSt}) ->
 info(active_n, #state{active_n = ActiveN}) ->
     ActiveN.
 
--spec stats(pid()|state()) -> emqx_types:stats().
+-spec stats(pid() | state()) -> emqx_types:stats().
 stats(CPid) when is_pid(CPid) ->
     call(CPid, stats);
 stats(#state{transport = Transport,