提交 0a976fe4 编写于 作者: Y YOUR_NAME

Description:add get uint64_t tokenId interface

Feature or Bugfix:Feature
Binary Source: No
Signed-off-by: NYOUR_NAME <heyingjiao@huawei.com>
上级 7d3728e7
......@@ -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);
......
......@@ -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();
......
......@@ -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;
......
......@@ -97,23 +97,39 @@ pid_t IPCSkeleton::GetCallingUid()
}
uint32_t IPCSkeleton::GetCallingTokenID()
{
IRemoteInvoker *invoker = IPCThreadSkeleton::GetActiveInvoker();
if (invoker != nullptr) {
return static_cast<uint32_t>(invoker->GetCallerTokenID());
}
return static_cast<uint32_t>(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<uint32_t>(invoker->GetFirstTokenID());
}
return static_cast<uint32_t>(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()
......
......@@ -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);
......
......@@ -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_;
......
......@@ -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;
......
......@@ -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<const uid_t>(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<uint64_t>(callerPid_)));
callerUid_ = static_cast<pid_t>(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<int>(pidUid >> PID_LEN);
callerPid_ = static_cast<int>(pidUid);
callerTokenID_ = static_cast<uint32_t>(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
......
......@@ -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<uint64_t>(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());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册