123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307open!Core(* [t] is an abstract type which holds the pam context *)typetmodulePam_error=structtypet=intendmodulePam_conv=structmoduleMessage=structtypestyle_t=|PAM_PROMPT_ECHO_OFF|PAM_PROMPT_ECHO_ON|PAM_ERROR_MSG|PAM_TEXT_INFO[@@derivingbin_io]typet={style:style_t;message:string}[@@derivingbin_io,fields](* The value here should not be changed without updating the code
and constant values in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| 47df5cd77358f7105834f9fc0e807676 |}];;letcreate=Fields.createendmoduleResponse=structtypet={resp:stringoption;resp_retcode:int}[@@derivingbin_io,fields](* Use custom create function as [pam] expects a constant [resp_retcode] *)letcreate~resp=Fields.create~resp~resp_retcode:0endmoduleResult=structtypeerror_t=|PAM_BUF_ERR|PAM_CONV_ERR[@@derivingbin_io]typet=(Response.tlist,error_t)Result.t[@@derivingbin_io](* The value here should not be changed without updating the return
code and ordering in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| 622288696dcfeb2b5599101c06a18a26 |}];;endendmodulePam_result=structtype'at=('a,Pam_error.t)Result.tendmodulePam_auth=structmoduleFlag=structtypet=|PAM_SILENT|PAM_DISALLOW_NULL_AUTHTOK[@@derivingbin_io](* The value here should not be changed without updating the return
code and ordering in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| 1d56cbf13292909f3ae9b88709273566 |}];;endendmodulePam_acct=structmoduleFlag=structtypet=|PAM_SILENT|PAM_DISALLOW_NULL_AUTHTOK[@@derivingbin_io](* The value here should not be changed without updating the return
code and ordering in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| 1d56cbf13292909f3ae9b88709273566 |}];;endendmodulePam_cred=structmoduleFlag=structtypet=|PAM_ESTABLISH_CRED|PAM_DELETE_CRED|PAM_REINITIALIZE_CRED|PAM_REFRESH_CRED[@@derivingbin_io](* The value here should not be changed without updating the return
code and ordering in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| f303df589fc8138228a35e94265f8eba |}];;endendmodulePam_authtok=structmoduleFlag=structtypet=|PAM_SILENT|PAM_CHANGE_EXPIRED_AUTHTOK[@@derivingbin_io](* The value here should not be changed without updating the return
code and ordering in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| 99753ea70855ca8f8bf962a186395393 |}];;endendtypepam_convtypepam_fail_delaytypepam_xauth_datamodulePam_item_type=struct(* The value here should not be changed or re-ordred without updating the return
code and ordering in [pam_stub.c]. [bin_io] does not work with gadt so we cannot
create unit test case to check like others *)type_t=|PAM_SERVICE:stringt|PAM_USER:stringt|PAM_USER_PROMPT:stringt|PAM_TTY:stringt|PAM_RUSER:stringt|PAM_RHOST:stringt|PAM_AUTHTOK:stringt|PAM_OLDAUTHTOK:stringt|PAM_XDISPLAY:stringt|PAM_XAUTHDATA:pam_xauth_datat|PAM_AUTHTOK_TYPE:stringt|PAM_CONV:pam_convt|PAM_FAIL_DELAY:pam_fail_delaytendmodulePam_session=structmoduleFlag=structtypet=PAM_SILENT[@@derivingbin_io](* The value here should not be changed without updating the return
code and ordering in [pam_stub.c] *)let%expect_test_=print_endline[%bin_digest:t];[%expect{| 5c9ce93eee7315a34bbf88ee63a24a3e |}];;endendexternalpam_start_c:string->string->((Pam_conv.Message.t,string)Result.tlist->Pam_conv.Result.t)->(t,t*Pam_error.t)Result.t="caml_pam_start"externalpam_end_c:t->unitPam_result.t="caml_pam_end"externalpam_authenticate_c:t->Pam_auth.Flag.tlist->unitPam_result.t="caml_pam_authenticate"externalpam_acct_mgmt_c:t->Pam_acct.Flag.tlist->unitPam_result.t="caml_pam_acct_mgmt"externalpam_setcred_c:t->bool->Pam_cred.Flag.t->unitPam_result.t="caml_pam_setcred"externalpam_chauthtok_c:t->Pam_authtok.Flag.tlist->unitPam_result.t="caml_pam_chauthtok"externalpam_open_session_c:t->Pam_session.Flag.tlist->unitPam_result.t="caml_pam_open_session"externalpam_close_session_c:t->Pam_session.Flag.tlist->unitPam_result.t="caml_pam_close_session"externalpam_getenv_c:t->string->(string,string)Result.t="caml_pam_getenv"externalpam_putenv_c:t->string->unitPam_result.t="caml_pam_putenv"externalpam_getenvlist_c:t->(stringlist,string)Result.t="caml_pam_getenvlist"externalpam_get_item_c:t->'aPam_item_type.t->'aoptionPam_result.t="caml_pam_get_item"externalpam_set_item_c:t->'aPam_item_type.t->'a->unitPam_result.t="caml_pam_set_item"externalpam_strerror_c:t->Pam_error.t->string="caml_pam_strerror"letpam_strerrorterrnum=pam_strerror_cterrnumletpam_errmsg~operrmsg=sprintf"[%s] %s"operrmsgletpam_result_to_or_error~optresult=Result.map_errorresult~f:(funerrnum->leterrmsg=pam_errmsg~op(pam_strerrorterrnum)inError.of_string(sprintf"%s (errnum: %d)"errmsgerrnum));;letpam_start~service~user~conv=pam_start_cserviceuserconv|>Result.map_error~f:(fun(t,errnum)->leterr_desc=pam_strerrorterrnuminignore(pam_end_ct);Error.of_stringerr_desc);;letpam_endt=(* We cannot use [t] after [pam_end_c] so we have to come up with an error message *)pam_end_ct|>Result.map_error~f:(funerrnum->Error.of_string(pam_errmsg~op:"pam_end"(sprintf"failed to release (errnum: %d)"errnum)));;letpam_authenticatet~flags=pam_authenticate_ctflags|>pam_result_to_or_error~op:"pam_authenticate"t;;letpam_acct_mgmtt~flags=pam_acct_mgmt_ctflags|>pam_result_to_or_error~op:"pam_acct_mgmt"t;;letpam_setcred?(silent=false)t~flag=pam_setcred_ctsilentflag|>pam_result_to_or_error~op:"pam_setcred"t;;letpam_chauthtokt~flags=pam_chauthtok_ctflags|>pam_result_to_or_error~op:"pam_chauthtok"t;;letpam_open_sessiont~flags=pam_open_session_ctflags|>pam_result_to_or_error~op:"pam_open_session"t;;letpam_close_sessiont~flags=pam_close_session_ctflags|>pam_result_to_or_error~op:"pam_close_session"t;;letpam_getenvt~key=pam_getenv_ctkey|>Result.map_error~f:(Fn.composeError.of_string(pam_errmsg~op:"pam_getenv"));;letpam_putenvt~key~data=pam_putenv_ct(sprintf"%s=%s"keydata)|>pam_result_to_or_error~op:"pam_putenv"t;;letpam_unsetenvt~key=pam_putenv_ctkey|>pam_result_to_or_error~op:"pam_putenv"tletpam_getenvlistt=pam_getenvlist_ct|>Result.map_error~f:(Fn.composeError.of_string(pam_errmsg~op:"pam_getenvlist"));;letpam_get_item(typea)t~(item_type:aPam_item_type.t):aoptionOr_error.t=pam_get_item_ctitem_type|>pam_result_to_or_error~op:"pam_get_item"t;;letpam_set_item(typea)t~(item_type:aPam_item_type.t)~(item:a):unitOr_error.t=pam_set_item_ctitem_typeitem|>pam_result_to_or_error~op:"pam_set_item"t;;