-
Notifications
You must be signed in to change notification settings - Fork 1
Added azuthnone changes #59
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| +20 −0 | include/nfsc/libnfs.h | |
| +12 −8 | lib/libnfs.c | |
| +1 −7 | lib/pdu.c | |
| +33 −40 | lib/socket.c | |
| +2 −0 | nfs/libnfs-raw-nfs.c | |
| +1 −0 | nfs/libnfs-raw-nfs.h | |
| +1 −0 | nfs/nfs.x |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ std::string get_clientid() { | |
| struct ifaddrs *ifaddr = nullptr; | ||
| struct ifaddrs *ifa = nullptr; | ||
| char ip[INET_ADDRSTRLEN] = {0}; | ||
| static std::string client_id = std::to_string(get_current_usecs()) + "-"; | ||
|
|
||
| /* | ||
| * Whatever is encoded here should not exceed the maximum possible that can be | ||
|
|
@@ -60,19 +59,28 @@ std::string get_clientid() { | |
| goto failed_get_clientip; | ||
| } | ||
|
|
||
| client_id += std::string(ip); | ||
|
|
||
| failed_get_clientip: | ||
| // Build and cache the client ID only once | ||
| static std::string client_id = std::to_string(get_current_usecs()) + "-" + std::string(ip); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Random number from /opt/microsoft/aznfs/data/client -- file and concatenate with macaddress.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets create 16bytes random number which is same for all connection and valid till this process is up. |
||
|
|
||
| // We cannot send clientid of size more than MAX_IP_LENGTH. | ||
| assert(client_id.length() <= MAX_IP_LENGTH); | ||
| AZLogDebug("Using clientid {}", client_id); | ||
|
|
||
| return client_id; | ||
|
|
||
| failed_get_clientip: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failed case return empty client_id which means error and mount should fail without client-id. |
||
| static std::string fallback_client_id = std::to_string(get_current_usecs()) + "-unknown"; | ||
| AZLogDebug("Using fallback clientid {}", fallback_client_id); | ||
| return fallback_client_id; | ||
| } | ||
|
|
||
| bool nfs_connection::open() | ||
| { | ||
| const int nodelay = 1; | ||
| std::string client_id; | ||
| int ret = -1; | ||
| uint64_t n; | ||
|
|
||
| // open() must be called only for a closed connection. | ||
| assert(nfs_context == nullptr); | ||
|
|
@@ -100,38 +108,39 @@ bool nfs_connection::open() | |
| nfs_destroy_url(url); | ||
|
|
||
| if (mo.auth) { | ||
| // 16 should be sufficient to hold the version string. | ||
| char client_version[16]; | ||
|
|
||
| [[maybe_unused]] | ||
| const uint64_t n = snprintf(client_version, sizeof(client_version), | ||
| "%d.%d.%d", AZNFSCLIENT_VERSION_MAJOR, | ||
| AZNFSCLIENT_VERSION_MINOR, | ||
| AZNFSCLIENT_VERSION_PATCH); | ||
| assert(n < sizeof(client_version)); | ||
|
|
||
| std::string client_id = get_clientid(); | ||
|
|
||
| assert(!mo.export_path.empty()); | ||
| assert(!mo.authtype.empty()); | ||
| assert(strlen(client_version) > 0); | ||
| assert(!client_id.empty()); | ||
|
|
||
| const int ret = nfs_set_auth_context(nfs_context, | ||
| mo.export_path.c_str(), | ||
| mo.authtype.c_str(), | ||
| client_version, | ||
| client_id.c_str()); | ||
| if (ret != 0) { | ||
| AZLogError("Failed to set auth values in nfs context, " | ||
| "exportpath={} authtype={} " | ||
| "clientversion={} clientid={}", | ||
| mo.export_path.c_str(), | ||
| mo.authtype.c_str(), | ||
| client_version, | ||
| client_id.c_str()); | ||
| goto destroy_context; | ||
| } | ||
| mo.authtype = "AzAuthAAD"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets set this value in constructor. |
||
| } | ||
|
|
||
| // 16 should be sufficient to hold the version string. | ||
| char client_version[16]; | ||
|
|
||
| n = snprintf(client_version, sizeof(client_version), | ||
| "%d.%d.%d", AZNFSCLIENT_VERSION_MAJOR, | ||
| AZNFSCLIENT_VERSION_MINOR, | ||
| AZNFSCLIENT_VERSION_PATCH); | ||
| assert(n < sizeof(client_version)); | ||
|
|
||
| client_id = get_clientid(); | ||
|
|
||
| assert(!mo.export_path.empty()); | ||
| assert(!mo.authtype.empty()); | ||
| assert(strlen(client_version) > 0); | ||
| assert(!client_id.empty()); | ||
|
|
||
| ret = nfs_set_auth_context(nfs_context, | ||
| mo.export_path.c_str(), | ||
| mo.authtype.c_str(), | ||
| client_version, | ||
| client_id.c_str()); | ||
| if (ret != 0) { | ||
| AZLogError("Failed to set auth values in nfs context, " | ||
| "exportpath={} authtype={} " | ||
| "clientversion={} clientid={}", | ||
| mo.export_path.c_str(), | ||
| mo.authtype.c_str(), | ||
| client_version, | ||
| client_id.c_str()); | ||
| goto destroy_context; | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -603,6 +603,40 @@ auth_token_cb_res *get_auth_token_and_setargs_cb(struct auth_context *auth) | |
| return cb_res; | ||
| } | ||
|
|
||
| auth_token_cb_res *get_auth_token_and_setargs_cb_none(struct auth_context *auth) | ||
| { | ||
| if (!auth) { | ||
| AZLogError("Null auth_context received"); | ||
| assert(0); | ||
| return nullptr; | ||
| } | ||
|
|
||
| // Allocate response structure | ||
| auth_token_cb_res *cb_res = (auth_token_cb_res *) malloc(sizeof(auth_token_cb_res)); | ||
| if (!cb_res) { | ||
| AZLogError("Failed to allocate memory for auth_token_cb_res"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| cb_res->azauth_data = strdup("None"); | ||
| cb_res->expiry_time = static_cast<uint64_t>(time(NULL))+300; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why 300 ?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you handle in AzAuthNone in rpc_auth_needs_refresh() then you don't need this . |
||
|
|
||
| return cb_res; | ||
| } | ||
|
|
||
| uint64_t set_azauth_res_sc_cb(uint64_t server_cap_map) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this capability code. |
||
| { | ||
| if (server_cap_map == 1) { | ||
| if (!client_started) { | ||
| AZLogError("Client not started when get_azauth_res_cb is called"); | ||
| return -1; | ||
| } | ||
| } | ||
|
|
||
| AZLogInfo("In get_azauth_res_cb %lu",server_cap_map); | ||
| return 0; | ||
| } | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| // Initialize logger first thing. | ||
|
|
@@ -789,7 +823,10 @@ int main(int argc, char *argv[]) | |
| if (aznfsc_cfg.auth) { | ||
| // Set the auth token callback for this connection if auth is enabled. | ||
| set_auth_token_callback(get_auth_token_and_setargs_cb); | ||
| } else { | ||
| set_auth_token_callback(get_auth_token_and_setargs_cb_none); | ||
| } | ||
| set_azauth_res_callback(set_azauth_res_sc_cb); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this one also |
||
|
|
||
| /* | ||
| * Initialize nfs_client singleton. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this from PR