* ParseUsersInfoDocument extracts and processes the fields of the BSON document * for the usersInfo command. */
| 1523 | * for the usersInfo command. |
| 1524 | */ |
| 1525 | static void |
| 1526 | ParseUsersInfoDocument(const bson_value_t *usersInfoBson, GetUserSpec *spec) |
| 1527 | { |
| 1528 | bson_iter_t iter; |
| 1529 | BsonValueInitIterator(usersInfoBson, &iter); |
| 1530 | |
| 1531 | bool forAllDBsFound = false; |
| 1532 | bool userFound = false; |
| 1533 | bool dbFound = false; |
| 1534 | while (bson_iter_next(&iter)) |
| 1535 | { |
| 1536 | const char *bsonDocKey = bson_iter_key(&iter); |
| 1537 | if (strcmp(bsonDocKey, "forAllDBs") == 0) |
| 1538 | { |
| 1539 | if (!BSON_ITER_HOLDS_BOOL(&iter) || bson_iter_as_bool(&iter) != true) |
| 1540 | { |
| 1541 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1542 | errmsg( |
| 1543 | "Unsupported value specified for 'forAllDBs'."))); |
| 1544 | } |
| 1545 | |
| 1546 | /* Because we only support users provisioned at admin database level, forAllDBs doesn't have any impact, so we only set spec->showAllUsers to true */ |
| 1547 | spec->showAllUsers = true; |
| 1548 | forAllDBsFound = true; |
| 1549 | } |
| 1550 | else if (strcmp(bsonDocKey, "db") == 0 && BSON_ITER_HOLDS_UTF8(&iter)) |
| 1551 | { |
| 1552 | dbFound = true; |
| 1553 | uint32_t strLength; |
| 1554 | const char *db = bson_iter_utf8(&iter, &strLength); |
| 1555 | if (strcmp(db, "admin") != 0) |
| 1556 | { |
| 1557 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1558 | errmsg( |
| 1559 | "Unsupported value specified for 'db' field. Only 'admin' is allowed."), |
| 1560 | errdetail_log( |
| 1561 | "Unsupported value specified for 'db' field. Only 'admin' is allowed."))); |
| 1562 | } |
| 1563 | } |
| 1564 | else if (strcmp(bsonDocKey, "user") == 0 && BSON_ITER_HOLDS_UTF8( |
| 1565 | &iter)) |
| 1566 | { |
| 1567 | userFound = true; |
| 1568 | uint32_t strLength; |
| 1569 | const char *userString = bson_iter_utf8(&iter, &strLength); |
| 1570 | spec->user = (StringView) { |
| 1571 | .string = userString, |
| 1572 | .length = strLength |
| 1573 | }; |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /* The usersInfo document must contain either 'forAllDBs' or (exclusive) 'user' and 'db' together*/ |
| 1578 | if (userFound ^ dbFound) |
| 1579 | { |
| 1580 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1581 | errmsg( |
| 1582 | "'usersInfo' document must contain both 'user' and 'db' together."))); |
no test coverage detected