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

Cannot get example to run #2

Closed
zacheryph opened this issue Jun 7, 2018 · 5 comments
Closed

Cannot get example to run #2

zacheryph opened this issue Jun 7, 2018 · 5 comments

Comments

@zacheryph
Copy link

zacheryph commented Jun 7, 2018

https://github.com/zacheryph/pamsm-test

I am new to rust and its possible I am missing something, though I know this hasn't been touched in a while and may be differences to rust versions. The readme explains whats going on. none of the pam_sm_* functions are making it to the final cdylib.

Thank You for any help 😄

@zacheryph
Copy link
Author

I updated the repo (and README).

I discovered after forcibly calling a method get_cached_authtok which in turn calls get_item from pam_raw it causes the resulting lib to be linked to PAM, have the pam callbacks, and get loaded by pam properly.

@zacheryph
Copy link
Author

Realistically any module must call into pam to get any details it needs from the request as args are from pam config. Feel free to close, though it may be handy to fix example so it works :)

@rcatolino
Copy link
Owner

rcatolino commented Jun 15, 2018

I've added a sub-crate containing the example code (without adding any callback). When I build it I get the following :

$ rustc --version
rustc 1.26.1

$readelf --syms target/release/libtest_module.so | grep pam_sm_
   313: 0000000000058a70    88 FUNC    GLOBAL DEFAULT   12 pam_sm_authenticate
  1001: 0000000000058b90    88 FUNC    GLOBAL DEFAULT   12 pam_sm_chauthtok
  1096: 00000000000589b0    88 FUNC    GLOBAL DEFAULT   12 pam_sm_open_session
  1485: 0000000000058ad0    88 FUNC    GLOBAL DEFAULT   12 pam_sm_setcred
  1903: 0000000000058a10    88 FUNC    GLOBAL DEFAULT   12 pam_sm_close_session
  2237: 0000000000058b30    88 FUNC    GLOBAL DEFAULT   12 pam_sm_acct_mgmt
  1930: 0000000000058ad0    88 FUNC    GLOBAL DEFAULT   12 pam_sm_setcred
  2529: 0000000000058b90    88 FUNC    GLOBAL DEFAULT   12 pam_sm_chauthtok
  2622: 0000000000058a10    88 FUNC    GLOBAL DEFAULT   12 pam_sm_close_session
  2979: 0000000000058b30    88 FUNC    GLOBAL DEFAULT   12 pam_sm_acct_mgmt
  3356: 00000000000589b0    88 FUNC    GLOBAL DEFAULT   12 pam_sm_open_session
  3597: 0000000000058a70    88 FUNC    GLOBAL DEFAULT   12 pam_sm_authenticate

which seems about right. I haven't actually tested it to authenticate though.
I'm not sure why you experience a different behavior.

@zacheryph
Copy link
Author

zacheryph commented Jun 15, 2018

Alrighty. crate-type = ["dylib"] links right away. cdylib did not link right away. I was under the impression dylib was for rust project linking but it worked fine. Guess i'll have to read more on the differences

@rcatolino
Copy link
Owner

rcatolino commented Jun 15, 2018

I wasn't aware of the cdylib crate type, and technicaly you were right to use it as it's intended for libraries linking against other languages, which will likely be the case for pam service modules.

The cdylib type seems to be an optimization where only symbols declared as #[no_mangle] pub extern fn are exported in the library. The thing is, all my pam_sm_ callbacks are declared as #[no_mangle] pub extern and they still get optimized out.

Oh well, as far as I underestand (from the relevant pr) a dylib should work just as well as a cdylib for all purposes but will simply be much bigger.

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

No branches or pull requests

2 participants