25 #ifdef DBUS_BUILD_TESTS
27 #include "dbus-auth-script.h"
28 #include "dbus-auth.h"
29 #include "dbus-string.h"
30 #include "dbus-hash.h"
31 #include "dbus-credentials.h"
32 #include "dbus-internals.h"
102 else if (b ==
' ' || b ==
'\n' || b ==
'\t')
121 int first_a_blank, first_b_blank;
126 if (first_a_blank != first_b_blank)
133 auth_state_from_string (
const DBusString *str)
136 return DBUS_AUTH_STATE_WAITING_FOR_INPUT;
138 return DBUS_AUTH_STATE_WAITING_FOR_MEMORY;
140 return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND;
142 return DBUS_AUTH_STATE_NEED_DISCONNECT;
144 return DBUS_AUTH_STATE_AUTHENTICATED;
150 auth_state_to_string (DBusAuthState state)
154 case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
155 return "WAITING_FOR_INPUT";
156 case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
157 return "WAITING_FOR_MEMORY";
158 case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
159 return "HAVE_BYTES_TO_SEND";
160 case DBUS_AUTH_STATE_NEED_DISCONNECT:
161 return "NEED_DISCONNECT";
162 case DBUS_AUTH_STATE_AUTHENTICATED:
163 return "AUTHENTICATED";
172 int i, j, k, count, end;
179 for (count = 0; i < end; count++)
191 for (k = 0; k < count; k++)
196 if (array[k] ==
NULL)
203 array[k][j - i] =
'\0';
213 auth_set_unix_credentials(
DBusAuth *auth,
220 if (credentials ==
NULL)
244 _dbus_auth_script_run (
const DBusString *filename)
280 _dbus_warn (
"Getting contents of %s failed: %s\n",
286 state = DBUS_AUTH_STATE_NEED_DISCONNECT;
296 _dbus_string_delete_leading_blanks (&line);
301 DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
337 _dbus_warn (
"skipping unix only auth script\n");
353 _dbus_warn (
"skipping windows only auth script\n");
365 _dbus_warn (
"already created a DBusAuth (CLIENT or SERVER given twice)\n");
372 _dbus_warn (
"no memory to create DBusAuth\n");
391 _dbus_warn (
"no memory for setting credentials\n");
407 _dbus_warn (
"already created a DBusAuth (CLIENT or SERVER given twice)\n");
414 _dbus_warn (
"no memory to create DBusAuth\n");
433 _dbus_warn (
"no memory for setting credentials\n");
444 else if (auth ==
NULL)
446 _dbus_warn (
"must specify CLIENT or SERVER\n");
461 "SILLY_CREDENTIALS"))
470 _dbus_string_delete_first_word (&line);
471 mechs = split_string (&line);
480 _dbus_string_delete_first_word (&line);
484 _dbus_warn (
"no memory to allocate string\n");
488 if (!append_quoted_string (&to_send, &line))
490 _dbus_warn (
"failed to append quoted string line %d\n",
500 _dbus_warn (
"failed to append \r\n from line %d\n",
511 "USERID_HEX", &where))
535 _dbus_warn (
"no memory to subst USERID_HEX\n");
544 "USERNAME_HEX", &where))
568 _dbus_warn (
"no memory to subst USERNAME_HEX\n");
585 _dbus_warn (
"not enough memory to call bytes_received, or can't add bytes to auth object already in end state\n");
599 DBusAuthState expected;
601 _dbus_string_delete_first_word (&line);
603 expected = auth_state_from_string (&line);
606 _dbus_warn (
"bad auth state given to EXPECT_STATE\n");
610 if (expected != state)
612 _dbus_warn (
"expected auth state %s but got %s on line %d\n",
613 auth_state_to_string (expected),
614 auth_state_to_string (state),
624 _dbus_string_delete_first_word (&line);
628 _dbus_warn (
"no mem to allocate string received\n");
634 _dbus_warn (
"no line popped from the DBusAuth being tested, expected command %s on line %d\n",
640 if (!same_first_word (&received, &line))
642 _dbus_warn (
"line %d expected command '%s' and got '%s'\n",
658 _dbus_string_delete_first_word (&line);
662 _dbus_warn (
"no mem to allocate string expected\n");
666 if (!append_quoted_string (&expected, &line))
668 _dbus_warn (
"failed to append quoted string line %d\n",
683 _dbus_warn (
"Expected unused bytes '%s' and have '%s'\n",
691 "EXPECT_HAVE_NO_CREDENTIALS"))
698 _dbus_warn (
"Expected anonymous login or failed login, but some credentials were authorized\n");
703 "EXPECT_HAVE_SOME_CREDENTIALS"))
710 _dbus_warn (
"Expected to have some credentials, but we don't\n");
719 _dbus_string_delete_first_word (&line);
723 _dbus_warn (
"no mem to allocate string expected\n");
727 if (!append_quoted_string (&expected, &line))
729 _dbus_warn (
"failed to append quoted string line %d\n",
744 _dbus_warn (
"Expected exact string '%s' and have '%s'\n",
758 _dbus_warn (
"couldn't process line %d \"%s\"\n",
766 _dbus_warn (
"Auth script is bogus, did not even have CLIENT or SERVER\n");
769 else if (state == DBUS_AUTH_STATE_AUTHENTICATED)
777 _dbus_warn (
"did not expect unused bytes (scripts must specify explicitly if they are expected)\n");
784 _dbus_warn (
"script did not have EXPECT_ statements for all the data received from the DBusAuth\n");