I want to write a udev
rule that blocks access to USB storage. I want to add match options that can recognise the username and permit only some users to use USB storage.
How can I find out which user(s) a currently logged in?
Why do you think you need such a complicated approach which also will cause trouble in any multi-user scenario? Why detect user logons?
I think you should simply write a udev
rule which changes device access rights (group and its permissions) for the USB subsystem, and maintain access via the group memebrship of users. This is a standard case for udev
rules.
man newgrp
. But somebody with your knowledge may be better off with solutions he can understand, even if they cause other problems which he isn't aware of.