[PATCH 09/25] Constify the reason string throughout the authorization check framework

Alan Coopersmith alan.coopersmith at oracle.com
Sun Dec 11 10:16:22 PST 2011


Almost all of the places the string is assigned point to a literal
string constant, so use const char * for those, and const char **
for function calls that return it via an argument.   Fortunately
the top level function, ClientAuthorized, which returns the string
as its return value is called from only one place, ProcEstablishConnection.

ProcEstablishConnection stores either that return value or a string literal
in char *reason.  It only uses reason as an argument to SendConnSetup.
SendConnSetup passes the reason argument to strlen & WriteToClient,
both of which already have const qualifiers on their args.
Thus added const to the reason variable in ProcEstablishConnection
and the reason argument to SendConnSetup.

Fixes gcc warnings:
dispatch.c: In function 'ProcEstablishConnection':
dispatch.c:3711:9: warning: assignment discards qualifiers from pointer target type
auth.c: In function 'CheckAuthorization':
auth.c:218:14: warning: assignment discards qualifiers from pointer target type
auth.c:220:20: warning: assignment discards qualifiers from pointer target type
connection.c: In function 'ClientAuthorized':
connection.c:683:3: warning: return discards qualifiers from pointer target type
mitauth.c: In function 'MitCheckCookie':
mitauth.c:88:13: warning: assignment discards qualifiers from pointer target type
xdmauth.c:259:14: warning: assignment discards qualifiers from pointer target type
xdmauth.c:270:14: warning: assignment discards qualifiers from pointer target type
xdmauth.c:277:11: warning: assignment discards qualifiers from pointer target type
xdmauth.c:293:15: warning: assignment discards qualifiers from pointer target type
xdmauth.c:313:14: warning: assignment discards qualifiers from pointer target type
xdmauth.c:322:11: warning: assignment discards qualifiers from pointer target type
rpcauth.c: In function 'SecureRPCCheck':
rpcauth.c:136:10: warning: assignment discards qualifiers from pointer target type

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dix/dispatch.c  |    5 +++--
 include/os.h    |    4 ++--
 os/auth.c       |    2 +-
 os/connection.c |    4 ++--
 os/mitauth.c    |    2 +-
 os/osdep.h      |    2 +-
 os/rpcauth.c    |    2 +-
 os/xdmauth.c    |    4 ++--
 8 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/dix/dispatch.c b/dix/dispatch.c
index b39271f..048dff6 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3600,7 +3600,7 @@ ProcInitialConnection(ClientPtr client)
 }
 
 static int
-SendConnSetup(ClientPtr client, char *reason)
+SendConnSetup(ClientPtr client, const char *reason)
 {
     xWindowRoot *root;
     int i;
@@ -3699,7 +3699,8 @@ SendConnSetup(ClientPtr client, char *reason)
 int
 ProcEstablishConnection(ClientPtr client)
 {
-    char *reason, *auth_proto, *auth_string;
+    const char *reason;
+    char *auth_proto, *auth_string;
     xConnClientPrefix *prefix;
     REQUEST(xReq);
 
diff --git a/include/os.h b/include/os.h
index 0b50241..48ce329 100644
--- a/include/os.h
+++ b/include/os.h
@@ -127,7 +127,7 @@ extern _X_EXPORT void CloseWellKnownConnections(void);
 
 extern _X_EXPORT XID AuthorizationIDOfClient(ClientPtr /*client*/);
 
-extern _X_EXPORT char *ClientAuthorized(
+extern _X_EXPORT const char *ClientAuthorized(
     ClientPtr /*client*/,
     unsigned int /*proto_n*/,
     char* /*auth_proto*/,
@@ -415,7 +415,7 @@ extern _X_EXPORT XID CheckAuthorization(
     unsigned int /*datalength*/,
     const char * /*data*/,
     ClientPtr /*client*/,
-    char ** /*reason*/
+    const char ** /*reason*/
 );
 
 extern _X_EXPORT void ResetAuthorization(void);
diff --git a/os/auth.c b/os/auth.c
index 9d36249..6669c14 100644
--- a/os/auth.c
+++ b/os/auth.c
@@ -163,7 +163,7 @@ CheckAuthorization (
     unsigned int data_length,
     const char	*data,
     ClientPtr client,
-    char	**reason)	/* failure message.  NULL for default msg */
+    const char	**reason)	/* failure message.  NULL for default msg */
 {
     int	i;
     struct stat buf;
diff --git a/os/connection.c b/os/connection.c
index 6f480de..8a677a7 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -629,7 +629,7 @@ AuthorizationIDOfClient(ClientPtr client)
  *
  *****************************************************************/
 
-char *
+const char *
 ClientAuthorized(ClientPtr client, 
     unsigned int proto_n, char *auth_proto, 
     unsigned int string_n, char *auth_string)
@@ -639,7 +639,7 @@ ClientAuthorized(ClientPtr client,
     int 		family;
     int			fromlen;
     XID	 		auth_id;
-    char	 	*reason = NULL;
+    const char	 	*reason = NULL;
     XtransConnInfo	trans_conn;
 
     priv = (OsCommPtr)client->osPrivate;
diff --git a/os/mitauth.c b/os/mitauth.c
index 4b8f6e9..477736e 100644
--- a/os/mitauth.c
+++ b/os/mitauth.c
@@ -76,7 +76,7 @@ MitCheckCookie (
     unsigned short	data_length,
     const char		*data,
     ClientPtr		client,
-    char		**reason)
+    const char		**reason)
 {
     struct auth	*auth;
 
diff --git a/os/osdep.h b/os/osdep.h
index 72bd7d7..71a7e44 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -137,7 +137,7 @@ typedef void (*AuthInitFunc) (AuthInitArgs);
 #define AuthAddCArgs unsigned short data_length, const char *data, XID id
 typedef int (*AuthAddCFunc) (AuthAddCArgs);
 
-#define AuthCheckArgs unsigned short data_length, const char *data, ClientPtr client, char **reason
+#define AuthCheckArgs unsigned short data_length, const char *data, ClientPtr client, const char **reason
 typedef XID (*AuthCheckFunc) (AuthCheckArgs);
 
 #define AuthFromIDArgs XID id, unsigned short *data_lenp, char **datap
diff --git a/os/rpcauth.c b/os/rpcauth.c
index 989a49a..63b97b6 100644
--- a/os/rpcauth.c
+++ b/os/rpcauth.c
@@ -128,7 +128,7 @@ static char rpc_error[MAXNETNAMELEN+50];
 
 _X_HIDDEN XID
 SecureRPCCheck (unsigned short data_length, const char *data,
-    ClientPtr client, char **reason)
+    ClientPtr client, const char **reason)
 {
     char *fullname;
     
diff --git a/os/xdmauth.c b/os/xdmauth.c
index b8cbada..733fda5 100644
--- a/os/xdmauth.c
+++ b/os/xdmauth.c
@@ -248,7 +248,7 @@ XdmClientAuthTimeout (long now)
 
 static XdmClientAuthPtr
 XdmAuthorizationValidate (unsigned char *plain, int length, 
-    XdmAuthKeyPtr rho, ClientPtr xclient, char **reason)
+    XdmAuthKeyPtr rho, ClientPtr xclient, const char **reason)
 {
     XdmClientAuthPtr	client, existing;
     long		now;
@@ -376,7 +376,7 @@ XdmAddCookie (unsigned short data_length, const char *data, XID id)
 
 XID
 XdmCheckCookie (unsigned short cookie_length, const char *cookie,
-    ClientPtr xclient, char **reason)
+    ClientPtr xclient, const char **reason)
 {
     XdmAuthorizationPtr	auth;
     XdmClientAuthPtr	client;
-- 
1.7.3.2



More information about the xorg-devel mailing list