#!/bin/sh -ex
cauthtool --create-keyring k --gen-key -p --name client.xx
-ceph auth add -i k client.xx mon 'allow command foo; allow command bar'
+ceph auth add -i k client.xx mon "allow command foo; allow command bar *; allow command baz ...; allow command foo add * mon allow\\ rwx osd allow\\ *"
-( ceph -k k -n client.xx foo || true ) | grep -v 'Access denied'
-( ceph -k k -n client.xx foo ooo || true ) | grep -v 'Access denied'
-( ceph -k k -n client.xx fo || true ) | grep 'Access denied'
-( ceph -k k -n client.xx fooo || true ) | grep 'Access denied'
+( ceph -k k -n client.xx foo || true ) | grep 'unrecog'
+( ceph -k k -n client.xx foo ooo || true ) | grep 'Access denied'
+( ceph -k k -n client.xx fo || true ) | grep 'Access denied'
+( ceph -k k -n client.xx fooo || true ) | grep 'Access denied'
-( ceph -k k -n client.xx bar || true ) | grep -v 'Access denied'
-( ceph -k k -n client.xx bar a b c || true ) | grep -v 'Access denied'
-( ceph -k k -n client.xx ba || true ) | grep 'Access denied'
-( ceph -k k -n client.xx barr || true ) | grep 'Access denied'
+( ceph -k k -n client.xx bar || true ) | grep 'Access denied'
+( ceph -k k -n client.xx bar a || true ) | grep 'unrecog'
+( ceph -k k -n client.xx bar a b c || true ) | grep 'Access denied'
+( ceph -k k -n client.xx ba || true ) | grep 'Access denied'
+( ceph -k k -n client.xx barr || true ) | grep 'Access denied'
-( ceph -k k -n client.xx baz || true ) | grep 'Access denied'
+( ceph -k k -n client.xx baz || true ) | grep -v 'Access denied'
+( ceph -k k -n client.xx baz a || true ) | grep -v 'Access denied'
+( ceph -k k -n client.xx baz a b || true ) | grep -v 'Access denied'
+
+( ceph -k k -n client.xx foo add osd.1 -i k mon 'allow rwx' osd 'allow *' || true ) | grep 'unrecog'
+( ceph -k k -n client.xx foo add osd a b c -i k mon 'allow rwx' osd 'allow *' || true ) | grep 'Access denied'
+( ceph -k k -n client.xx foo add osd a b c -i k mon 'allow *' || true ) | grep 'Access denied'
echo OK
\ No newline at end of file
if (start < 0) {
return false;
}
+
+ token.clear();
- if (s[start] == '=' || s[start] == ',' || s[start] == ';') {
- end = start + 1;
- } else {
- end = s.find_first_of(";,= \t", start+1);
- }
-
- if (end < 0) {
- end=s.size();
+ while (true) {
+ if (s[start] == '=' || s[start] == ',' || s[start] == ';') {
+ end = start + 1;
+ } else {
+ end = s.find_first_of(";,= \t", start+1);
+ if (end < 0) {
+ end = s.size();
+ }
+ else if (end >= start + 2 && s[end] == ' ' && s[end-1] == '\\') {
+ token += s.substr(start, end - start - 1);
+ token += ' ';
+ start = end + 1;
+ continue;
+ }
+ }
+ break;
}
- token = s.substr(start, end - start);
+ token += s.substr(start, end - start);
pos = end;
-
return true;
}
bool op_deny = false;
bool any_cmd = false;
bool got_eq = false;
- bool got_command = false;
- list<string> command;
list<int> services_list;
list<int> uid_list;
bool last_is_comma = false;
op_deny = false;
any_cmd = false;
got_eq = false;
- got_command = false;
- command.clear();
last_is_comma = false;
cap_val = 0;
init = false;
allow_all = true;
} else if (token.compare("command") == 0) {
ASSERT_STATE(op_allow);
- got_command = true;
+ list<string> command;
+ while (get_next_token(s, pos, token)) {
+ if (token.compare(";") == 0)
+ break;
+ command.push_back(token);
+ }
+ cmd_allow.push_back(command);
} else if (token.compare("=") == 0) {
ASSERT_STATE(any_cmd);
got_eq = true;
} else if (is_rwx(token, cap_val)) {
ASSERT_STATE(op_allow || op_deny);
} else if (token.compare(";") != 0) {
- if (got_command) {
- command.push_back(token);
+ ASSERT_STATE(got_eq);
+ if (token.compare(",") == 0) {
+ ASSERT_STATE(!last_is_comma);
} else {
- ASSERT_STATE(got_eq);
- if (token.compare(",") == 0) {
- ASSERT_STATE(!last_is_comma);
- } else {
- last_is_comma = false;
- int service = get_service_id(token);
- if (service != -EINVAL) {
- if (service >= 0) {
- services_list.push_back(service);
- } else {
- generic_dout(0) << "error parsing caps at pos=" << pos << ", unknown service_name: " << token << dendl;
- }
- } else { //must be a uid
- uid_list.push_back(strtoul(token.c_str(), NULL, 10));
+ last_is_comma = false;
+ int service = get_service_id(token);
+ if (service != -EINVAL) {
+ if (service >= 0) {
+ services_list.push_back(service);
+ } else {
+ generic_dout(0) << "error parsing caps at pos=" << pos << ", unknown service_name: " << token << dendl;
}
+ } else { //must be a uid
+ uid_list.push_back(strtoul(token.c_str(), NULL, 10));
}
}
}
if (token.compare(";") == 0 || pos >= s.size()) {
- if (got_command) {
- generic_dout(0) << "parsed command " << command << dendl;
- cmd_allow.push_back(command);
- }
- else if (got_eq) {
+ if (got_eq) {
ASSERT_STATE((services_list.size() > 0) ||
(uid_list.size() > 0));