Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started whitelist code (WIP) #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thegrb93
Copy link

@thegrb93 thegrb93 commented Jan 10, 2020

Feel free to push modifications or reject if you have a different plan. I'm mostly just experimenting.

Closes: #7

@thegrb93
Copy link
Author

thegrb93 commented Jan 14, 2020

@danielga couple things I'm unsure about are my LUA->ThrowError usage and the whitelist read location. I'll be testing it out later.

@thegrb93
Copy link
Author

I think my ThrowError usage looks better now.

@thegrb93
Copy link
Author

thegrb93 commented Jan 14, 2020

I'll change the whitelist structure to a map of sets instead of vector of pairs.

@thegrb93
Copy link
Author

thegrb93 commented Jan 15, 2020

It's working. Started a game and it allowed the valid whitelisted address and blocked another valid non-whitelisted address. Switched the port in the whitelist and reloaded the map and the whitelist updated to the new port. Last thing to figure out is where to read the whitelist file from and then to update documentation.

@thegrb93
Copy link
Author

thegrb93 commented Jan 15, 2020

Anywhere in the base game folder, common/GarrysMod is accessible to lua so maybe AppData? Not sure. Right now it's reading from steamapps/common, idk if that's ideal or not.

@thegrb93
Copy link
Author

I'd prefer lua to not be able to read the whitelist.

@danielga danielga self-assigned this Jan 16, 2020
@thegrb93
Copy link
Author

Also forgot to mention I haven't tested it on Linux since I don't have a linux installation.

@danielga
Copy link
Owner

Isn't the executable directory enough to prevent Lua from reading the file? I don't remember any search path that has it. Also, can you give me examples of how the regex helps parsing the file (whitelist examples)?

@thegrb93
Copy link
Author

thegrb93 commented Jan 16, 2020

The full list is here https://wiki.garrysmod.com/page/File_Search_Paths . "EXECUTABLE_PATH" lets you get there.

Here's a sample whitelist

google.com:80
       192.168.1.1:27015


whitelist.com:12

//Malformed lines are ignored and can be used as comments

helloworld:100

@thegrb93
Copy link
Author

Could probably change it to domain:port to be more conventional

@danielga
Copy link
Owner

I've tried reading/opening a file with the EXECUTABLE_PATH search path and was unable to do so. And yes, domain:port sounds more convenient.

@danielga
Copy link
Owner

Noticed BASE_PATH and this one actually works.

@thegrb93
Copy link
Author

thegrb93 commented Jan 16, 2020

Doesn't look like LUA->ThrowError is working. Any idea what's wrong?

@thegrb93
Copy link
Author

Ok I just realized my pcall(require is the reason it didn't error. I'll forward the error to ErrorNoHalt and test it tonight.

@thegrb93
Copy link
Author

thegrb93 commented Jan 16, 2020

I'm also going to add the * wildcard so you can do *.*:80 if you wanted. (maybe)

@thegrb93
Copy link
Author

Looks like it's working.

@thegrb93
Copy link
Author

thegrb93 commented Jan 17, 2020

@Python1320 any comments/suggestions?

@thegrb93
Copy link
Author

thegrb93 commented Jan 17, 2020

Seems to crash on linux atm. Crashes whenever the module is loaded.

@thegrb93
Copy link
Author

thegrb93 commented Jan 17, 2020

Is there a specific way you have to build it? He just used premake5 gmake, then make -f gmcl_socket.core.make

@danielga
Copy link
Owner

Sounds like a bug in the code.

@thegrb93
Copy link
Author

It works fine in windows though.

@thegrb93
Copy link
Author

thegrb93 commented Jan 17, 2020

Maybe garrysmod_common has some issue with Linux? @DaDamRival did you try with a valid whitelist with a valid entry? Would be good to try that and make sure its not the Lua->ThrowError that's crashing it.

@danielga
Copy link
Owner

Different compilers have different behavior in undefined behavior situations. You could try executing the code on a Linux VM with a simple executable.

@thegrb93
Copy link
Author

I think he only tried loading it without the whitelist to see if it would error as expected but it crashed, but hopefully he'll reply with some more information here soon.

@Sevii77
Copy link

Sevii77 commented Jan 17, 2020

Seems like that was indeed the issue. Works fine when the whitelist exists.

@thegrb93
Copy link
Author

@DaDamRival could you try replacing them with this?

		case PARSE_CANT_READ:
			LUA->PushString("Failed to read whitelist file!");
			LUA->Error();
			break;
		case PARSE_NO_ENTRIES:
			LUA->PushString("Didn't find any valid entries in whitelist file!");
			LUA->Error();
			break;

@thegrb93
Copy link
Author

That doesn't work either unfortunately. Willox says ThrowError works fine for him in Linux, so perhaps its something wrong with garrysmod_common

@danielga
Copy link
Owner

Besides a few issues with undefined symbols (I might need to add the whole-archive flag to the lua_shared project on garrysmod_common), the module loaded perfectly fine with a valid whitelist and threw an error properly with an invalid whitelist.

@thegrb93
Copy link
Author

Ok, let me know if anything needs to change. I'll have this version deployed on starfall meanwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address/port whitelist for gm_socket
3 participants