os: auth: use strlen() for auth proto name length
No need to explicitly hard-code strings lengths when we can use standard strlen(). Those code pathes are so cold that trying to spare a few cycled for an (usually inlined) strlen() doesn't seem to justify any extra care. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
58e661e1cc
commit
0da8fc466d
18
os/auth.c
18
os/auth.c
|
@ -53,7 +53,6 @@ from The Open Group.
|
||||||
#include "mitauth.h"
|
#include "mitauth.h"
|
||||||
|
|
||||||
struct protocol {
|
struct protocol {
|
||||||
unsigned short name_length;
|
|
||||||
const char *name;
|
const char *name;
|
||||||
AuthAddCFunc Add; /* new authorization data */
|
AuthAddCFunc Add; /* new authorization data */
|
||||||
AuthCheckFunc Check; /* verify client authorization data */
|
AuthCheckFunc Check; /* verify client authorization data */
|
||||||
|
@ -67,7 +66,6 @@ struct protocol {
|
||||||
|
|
||||||
static struct protocol protocols[] = {
|
static struct protocol protocols[] = {
|
||||||
{
|
{
|
||||||
.name_length = 18,
|
|
||||||
.name = "MIT-MAGIC-COOKIE-1",
|
.name = "MIT-MAGIC-COOKIE-1",
|
||||||
.Add = MitAddCookie,
|
.Add = MitAddCookie,
|
||||||
.Check = MitCheckCookie,
|
.Check = MitCheckCookie,
|
||||||
|
@ -80,7 +78,6 @@ static struct protocol protocols[] = {
|
||||||
},
|
},
|
||||||
#ifdef HASXDMAUTH
|
#ifdef HASXDMAUTH
|
||||||
{
|
{
|
||||||
.name_length = 19,
|
|
||||||
.name = "XDM-AUTHORIZATION-1",
|
.name = "XDM-AUTHORIZATION-1",
|
||||||
.Add = XdmAddCookie,
|
.Add = XdmAddCookie,
|
||||||
.Check = XdmCheckCookie,
|
.Check = XdmCheckCookie,
|
||||||
|
@ -132,7 +129,7 @@ LoadAuthorization(void)
|
||||||
|
|
||||||
while ((auth = XauReadAuth(f)) != 0) {
|
while ((auth = XauReadAuth(f)) != 0) {
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
||||||
if (protocols[i].name_length == auth->name_length &&
|
if (strlen(protocols[i].name) == auth->name_length &&
|
||||||
memcmp(protocols[i].name, auth->name,
|
memcmp(protocols[i].name, auth->name,
|
||||||
(int) auth->name_length) == 0 && protocols[i].Add) {
|
(int) auth->name_length) == 0 && protocols[i].Add) {
|
||||||
++count;
|
++count;
|
||||||
|
@ -158,8 +155,7 @@ RegisterAuthorizations(void)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++)
|
for (i = 0; i < NUM_AUTHORIZATION; i++)
|
||||||
XdmcpRegisterAuthorization(protocols[i].name,
|
XdmcpRegisterAuthorization(protocols[i].name);
|
||||||
(int) protocols[i].name_length);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -210,7 +206,7 @@ CheckAuthorization(unsigned int name_length,
|
||||||
}
|
}
|
||||||
if (name_length) {
|
if (name_length) {
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
||||||
if (protocols[i].name_length == name_length &&
|
if (strlen(protocols[i].name) == name_length &&
|
||||||
memcmp(protocols[i].name, name, (int) name_length) == 0) {
|
memcmp(protocols[i].name, name, (int) name_length) == 0) {
|
||||||
return (*protocols[i].Check) (data_length, data, client,
|
return (*protocols[i].Check) (data_length, data, client,
|
||||||
reason);
|
reason);
|
||||||
|
@ -244,7 +240,7 @@ AuthorizationFromID(XID id,
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
||||||
if (protocols[i].FromID &&
|
if (protocols[i].FromID &&
|
||||||
(*protocols[i].FromID) (id, data_lenp, datap)) {
|
(*protocols[i].FromID) (id, data_lenp, datap)) {
|
||||||
*name_lenp = protocols[i].name_length;
|
*name_lenp = strlen(protocols[i].name);
|
||||||
*namep = protocols[i].name;
|
*namep = protocols[i].name;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -260,7 +256,7 @@ RemoveAuthorization(unsigned short name_length,
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
||||||
if (protocols[i].name_length == name_length &&
|
if (strlen(protocols[i].name) == name_length &&
|
||||||
memcmp(protocols[i].name, name, (int) name_length) == 0 &&
|
memcmp(protocols[i].name, name, (int) name_length) == 0 &&
|
||||||
protocols[i].Remove) {
|
protocols[i].Remove) {
|
||||||
return (*protocols[i].Remove) (data_length, data);
|
return (*protocols[i].Remove) (data_length, data);
|
||||||
|
@ -276,7 +272,7 @@ AddAuthorization(unsigned name_length, const char *name,
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
||||||
if (protocols[i].name_length == name_length &&
|
if (strlen(protocols[i].name) == name_length &&
|
||||||
memcmp(protocols[i].name, name, (int) name_length) == 0 &&
|
memcmp(protocols[i].name, name, (int) name_length) == 0 &&
|
||||||
protocols[i].Add) {
|
protocols[i].Add) {
|
||||||
return (*protocols[i].Add) (data_length, data, FakeClientID(0));
|
return (*protocols[i].Add) (data_length, data, FakeClientID(0));
|
||||||
|
@ -297,7 +293,7 @@ GenerateAuthorization(unsigned name_length,
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
for (i = 0; i < NUM_AUTHORIZATION; i++) {
|
||||||
if (protocols[i].name_length == name_length &&
|
if (strlen(protocols[i].name) == name_length &&
|
||||||
memcmp(protocols[i].name, name, (int) name_length) == 0 &&
|
memcmp(protocols[i].name, name, (int) name_length) == 0 &&
|
||||||
protocols[i].Generate) {
|
protocols[i].Generate) {
|
||||||
return (*protocols[i].Generate) (data_length, data,
|
return (*protocols[i].Generate) (data_length, data,
|
||||||
|
|
|
@ -536,11 +536,12 @@ XdmcpRegisterAuthorizations(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XdmcpRegisterAuthorization(const char *name, int namelen)
|
XdmcpRegisterAuthorization(const char *name)
|
||||||
{
|
{
|
||||||
ARRAY8 authName;
|
ARRAY8 authName;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
size_t namelen = strlen(name);
|
||||||
authName.data = calloc(namelen, sizeof(CARD8));
|
authName.data = calloc(namelen, sizeof(CARD8));
|
||||||
if (!authName.data)
|
if (!authName.data)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -9,7 +9,7 @@ void XdmcpUseMsg(void);
|
||||||
int XdmcpOptions(int argc, char **argv, int i);
|
int XdmcpOptions(int argc, char **argv, int i);
|
||||||
void XdmcpRegisterConnection(int type, const char *address, int addrlen);
|
void XdmcpRegisterConnection(int type, const char *address, int addrlen);
|
||||||
void XdmcpRegisterAuthorizations(void);
|
void XdmcpRegisterAuthorizations(void);
|
||||||
void XdmcpRegisterAuthorization(const char *name, int namelen);
|
void XdmcpRegisterAuthorization(const char *name);
|
||||||
void XdmcpInit(void);
|
void XdmcpInit(void);
|
||||||
void XdmcpReset(void);
|
void XdmcpReset(void);
|
||||||
void XdmcpOpenDisplay(int sock);
|
void XdmcpOpenDisplay(int sock);
|
||||||
|
|
Loading…
Reference in New Issue