-static const struct {
- rights_type bit;
- const char *name;
-} rights_names[] = {
- { RIGHT_READ, "read" },
- { RIGHT_PLAY, "play" },
- { RIGHT_MOVE_ANY, "move any" },
- { RIGHT_MOVE_MINE, "move mine" },
- { RIGHT_MOVE_RANDOM, "move random" },
- { RIGHT_REMOVE_ANY, "remove any" },
- { RIGHT_REMOVE_MINE, "remove mine" },
- { RIGHT_REMOVE_RANDOM, "remove random" },
- { RIGHT_SCRATCH_ANY, "scratch any" },
- { RIGHT_SCRATCH_MINE, "scratch mine" },
- { RIGHT_SCRATCH_RANDOM, "scratch random" },
- { RIGHT_VOLUME, "volume" },
- { RIGHT_ADMIN, "admin" },
- { RIGHT_RESCAN, "rescan" },
- { RIGHT_REGISTER, "register" },
- { RIGHT_USERINFO, "userinfo" },
- { RIGHT_PREFS, "prefs" },
- { RIGHT_GLOBAL_PREFS, "global prefs" }
-};
-#define NRIGHTS (sizeof rights_names / sizeof *rights_names)
-
-/** @brief Convert a rights word to a string */
-static char *rights_string(rights_type r) {
- struct dynstr d[1];
- size_t n;
-
- dynstr_init(d);
- for(n = 0; n < NRIGHTS; ++n) {
- if(r & rights_names[n].bit) {
- if(d->nvec)
- dynstr_append(d, ',');
- dynstr_append_string(d, rights_names[n].name);
- }
+/** @brief Return non-zero for a valid username
+ *
+ * Currently we only allow the letters and digits in ASCII. We could be more
+ * liberal than this but it is a nice simple test. It is critical that
+ * semicolons are never allowed.
+ */
+static int valid_username(const char *user) {
+ if(!*user)
+ return 0;
+ while(*user) {
+ const uint8_t c = *user++;
+ /* For now we are very strict */
+ if((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9'))
+ /* ok */;
+ else
+ return 0;