Skip to contentSkip to conversation

header file issues with 2002031409

PATCH Russell Coker 1 participant 1 message Mar 18, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have attached a patch that fixes a couple of header file problems.

Firstly "new" is a key word in C++ and using it in a C program is generally not a good idea. It's especially bad when you accidentally put your compiler into C++ mode and get strange errors.

One thing that you might consider is putting the following in the header files:
#ifdef __cplusplus
extern "C" {
#endif

If the above is put before the declarations of functions and the following is put afterwards then anyone can just include the headers in their C or C++ programs without any problem.

#ifdef __cplusplus
extern "C" {
#endif

The next thing is that I had problems with proc_secure.h being included multiple times in one of my programs (and as it was being included by other headers avoiding this was more pain than it was worth).

Would it be possible to put header file protection like this around all the headers?

Signature · 4 lines
If you send email to me or to a mailing list that I use which has >4 lines
of legalistic junk at the end then you are specifically authorizing me to do
whatever I wish with the message and all other messages from your domain, by
posting the message you agree that your long legalistic sig is void.
libsecure/src/get_user_sid.c +12 -12
@@ -733,7 +733,7 @@
  */
 int parts_to_security_context (const char* user, const char* role, 
                                const char* type,
-                               const char* level, security_context_t* new)
+                               const char* level, security_context_t* New)
 {
     int userlen,   /* the length of the user field           */
         rolelen,   /* the length of the role field           */
@@ -766,26 +766,26 @@
 #endif
 
     /* Malloc space for the new security context */
-    (*new) = (security_context_t)malloc (sizeof(char) * newlen);
-    if ((*new) == NULL)
+    (*New) = (security_context_t)malloc (sizeof(char) * newlen);
+    if ((*New) == NULL)
     {
         fprintf (stderr, "Unable to malloc\n");
         return 0;
     }
 
     /* copy the parts into the new security context with :'s separating them */
-    strncpy ((*new), user, userlen);
-    (*new)[userlen] = ':';
-    strncpy (&(*new)[userlen+1], role, rolelen);
-    (*new)[userlen+rolelen+1] = ':';
-    strncpy (&(*new)[userlen+rolelen+2], type, typelen);
+    strncpy ((*New), user, userlen);
+    (*New)[userlen] = ':';
+    strncpy (&(*New)[userlen+1], role, rolelen);
+    (*New)[userlen+rolelen+1] = ':';
+    strncpy (&(*New)[userlen+rolelen+2], type, typelen);
 
 #ifdef CONFIG_FLASK_MLS
-    (*new)[userlen+rolelen+typelen+2] = ':';
-    strncpy (&(*new)[userlen+rolelen+typelen+3], level, levellen);
-    (*new)[userlen+rolelen+typelen+levellen+3] = '\0';
+    (*New)[userlen+rolelen+typelen+2] = ':';
+    strncpy (&(*New)[userlen+rolelen+typelen+3], level, levellen);
+    (*New)[userlen+rolelen+typelen+levellen+3] = '\0';
 #else
-    (*new)[userlen+rolelen+typelen+2] = '\0';
+    (*New)[userlen+rolelen+typelen+2] = '\0';
 #endif
 
     /* If we've made it this far, we're successful */
libsecure/include/proc_secure.h +4 -1
@@ -1,3 +1,6 @@
+#ifndef PROC_SECURE_H
+#define PROC_SECURE_H
+
 #include <unistd.h>
 #include <linux/flask/flask.h>
 
@@ -30,4 +33,4 @@
 			   security_id_t sid, 
 			   char *const argv[]);
 
-
+#endif
libsecure/include/get_user_sid.h +1 -1
@@ -53,5 +53,5 @@
                                char** role, char** type, char** domain);
 int parts_to_security_context (const char* user, const char* role, 
                                const char* type,
-                               const char* domain, security_context_t* new);
+                               const char* domain, security_context_t* New);
 #endif  /* ifndef _GET_USER_SID_H_ */