Exactly what is that you want to block? Do you want to block anyone from logging into these three companies, or just selected user from logging in? Or is it enough to block anyone from posting in these companies?
I’m not quite sure I understand your problem.
But one thing you could do is the create a specific permissions set for each of the three companies (or just one if it is the same people who needs to access the 3 companies). Then you create a field in a table everyone can read where you select this permission set. In Codeunit 1 in the login function you make a check to see if the user has access to this permission set or not. If the field is blank then you’re not doing the test. This way you can assign the permission only to the users who are allowed access. Maybe not the most “clean” solution, but it will do the job.