Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
supervisedid
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs
cls
supervisedid
Commits
88d9c9b5
Commit
88d9c9b5
authored
4 years ago
by
Claudio Scafuri
Browse files
Options
Downloads
Patches
Plain Diff
use enum for priveleges values
parent
058cc4f4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Checkprivileges
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/SupervisedID.cpp
+17
-13
17 additions, 13 deletions
src/SupervisedID.cpp
src/SupervisedID.h
+4
-6
4 additions, 6 deletions
src/SupervisedID.h
with
21 additions
and
19 deletions
src/SupervisedID.cpp
+
17
−
13
View file @
88d9c9b5
...
...
@@ -314,7 +314,7 @@ void SupervisedID::add_dynamic_commands()
* AUTHORIZED : can set gap/tapering when enabled
* NORMAL : can only read;
*/
int
SupervisedID
::
caller_privileges
(
void
)
privilege
SupervisedID
::
caller_privileges
(
void
)
{
//if no privileges are configured, run unimpeded
if
(
hostMap
.
size
()
==
0
)
return
PRIVILEGED
;
...
...
@@ -328,14 +328,6 @@ int SupervisedID::caller_privileges(void)
loc
=
clientAddress
.
find
(
" "
,
0
);
clientAddress
=
clientAddress
.
substr
(
0
,
loc
);
INFO_STREAM
<<
"checking call from "
<<
clientAddress
<<
endl
;
// std::set<std::string> client_ips;
// get_ips_from_host(clientAddress, client_ips);
//
// for (std::set<std::string>::const_iterator it = client_ips.begin(); it != client_ips.end(); ++it )
// {
// if (std::find(allowed_ips.begin(), allowed_ips.end(), *it) != allowed_ips.end())
// return; // found the IP in the allowed list of IPs
// }
map
<
string
,
int
>::
iterator
it
;
it
=
hostMap
.
find
(
clientAddress
);
if
(
it
==
hostMap
.
end
())
{
...
...
@@ -343,8 +335,20 @@ int SupervisedID::caller_privileges(void)
return
NORMAL
;
}
else
{
INFO_STREAM
<<
"host: "
<<
clientAddress
<<
" privilges="
<<
it
->
second
<<
endl
;
return
it
->
second
;
INFO_STREAM
<<
"host: "
<<
clientAddress
<<
" privilges="
<<
it
->
second
<<
endl
;
switch
(
it
->
second
)
{
case
0
:
return
NORMAL
;
case
1
:
return
AUTHORIZED
;
case
2
:
return
PRIVILEGED
;
default:
return
NORMAL
;
}
}
}
...
...
@@ -366,9 +370,9 @@ int SupervisedID::caller_privileges(void)
* NORMAL : can only read;
*/
int
SupervisedID
::
check_privileges
(
int
level
,
string
msg
)
privilege
SupervisedID
::
check_privileges
(
privilege
level
,
string
msg
)
{
int
priv
=
caller_privileges
();
privilege
priv
=
caller_privileges
();
if
(
priv
<
level
){
INFO_STREAM
<<
msg
<<
" from "
<<
clientAddress
<<
" REJECTED"
<<
endl
;
TangoSys_OMemStream
o
;
...
...
This diff is collapsed.
Click to expand it.
src/SupervisedID.h
+
4
−
6
View file @
88d9c9b5
...
...
@@ -37,9 +37,7 @@
#include
<tango.h>
#include
<map>
#define PRIVILEGED 2
#define AUTHORIZED 1
#define NORMAL 0
/*----- PROTECTED REGION END -----*/
// SupervisedID.h
/**
...
...
@@ -56,7 +54,7 @@ namespace SupervisedID_ns
// Additional Class Declarations
/*----- PROTECTED REGION END -----*/
// SupervisedID::Additional Class Declarations
enum
privilege
{
NORMAL
,
AUTHORIZED
,
PRIVILEGED
};
class
SupervisedID
:
public
TANGO_BASE_CLASS
{
...
...
@@ -64,11 +62,11 @@ class SupervisedID : public TANGO_BASE_CLASS
// Add your own data members
protected:
int
caller_privileges
(
void
);
privilege
caller_privileges
(
void
);
bool
is_privileged
;
//true is the caller has all privileges - must be handled in alawys_executed
string
clientAddress
;
map
<
string
,
int
>
hostMap
;
int
check_privileges
(
int
,
string
);
//check privileges , emits diagnostics and throw exception, returns actual privileges
privilege
check_privileges
(
privilege
,
string
);
//check privileges , emits diagnostics and throw exception, returns actual privileges
/*----- PROTECTED REGION END -----*/
// SupervisedID::Data Members
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment