author | Sebastian Harl <sh@tokkee.org> | |
Fri, 12 Dec 2014 07:55:39 +0000 (08:55 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 12 Dec 2014 07:57:51 +0000 (08:57 +0100) |
1 | 2 | |||
---|---|---|---|---|
src/tools/sysdb/input.h | patch | | diff1 | | diff2 | | blob | history |
src/tools/sysdb/main.c | patch | | diff1 | | diff2 | | blob | history |
t/integration/query.sh | patch | | diff1 | | diff2 | | blob | history |
diff --cc src/tools/sysdb/input.h
index 0ba5c0a4dd385169fc439c1fe133b33464f609a8,b8501f472383cd454608c19aebcab8688e784c60..ba2b32d8d3553dad528bfda657d7f18f79b20234
+++ b/src/tools/sysdb/input.h
typedef struct {
sdb_client_t *client;
- const char *user;
++ char *user;
sdb_strbuf_t *input;
size_t tokenizer_pos;
diff --cc src/tools/sysdb/main.c
index b3a73c698e1e2507f9741b60a6692cb11ed5dd6c,6e10e8d9fd87d937a3d668566f9f4fccf7bbcd7d..357ef34827672d0033030eeefe8d85d059f98836
+++ b/src/tools/sysdb/main.c
if (! host)
host = DEFAULT_SOCKET;
- if (! user)
- user = sdb_get_current_user();
- if (! input.user) {
- input.user = get_current_user();
- if (! input.user)
- exit(1);
- }
++ if (! input.user)
++ input.user = sdb_get_current_user();
+ else
- user = strdup(user);
- if (! user)
++ input.user = strdup(input.user);
++ if (! input.user)
+ exit(1);
input.client = sdb_client_create(host);
if (! input.client) {
sdb_log(SDB_LOG_ERR, "Failed to create client object");
- free(user);
++ free(input.user);
exit(1);
}
- if (sdb_client_connect(input.client, user)) {
+ if (sdb_client_connect(input.client, input.user)) {
sdb_log(SDB_LOG_ERR, "Failed to connect to SysDBd");
sdb_client_destroy(input.client);
- free(user);
++ free(input.user);
exit(1);
}
int status = execute_commands(input.client, commands);
sdb_llist_destroy(commands);
sdb_client_destroy(input.client);
- free(user);
++ free(input.user);
if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA))
exit(1);
exit(0);
hist_file, sdb_strerror(errno, errbuf, sizeof(errbuf)));
}
}
- free(user);
++ free(input.user);
input.input = sdb_strbuf_create(2048);
sdb_input_init(&input);
diff --cc t/integration/query.sh
index 5536c701c9c517eefd3882518e0e2eee1683a88a,f8287b45a645adac6798dbb611b092279e070d4f..eb4ccd8814771f058f6a9a357f1b669f5803b5e5
+++ b/t/integration/query.sh
wait_for_sysdbd
sleep 3
+# Invalid user.
+output="$( run_sysdb_nouser -H "$SOCKET_FILE" \
+ -U $SYSDB_USER-invalid -c 'LIST hosts' 2>&1 )" && exit 1
+echo "$output" | grep -F 'Access denied'
+
# On parse errors, expect a non-zero exit code.
- output="$( run_sysdb -H "$SOCKET_FILE" -c INVALID )" && exit 1
+ output="$( run_sysdb -H "$SOCKET_FILE" -c INVALID 2>&1 )" && exit 1
echo "$output" | grep "Failed to parse query 'INVALID'"
echo "$output" | grep "parse error: syntax error"