Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
fa0f0e21
Commit
fa0f0e21
authored
Jun 22, 2013
by
Martin Hurton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ZAP optional for PLAIN mechanism
parent
5975e00f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
69 deletions
+78
-69
plain_mechanism.cpp
src/plain_mechanism.cpp
+72
-69
plain_mechanism.hpp
src/plain_mechanism.hpp
+6
-0
No files found.
src/plain_mechanism.cpp
View file @
fa0f0e21
...
...
@@ -35,6 +35,7 @@ zmq::plain_mechanism_t::plain_mechanism_t (session_base_t *session_,
const
options_t
&
options_
)
:
mechanism_t
(
options_
),
session
(
session_
),
expecting_zap_reply
(
false
),
state
(
options
.
as_server
?
waiting_for_hello
:
sending_hello
)
{
}
...
...
@@ -82,16 +83,8 @@ int zmq::plain_mechanism_t::process_handshake_message (msg_t *msg_)
switch
(
state
)
{
case
waiting_for_hello
:
rc
=
process_hello_command
(
msg_
);
if
(
rc
==
0
)
{
rc
=
receive_and_process_zap_reply
();
if
(
rc
==
0
)
state
=
sending_welcome
;
else
if
(
errno
==
EAGAIN
)
{
rc
=
0
;
state
=
waiting_for_zap_reply
;
}
}
if
(
rc
==
0
)
state
=
expecting_zap_reply
?
waiting_for_zap_reply
:
sending_welcome
;
break
;
case
waiting_for_welcome
:
rc
=
process_welcome_command
(
msg_
);
...
...
@@ -216,68 +209,18 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_)
return
-
1
;
}
// Use ZAP protocol (RFC 27) to authenticate user.
// Use ZAP protocol (RFC 27) to authenticate
the
user.
int
rc
=
session
->
zap_connect
();
if
(
rc
==
-
1
)
{
errno
=
EPROTO
;
return
-
1
;
if
(
rc
==
0
)
{
send_zap_request
(
username
,
password
);
rc
=
receive_and_process_zap_reply
();
if
(
rc
!=
0
)
{
if
(
errno
!=
EAGAIN
)
return
-
1
;
expecting_zap_reply
=
true
;
}
}
msg_t
msg
;
// Address delimiter frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Version frame
rc
=
msg
.
init_size
(
3
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1.0"
,
3
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Sequence frame
rc
=
msg
.
init_size
(
1
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1"
,
1
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Domain frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Mechanism frame
rc
=
msg
.
init_size
(
5
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"PLAIN"
,
5
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Username frame
rc
=
msg
.
init_size
(
username_length
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
username
.
c_str
(),
username_length
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Password frame
rc
=
msg
.
init_size
(
password_length
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
password
.
c_str
(),
password_length
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
return
0
;
}
...
...
@@ -389,6 +332,66 @@ int zmq::plain_mechanism_t::process_ready_command (msg_t *msg_)
return
parse_property_list
(
ptr
+
8
,
bytes_left
-
8
);
}
void
zmq
::
plain_mechanism_t
::
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
{
int
rc
;
msg_t
msg
;
// Address delimiter frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Version frame
rc
=
msg
.
init_size
(
3
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1.0"
,
3
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Sequence frame
rc
=
msg
.
init_size
(
1
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1"
,
1
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Domain frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Mechanism frame
rc
=
msg
.
init_size
(
5
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"PLAIN"
,
5
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Username frame
rc
=
msg
.
init_size
(
username
.
length
());
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
username
.
c_str
(),
username
.
length
());
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Password frame
rc
=
msg
.
init_size
(
password
.
length
());
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
password
.
c_str
(),
password
.
length
());
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
}
int
zmq
::
plain_mechanism_t
::
receive_and_process_zap_reply
()
{
int
rc
=
0
;
...
...
src/plain_mechanism.hpp
View file @
fa0f0e21
...
...
@@ -59,6 +59,10 @@ namespace zmq
};
session_base_t
*
const
session
;
// True iff we are awaiting reply from ZAP reply.
bool
expecting_zap_reply
;
state_t
state
;
int
hello_command
(
msg_t
*
msg_
)
const
;
...
...
@@ -71,6 +75,8 @@ namespace zmq
int
process_ready_command
(
msg_t
*
msg_
);
int
process_initiate_command
(
msg_t
*
msg_
);
void
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
int
receive_and_process_zap_reply
();
int
parse_property_list
(
const
unsigned
char
*
ptr
,
size_t
length
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment