diff --git a/interfaces/innerkits/ipc_core/include/ipc_object_stub.h b/interfaces/innerkits/ipc_core/include/ipc_object_stub.h index dfa4e18c79602da247f9935660c44a6e8000aaed..d40f1ea6897454df2db6250504fd42666c4326ee 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_object_stub.h +++ b/interfaces/innerkits/ipc_core/include/ipc_object_stub.h @@ -64,8 +64,12 @@ public: uint32_t GetCallingTokenID(); + uint64_t GetCallingFullTokenID(); + uint32_t GetFirstTokenID(); + uint64_t GetFirstFullTokenID(); + virtual int OnRemoteDump(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); virtual int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index 4ea3c1a3bf9e224ffc41a3aca95f2e86989612ec..6c45eec71d619b9a7d33bc0293a7d1341250a870 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -39,8 +39,12 @@ public: static uint32_t GetCallingTokenID(); + static uint64_t GetCallingFullTokenID(); + static uint32_t GetFirstTokenID(); + static uint64_t GetFirstFullTokenID(); + static std::string GetLocalDeviceID(); static std::string GetCallingDeviceID(); diff --git a/ipc/native/src/core/source/ipc_object_stub.cpp b/ipc/native/src/core/source/ipc_object_stub.cpp index 2171145c87b90e64b664c18a3256bc95a9d29cb9..2f1bba850d73f808043a7d2afc14097f241163c9 100644 --- a/ipc/native/src/core/source/ipc_object_stub.cpp +++ b/ipc/native/src/core/source/ipc_object_stub.cpp @@ -321,11 +321,21 @@ uint32_t IPCObjectStub::GetCallingTokenID() return IPCSkeleton::GetCallingTokenID(); } +uint64_t IPCObjectStub::GetCallingFullTokenID() +{ + return IPCSkeleton::GetCallingFullTokenID(); +} + uint32_t IPCObjectStub::GetFirstTokenID() { return IPCSkeleton::GetFirstTokenID(); } +uint64_t IPCObjectStub::GetFirstFullTokenID() +{ + return IPCSkeleton::GetFirstFullTokenID(); +} + int IPCObjectStub::GetObjectType() const { return OBJECT_TYPE_NATIVE; diff --git a/ipc/native/src/core/source/ipc_skeleton.cpp b/ipc/native/src/core/source/ipc_skeleton.cpp index d13398134347aec20efec646657846344dfe70e6..8f6247839396947d21d2efa5c30f360c15217f96 100644 --- a/ipc/native/src/core/source/ipc_skeleton.cpp +++ b/ipc/native/src/core/source/ipc_skeleton.cpp @@ -97,23 +97,39 @@ pid_t IPCSkeleton::GetCallingUid() } uint32_t IPCSkeleton::GetCallingTokenID() +{ + IRemoteInvoker *invoker = IPCThreadSkeleton::GetActiveInvoker(); + if (invoker != nullptr) { + return static_cast(invoker->GetCallerTokenID()); + } + return static_cast(RpcGetSelfTokenID()); +} + +uint64_t IPCSkeleton::GetCallingFullTokenID() { IRemoteInvoker *invoker = IPCThreadSkeleton::GetActiveInvoker(); if (invoker != nullptr) { return invoker->GetCallerTokenID(); } - uint64_t token = RpcGetSelfTokenID(); - return (uint32_t)token; + return RpcGetSelfTokenID(); } uint32_t IPCSkeleton::GetFirstTokenID() +{ + IRemoteInvoker *invoker = IPCThreadSkeleton::GetActiveInvoker(); + if (invoker != nullptr) { + return static_cast(invoker->GetFirstTokenID()); + } + return static_cast(RpcGetFirstCallerTokenID()); +} + +uint64_t IPCSkeleton::GetFirstFullTokenID() { IRemoteInvoker *invoker = IPCThreadSkeleton::GetActiveInvoker(); if (invoker != nullptr) { return invoker->GetFirstTokenID(); } - uint64_t ftoken = RpcGetFirstCallerTokenID(); - return (uint32_t)ftoken; + return RpcGetFirstCallerTokenID(); } std::string IPCSkeleton::GetLocalDeviceID() diff --git a/ipc/native/src/mock/include/binder_invoker.h b/ipc/native/src/mock/include/binder_invoker.h index fd56ba751e6b6ee3e1f6b33f980955682a53149a..cd3ef1f78b625a647247696fd3649c21a87fa853 100644 --- a/ipc/native/src/mock/include/binder_invoker.h +++ b/ipc/native/src/mock/include/binder_invoker.h @@ -78,9 +78,9 @@ public: uid_t GetCallerUid() const override; - uint32_t GetCallerTokenID() const override; + uint64_t GetCallerTokenID() const override; - uint32_t GetFirstTokenID() const override; + uint64_t GetFirstTokenID() const override; uint32_t GetStatus() const override; @@ -113,8 +113,8 @@ protected: bool stopWorkThread; pid_t callerPid_; pid_t callerUid_; - uint32_t callerTokenID_; - uint32_t firstTokenID_; + uint64_t callerTokenID_; + uint64_t firstTokenID_; private: int TransactWithDriver(bool doRead = true); diff --git a/ipc/native/src/mock/include/dbinder_databus_invoker.h b/ipc/native/src/mock/include/dbinder_databus_invoker.h index 780646d1c3a2363895673e313406e5fa57d509c7..93f9a1d650cf1ed866b233e1cdbd52367485949d 100644 --- a/ipc/native/src/mock/include/dbinder_databus_invoker.h +++ b/ipc/native/src/mock/include/dbinder_databus_invoker.h @@ -46,8 +46,8 @@ public: bool WriteFileDescriptor(Parcel &parcel, int fd, bool takeOwnership) override; pid_t GetCallerPid() const override; uid_t GetCallerUid() const override; - uint32_t GetCallerTokenID() const override; - uint32_t GetFirstTokenID() const override; + uint64_t GetCallerTokenID() const override; + uint64_t GetFirstTokenID() const override; uint32_t GetStatus() const override; bool IsLocalCalling() override; std::string GetLocalDeviceID() override; @@ -106,8 +106,8 @@ private: pid_t callerPid_; pid_t callerUid_; std::string callerDeviceID_; - uint32_t callerTokenID_; - uint32_t firstTokenID_; + uint64_t callerTokenID_; + uint64_t firstTokenID_; uint64_t seqNumber_ = 0; uint32_t clientFd_ = 0; uint32_t status_; diff --git a/ipc/native/src/mock/include/iremote_invoker.h b/ipc/native/src/mock/include/iremote_invoker.h index b7f82730611865cae11f8f2b3f9843eddb6bc1e7..3e04bb4c2dec1edcc2dd0054aa268287a10b995b 100644 --- a/ipc/native/src/mock/include/iremote_invoker.h +++ b/ipc/native/src/mock/include/iremote_invoker.h @@ -66,9 +66,9 @@ public: virtual uid_t GetCallerUid() const = 0; - virtual uint32_t GetCallerTokenID() const = 0; + virtual uint64_t GetCallerTokenID() const = 0; - virtual uint32_t GetFirstTokenID() const = 0; + virtual uint64_t GetFirstTokenID() const = 0; virtual uint32_t GetStatus() const = 0; diff --git a/ipc/native/src/mock/source/binder_invoker.cpp b/ipc/native/src/mock/source/binder_invoker.cpp index acfaa00aaf241c0f36cb46eacb3e4f13aacee841..e095d0c86f953142a93585d20d7b66934e9bbca6 100644 --- a/ipc/native/src/mock/source/binder_invoker.cpp +++ b/ipc/native/src/mock/source/binder_invoker.cpp @@ -47,7 +47,7 @@ BinderInvoker::BinderInvoker() : isMainWorkThread(false), stopWorkThread(false), callerPid_(getpid()), callerUid_(getuid()), firstTokenID_(0), status_(0) { - callerTokenID_ = (uint32_t)RpcGetSelfTokenID(); + callerTokenID_ = RpcGetSelfTokenID(); input_.SetDataCapacity(IPC_DEFAULT_PARCEL_SIZE); binderConnector_ = BinderConnector::GetInstance(); } @@ -401,8 +401,8 @@ void BinderInvoker::OnTransaction(const uint8_t *buffer) int isServerTraced = HitraceInvoker::TraceServerReceieve(tr->target.handle, tr->code, *data, newflags); const pid_t oldPid = callerPid_; const auto oldUid = static_cast(callerUid_); - const uint32_t oldToken = callerTokenID_; - const uint32_t oldFirstToken = firstTokenID_; + const uint64_t oldToken = callerTokenID_; + const uint64_t oldFirstToken = firstTokenID_; uint32_t oldStatus = status_; callerPid_ = tr->sender_pid; callerUid_ = tr->sender_euid; @@ -833,15 +833,15 @@ uid_t BinderInvoker::GetCallerUid() const return callerUid_; } -uint32_t BinderInvoker::GetCallerTokenID() const +uint64_t BinderInvoker::GetCallerTokenID() const { return callerTokenID_; } -uint32_t BinderInvoker::GetFirstTokenID() const +uint64_t BinderInvoker::GetFirstTokenID() const { if (firstTokenID_ == 0) { - return (uint32_t)RpcGetFirstCallerTokenID(); + return RpcGetFirstCallerTokenID(); } return firstTokenID_; } @@ -973,9 +973,9 @@ bool BinderInvoker::WriteFileDescriptor(Parcel &parcel, int fd, bool takeOwnersh std::string BinderInvoker::ResetCallingIdentity() { char buf[ACCESS_TOKEN_MAX_LEN + 1] = {0}; - int ret = sprintf_s(buf, ACCESS_TOKEN_MAX_LEN + 1, "%010u", callerTokenID_); + int ret = sprintf_s(buf, ACCESS_TOKEN_MAX_LEN + 1, "%010" PRIu64, callerTokenID_); if (ret < 0) { - ZLOGE(LABEL, "%s: sprintf callerTokenID_ %u failed", __func__, callerTokenID_); + ZLOGE(LABEL, "%{public}s: sprintf callerTokenID_ %{public}" PRIu64 " failed", __func__, callerTokenID_); return ""; } std::string accessToken(buf); @@ -983,7 +983,7 @@ std::string BinderInvoker::ResetCallingIdentity() | static_cast(callerPid_))); callerUid_ = static_cast(getuid()); callerPid_ = getpid(); - callerTokenID_ = (uint32_t)RpcGetSelfTokenID(); + callerTokenID_ = RpcGetSelfTokenID(); return accessToken + pidUid; } @@ -997,7 +997,7 @@ bool BinderInvoker::SetCallingIdentity(std::string &identity) std::stoull(identity.substr(ACCESS_TOKEN_MAX_LEN, identity.length() - ACCESS_TOKEN_MAX_LEN).c_str()); callerUid_ = static_cast(pidUid >> PID_LEN); callerPid_ = static_cast(pidUid); - callerTokenID_ = static_cast(std::atoi(identity.substr(0, ACCESS_TOKEN_MAX_LEN).c_str())); + callerTokenID_ = std::stoull(identity.substr(0, ACCESS_TOKEN_MAX_LEN).c_str()); return true; } #ifdef CONFIG_IPC_SINGLE diff --git a/ipc/native/src/mock/source/dbinder_databus_invoker.cpp b/ipc/native/src/mock/source/dbinder_databus_invoker.cpp index ee853bc10067b5bf0c0f02ec12d1969121282484..447db17c313efda83a8e4cda5281aab5fbda19fe 100644 --- a/ipc/native/src/mock/source/dbinder_databus_invoker.cpp +++ b/ipc/native/src/mock/source/dbinder_databus_invoker.cpp @@ -643,12 +643,12 @@ void DBinderDatabusInvoker::SetCallerUid(pid_t uid) callerUid_ = uid; } -uint32_t DBinderDatabusInvoker::GetCallerTokenID() const +uint64_t DBinderDatabusInvoker::GetCallerTokenID() const { return callerTokenID_; } -uint32_t DBinderDatabusInvoker::GetFirstTokenID() const +uint64_t DBinderDatabusInvoker::GetFirstTokenID() const { return firstTokenID_; } @@ -873,9 +873,9 @@ std::string DBinderDatabusInvoker::ResetCallingIdentity() | static_cast(callerPid_))); std::string identity = callerDeviceID_ + token; char buf[ACCESS_TOKEN_MAX_LEN + 1] = {0}; - int ret = sprintf_s(buf, ACCESS_TOKEN_MAX_LEN + 1, "%010u", callerTokenID_); + int ret = sprintf_s(buf, ACCESS_TOKEN_MAX_LEN + 1, "%010" PRIu64, callerTokenID_); if (ret < 0) { - ZLOGE(LOG_LABEL, "sprintf callerTokenID_ %u failed", callerTokenID_); + ZLOGE(LOG_LABEL, "sprintf callerTokenID_ %{public}" PRIu64 " failed", callerTokenID_); return ""; } std::string accessToken(buf); @@ -892,7 +892,7 @@ bool DBinderDatabusInvoker::SetCallingIdentity(std::string &identity) return false; } - uint32_t tokenId = std::stoul(identity.substr(0, ACCESS_TOKEN_MAX_LEN)); + uint64_t tokenId = std::stoull(identity.substr(0, ACCESS_TOKEN_MAX_LEN).c_str()); std::string deviceId = identity.substr(ACCESS_TOKEN_MAX_LEN, DEVICEID_LENGTH); uint64_t token = std::stoull(identity.substr(ACCESS_TOKEN_MAX_LEN + DEVICEID_LENGTH, identity.length() - ACCESS_TOKEN_MAX_LEN - DEVICEID_LENGTH).c_str());