diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-12 23:08:14 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-19 15:43:29 -0700 |
commit | cd9667d6be072a9c736e49c679b55852f7b30a6c (patch) | |
tree | c99c10d4c0caea96cc5a5420532eccaa60efe976 /lib9p/srv.c | |
parent | 6381e08fd03e322d7d95973ca00c5605afb67707 (diff) |
lib9p: Don't nul-terminate strings, add some string utils
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index d5b643d..9eb945c 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -143,11 +143,8 @@ static void respond_error(struct _lib9p_srv_req *req) { ssize_t r; struct lib9p_msg_Rerror host = { .tag = req->tag, - .ename = { - .len = strnlen(req->ctx.basectx.err_msg, - CONFIG_9P_MAX_ERR_SIZE), - .utf8 = req->ctx.basectx.err_msg, - }, + .ename = lib9p_strn(req->ctx.basectx.err_msg, + CONFIG_9P_MAX_ERR_SIZE), #if CONFIG_9P_ENABLE_9P2000_u .errno = req->ctx.basectx.err_num, #endif @@ -443,14 +440,14 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx, '0' <= req->version.utf8[3] && req->version.utf8[3] <= '9' && '0' <= req->version.utf8[4] && req->version.utf8[4] <= '9' && '0' <= req->version.utf8[5] && req->version.utf8[5] <= '9' && - (req->version.utf8[6] == '\0' || req->version.utf8[6] == '.')) { + (req->version.len == 6 || req->version.utf8[6] == '.')) { version = LIB9P_VER_9P2000; #if CONFIG_9P_ENABLE_9P2000_u - if (strcmp(&req->version.utf8[6], ".u") == 0) + if (lib9p_str_eq(lib9p_str_sliceleft(req->version, 6), lib9p_str(".u"))) version = LIB9P_VER_9P2000_u; #endif #if CONFIG_9P_ENABLE_9P2000_e - if (strcmp(&req->version.utf8[6], ".e") == 0) + if (lib9p_str_eq(lib9p_str_sliceleft(req->version, 6), lib9p_str(".e"))) version = LIB9P_VER_9P2000_e; #endif } @@ -463,11 +460,7 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx, return; } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" - resp->version.utf8 = lib9p_version_str(version); -#pragma GCC diagnostic pop - resp->version.len = strlen(resp->version.utf8); + resp->version = lib9p_str((char *)lib9p_version_str(version)); /* cast to discard "const" qualifier */ resp->max_msg_size = (CONFIG_9P_MAX_MSG_SIZE < req->max_msg_size) ? CONFIG_9P_MAX_MSG_SIZE : req->max_msg_size; @@ -511,7 +504,7 @@ static void handle_Tauth(struct _lib9p_srv_req *ctx, util_handler_common(ctx, req, resp); ctx->ctx.uid = req->n_uid; - ctx->ctx.uname = req->uname.utf8; + ctx->ctx.uname = req->uname; struct lib9p_srv *srv = ctx->parent_sess->parent_conn->parent_srv; if (!srv->auth) { @@ -520,7 +513,7 @@ static void handle_Tauth(struct _lib9p_srv_req *ctx, return; } - srv->auth(&ctx->ctx, req->aname.utf8); + srv->auth(&ctx->ctx, req->aname); lib9p_error(&ctx->ctx.basectx, LINUX_EOPNOTSUPP, "TODO: auth not implemented"); } @@ -531,7 +524,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, util_handler_common(ctx, req, resp); ctx->ctx.uid = req->n_uid; - ctx->ctx.uname = req->uname.utf8; + ctx->ctx.uname = req->uname; struct lib9p_srv *srv = ctx->parent_sess->parent_conn->parent_srv; if (srv->auth) { @@ -543,14 +536,16 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, else if (fh->type != FH_AUTH) lib9p_error(&ctx->ctx.basectx, LINUX_EACCES, "FID provided as auth-file is not an auth-file"); - else if (strcmp(fh->data.auth.uname, req->uname.utf8) != 0) + else if (!lib9p_str_eq(fh->data.auth.uname, req->uname)) lib9p_errorf(&ctx->ctx.basectx, - LINUX_EACCES, "FID provided as auth-file is for user=\"%s\" and cannot be used for user=\"%s\"", - fh->data.auth.uname, req->uname.utf8); - else if (strcmp(fh->data.auth.aname, req->aname.utf8) != 0) + LINUX_EACCES, "FID provided as auth-file is for user=\"%.*s\" and cannot be used for user=\"%.*s\"", + fh->data.auth.uname.len, fh->data.auth.uname.utf8, + req->uname.len, req->uname.utf8); + else if (!lib9p_str_eq(fh->data.auth.aname, req->aname)) lib9p_errorf(&ctx->ctx.basectx, - LINUX_EACCES, "FID provided as auth-file is for tree=\"%s\" and cannot be used for tree=\"%s\"", - fh->data.auth.aname, req->aname.utf8); + LINUX_EACCES, "FID provided as auth-file is for tree=\"%.*s\" and cannot be used for tree=\"%.*s\"", + fh->data.auth.aname.len, fh->data.auth.aname.utf8, + req->aname.len, req->aname.utf8); else if (!fh->data.auth.authenticated) lib9p_error(&ctx->ctx.basectx, LINUX_EACCES, "FID provided as auth-file has not completed authentication"); @@ -575,7 +570,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, return; } - implements_lib9p_srv_file *rootdir = srv->rootdir(&ctx->ctx, req->aname.utf8); + implements_lib9p_srv_file *rootdir = srv->rootdir(&ctx->ctx, req->aname); assert((rootdir == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx)); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; @@ -647,7 +642,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, resp->wqid = (struct lib9p_qid *)(&resp[1]); for (resp->nwqid = 0; resp->nwqid < req->nwname; resp->nwqid++) { implements_lib9p_srv_file *member; - if (strcmp(req->wname[resp->nwqid].utf8, "..") == 0) { + if (lib9p_str_eq(req->wname[resp->nwqid], lib9p_str(".."))) { member = dir->_parent_dir; } else { if (!isdir) { @@ -656,7 +651,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, break; } - member = VCALL(dir, dopen, &ctx->ctx, req->wname[resp->nwqid].utf8); + member = VCALL(dir, dopen, &ctx->ctx, req->wname[resp->nwqid]); assert((member == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx)); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) break; |