-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-auth-script.c Test DBusAuth using a special script file (internal to D-Bus implementation)
*
* Copyright (C) 2003 Red Hat, Inc.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
credentials = _dbus_credentials_new ();
if (credentials == NULL)
- {
- _dbus_warn ("no memory\n");
- return;
- }
+ _dbus_assert_not_reached ("no memory");
+
if (uid != DBUS_UID_UNSET)
_dbus_credentials_add_unix_uid (credentials, uid);
if (pid != DBUS_PID_UNSET)
- _dbus_credentials_add_unix_pid (credentials, pid);
+ _dbus_credentials_add_pid (credentials, pid);
_dbus_auth_set_credentials (auth, credentials);
_dbus_auth_script_run (const DBusString *filename)
{
DBusString file;
- DBusError error;
+ DBusError error = DBUS_ERROR_INIT;
DBusString line;
dbus_bool_t retval;
int line_no;
return FALSE;
}
- dbus_error_init (&error);
if (!_dbus_file_get_contents (&file, filename, &error)) {
_dbus_warn ("Getting contents of %s failed: %s\n",
_dbus_string_get_const_data (filename), error.message);
state = DBUS_AUTH_STATE_NEED_DISCONNECT;
line_no = 0;
+
next_iteration:
while (_dbus_string_pop_line (&file, &line))
{
line_no += 1;
+ /* _dbus_warn ("%s\n", _dbus_string_get_const_data (&line)); */
+
_dbus_string_delete_leading_blanks (&line);
if (auth != NULL)
/* Ignore this comment */
goto next_iteration;
}
+#ifdef DBUS_WIN
+ else if (_dbus_string_starts_with_c_str (&line,
+ "WIN_ONLY"))
+ {
+ /* Ignore this line */
+ goto next_iteration;
+ }
+ else if (_dbus_string_starts_with_c_str (&line,
+ "UNIX_ONLY"))
+ {
+ /* skip this file */
+ _dbus_warn ("skipping unix only auth script\n");
+ retval = TRUE;
+ goto out;
+ }
+#endif
+#ifdef DBUS_UNIX
+ else if (_dbus_string_starts_with_c_str (&line,
+ "UNIX_ONLY"))
+ {
+ /* Ignore this line */
+ goto next_iteration;
+ }
+ else if (_dbus_string_starts_with_c_str (&line,
+ "WIN_ONLY"))
+ {
+ /* skip this file */
+ _dbus_warn ("skipping windows only auth script\n");
+ retval = TRUE;
+ goto out;
+ }
+#endif
else if (_dbus_string_starts_with_c_str (&line,
"CLIENT"))
{
goto out;
}
- if (!_dbus_append_desired_identity (&username))
+ if (!_dbus_append_user_from_current_process (&username))
{
_dbus_warn ("no memory for userid\n");
_dbus_string_free (&username);
"USERNAME_HEX", &where))
{
DBusString username;
- const DBusString *u;
if (!_dbus_string_init (&username))
{
goto out;
}
- if (!_dbus_username_from_current_process (&u) ||
- !_dbus_string_copy (u, 0, &username,
- _dbus_string_get_length (&username)))
+ if (!_dbus_append_user_from_current_process (&username))
{
_dbus_warn ("no memory for username\n");
_dbus_string_free (&username);
}
}
else if (_dbus_string_starts_with_c_str (&line,
+ "EXPECT_HAVE_NO_CREDENTIALS"))
+ {
+ DBusCredentials *authorized_identity;
+
+ authorized_identity = _dbus_auth_get_identity (auth);
+ if (!_dbus_credentials_are_anonymous (authorized_identity))
+ {
+ _dbus_warn ("Expected anonymous login or failed login, but some credentials were authorized\n");
+ goto out;
+ }
+ }
+ else if (_dbus_string_starts_with_c_str (&line,
+ "EXPECT_HAVE_SOME_CREDENTIALS"))
+ {
+ DBusCredentials *authorized_identity;
+
+ authorized_identity = _dbus_auth_get_identity (auth);
+ if (_dbus_credentials_are_anonymous (authorized_identity))
+ {
+ _dbus_warn ("Expected to have some credentials, but we don't\n");
+ goto out;
+ }
+ }
+ else if (_dbus_string_starts_with_c_str (&line,
"EXPECT"))
{
DBusString expected;
}
}
- if (auth != NULL &&
- state == DBUS_AUTH_STATE_AUTHENTICATED)
+ if (auth == NULL)
+ {
+ _dbus_warn ("Auth script is bogus, did not even have CLIENT or SERVER\n");
+ goto out;
+ }
+ else if (state == DBUS_AUTH_STATE_AUTHENTICATED)
{
const DBusString *unused;