]> granicus.if.org Git - sudo/commitdiff
No need to have version macros for hooks, callbacks and the sudoers
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 9 Sep 2015 20:56:52 +0000 (14:56 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 9 Sep 2015 20:56:52 +0000 (14:56 -0600)
group plugin.  We can just use the main sudo API macros.  The sudoers
group plugin macros are preserved for source compatibility but are
not documented.

doc/sudo_plugin.cat
doc/sudo_plugin.man.in
doc/sudo_plugin.mdoc.in
include/sudo_plugin.h
plugins/group_file/group_file.c
plugins/group_file/plugin_test.c
plugins/sudoers/group_plugin.c
plugins/sudoers/policy.c
plugins/system_group/system_group.c
src/hooks.c

index daa3c6e861384c8ec993907220fe4da45fda1179..164271a3c7db1a66f3465121b3e5f064eaa7b347 100644 (file)
@@ -799,7 +799,7 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
          *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
      } while(0)
-     #define SUDO_VERSION_SET_MINOR(vp, n) do { \
+     #define SUDO_API_VERSION_SET_MINOR(vp, n) do { \
          *(vp) = (*(vp) & 0xffff0000) | (n); \
      } while(0)
 
@@ -1232,19 +1232,10 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      /* Hook API version major/minor */
      #define SUDO_HOOK_VERSION_MAJOR 1
      #define SUDO_HOOK_VERSION_MINOR 0
-     #define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y)
-     #define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\
+     #define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\
                                                    SUDO_HOOK_VERSION_MINOR)
 
-     /* Getters and setters for hook API version */
-     #define SUDO_HOOK_VERSION_GET_MAJOR(v) ((v) >> 16)
-     #define SUDO_HOOK_VERSION_GET_MINOR(v) ((v) & 0xffff)
-     #define SUDO_HOOK_VERSION_SET_MAJOR(vp, n) do { \
-         *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
-     } while(0)
-     #define SUDO_HOOK_VERSION_SET_MINOR(vp, n) do { \
-         *(vp) = (*(vp) & 0xffff0000) | (n); \
-     } while(0)
+     For getters and setters see the _\bP_\bo_\bl_\bi_\bc_\by _\bp_\bl_\bu_\bg_\bi_\bn _\bA_\bP_\bI.
 
    R\bRe\bem\bmo\bot\bte\be c\bco\bom\bmm\bma\ban\bnd\bd e\bex\bxe\bec\bcu\but\bti\bio\bon\bn
      The s\bsu\bud\bdo\bo front end does not have native support for running remote
@@ -1279,6 +1270,11 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      informational or error messages to the user, which is usually more
      convenient for simple messages where no use input is required.
 
+     _\bC_\bo_\bn_\bv_\be_\br_\bs_\ba_\bt_\bi_\bo_\bn _\bf_\bu_\bn_\bc_\bt_\bi_\bo_\bn _\bs_\bt_\br_\bu_\bc_\bt_\bu_\br_\be_\bs
+
+     The conversation function takes as arguments pointers to the following
+     structures:
+
      struct sudo_conv_message {
      #define SUDO_CONV_PROMPT_ECHO_OFF  0x0001 /* do not echo user input */
      #define SUDO_CONV_PROMPT_ECHO_ON   0x0002 /* echo user input */
@@ -1297,14 +1293,6 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
          char *reply;
      };
 
-     /* Conversation callback API version major/minor */
-     #define SUDO_CONV_CALLBACK_VERSION_MAJOR 1
-     #define SUDO_CONV_CALLBACK_VERSION_MINOR 0
-     #define SUDO_CONV_CALLBACK_MKVERSION(x, y) ((x << 16) | y)
-     #define SUDO_CONV_CALLBACK_VERSION \
-         SUDO_CONV_CALLBACK_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, \
-         SUDO_CONV_CALLBACK_VERSION_MINOR)
-
      typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
      struct sudo_conv_callback {
          unsigned int version;
@@ -1313,6 +1301,11 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
          sudo_conv_callback_fn_t on_resume;
      };
 
+     Pointers to the c\bco\bon\bnv\bve\ber\brs\bsa\bat\bti\bio\bon\bn() and p\bpr\bri\bin\bnt\btf\bf()-style functions are passed in
+     to the plugin's o\bop\bpe\ben\bn() function when the plugin is initialized.  The
+     following type definitions can be used in the declaration of the o\bop\bpe\ben\bn()
+     function:
+
      typedef int (*sudo_conv_t)(int num_msgs,
                   const struct sudo_conv_message msgs[],
                   struct sudo_conv_reply replies[],
@@ -1320,20 +1313,18 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
 
      typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
 
-     Pointers to the c\bco\bon\bnv\bve\ber\brs\bsa\bat\bti\bio\bon\bn() and p\bpr\bri\bin\bnt\btf\bf()-style functions are passed in
-     to the plugin's o\bop\bpe\ben\bn() function when the plugin is initialized.
-
      To use the c\bco\bon\bnv\bve\ber\brs\bsa\bat\bti\bio\bon\bn() function, the plugin must pass an array of
      sudo_conv_message and sudo_conv_reply structures.  There must be a struct
      sudo_conv_message and struct sudo_conv_reply for each message in the
-     conversation.  The struct sudo_conv_callback pointer, if not NULL,
-     contains function pointers that are called when the s\bsu\bud\bdo\bo process is
-     suspended and/or resumed during conversation input.  The functions are
-     passed the signal that caused s\bsu\bud\bdo\bo to be suspended and the _\bc_\bl_\bo_\bs_\bu_\br_\be
-     pointer.  This allows the plugin to release resources such as locks that
-     should not be held indefinitely on suspend and reacquire them on resume.
-     Note that the functions are not actually invoked from within a signal
-     handler.
+     conversation.  The struct sudo_conv_callback pointer, if not NULL, should
+     contain function pointers to be called when the s\bsu\bud\bdo\bo process is suspended
+     and/or resumed during conversation input.  The _\bo_\bn_\b__\bs_\bu_\bs_\bp_\be_\bn_\bd and _\bo_\bn_\b__\br_\be_\bs_\bu_\bm_\be
+     functions are called with the signal that caused s\bsu\bud\bdo\bo to be suspended and
+     the _\bc_\bl_\bo_\bs_\bu_\br_\be pointer from the struct sudo_conv_callback.  The intended use
+     is to allow the plugin to release resources, such as locks, that should
+     not be held indefinitely while suspended and then reacquire them when the
+     process is resumed.  Note that the functions are not actually invoked
+     from within a signal handler.
 
      The plugin is responsible for freeing the reply buffer located in each
      struct sudo_conv_reply, if it is not NULL.  SUDO_CONV_REPL_MAX represents
@@ -1440,16 +1431,7 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      #define GROUP_API_VERSION_MINOR 0
      #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \
                                 GROUP_API_VERSION_MINOR)
-
-     /* Getters and setters for group version */
-     #define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
-     #define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
-     #define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \
-         *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
-     } while(0)
-     #define GROUP_API_VERSION_SET_MINOR(vp, n) do { \
-         *(vp) = (*(vp) & 0xffff0000) | (n); \
-     } while(0)
+     For getters and setters see the _\bP_\bo_\bl_\bi_\bc_\by _\bp_\bl_\bu_\bg_\bi_\bn _\bA_\bP_\bI.
 
 P\bPL\bLU\bUG\bGI\bIN\bN A\bAP\bPI\bI C\bCH\bHA\bAN\bNG\bGE\bEL\bLO\bOG\bG
      The following revisions have been made to the Sudo Plugin API.
index d7a44136c3d231315b57b303aef28bdef35a5a9f..c5bc35e3751bd39bbf930f201cd97e211ad523fa 100644 (file)
@@ -1391,7 +1391,7 @@ will not be called.
 #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e
     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
 } while(0)
-#define SUDO_VERSION_SET_MINOR(vp, n) do { \e
+#define SUDO_API_VERSION_SET_MINOR(vp, n) do { \e
     *(vp) = (*(vp) & 0xffff0000) | (n); \e
 } while(0)
 .RE
@@ -2201,21 +2201,13 @@ return SUDO_HOOK_RET_STOP;
 /* Hook API version major/minor */
 #define SUDO_HOOK_VERSION_MAJOR 1
 #define SUDO_HOOK_VERSION_MINOR 0
-#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y)
-#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
+#define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
                                               SUDO_HOOK_VERSION_MINOR)
-
-/* Getters and setters for hook API version */
-#define SUDO_HOOK_VERSION_GET_MAJOR(v) ((v) >> 16)
-#define SUDO_HOOK_VERSION_GET_MINOR(v) ((v) & 0xffff)
-#define SUDO_HOOK_VERSION_SET_MAJOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
-} while(0)
-#define SUDO_HOOK_VERSION_SET_MINOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0xffff0000) | (n); \e
-} while(0)
 .RE
 .fi
+.PP
+For getters and setters see the
+\fIPolicy plugin API\fR.
 .SS "Remote command execution"
 The
 \fBsudo\fR
@@ -2272,6 +2264,11 @@ A
 function is also available that can be used to display informational
 or error messages to the user, which is usually more convenient for
 simple messages where no use input is required.
+.PP
+\fIConversation function structures\fR
+.PP
+The conversation function takes as arguments pointers to the following
+structures:
 .nf
 .sp
 .RS 0n
@@ -2293,14 +2290,6 @@ struct sudo_conv_reply {
     char *reply;
 };
 
-/* Conversation callback API version major/minor */
-#define SUDO_CONV_CALLBACK_VERSION_MAJOR 1
-#define SUDO_CONV_CALLBACK_VERSION_MINOR 0
-#define SUDO_CONV_CALLBACK_MKVERSION(x, y) ((x << 16) | y)
-#define SUDO_CONV_CALLBACK_VERSION \e
-    SUDO_CONV_CALLBACK_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, \e
-    SUDO_CONV_CALLBACK_VERSION_MINOR)
-
 typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
 struct sudo_conv_callback {
     unsigned int version;
@@ -2308,13 +2297,6 @@ struct sudo_conv_callback {
     sudo_conv_callback_fn_t on_suspend;
     sudo_conv_callback_fn_t on_resume;
 };
-
-typedef int (*sudo_conv_t)(int num_msgs,
-             const struct sudo_conv_message msgs[],
-             struct sudo_conv_reply replies[],
-            struct sudo_conv_callback *callback);
-
-typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
 .RE
 .fi
 .PP
@@ -2326,6 +2308,20 @@ functions are passed
 in to the plugin's
 \fBopen\fR()
 function when the plugin is initialized.
+The following type definitions can be used in the declaration of the
+\fBopen\fR()
+function:
+.nf
+.sp
+.RS 0n
+typedef int (*sudo_conv_t)(int num_msgs,
+             const struct sudo_conv_message msgs[],
+             struct sudo_conv_reply replies[],
+            struct sudo_conv_callback *callback);
+
+typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
+.RE
+.fi
 .PP
 To use the
 \fBconversation\fR()
@@ -2344,17 +2340,22 @@ The
 \fRstruct sudo_conv_callback\fR
 pointer, if not
 \fRNULL\fR,
-contains function pointers that are called when the
+should contain function pointers to be called when the
 \fBsudo\fR
 process is suspended and/or resumed during conversation input.
-The functions are passed the signal that caused
+The
+\fIon_suspend\fR
+and
+\fIon_resume\fR
+functions are called with the signal that caused
 \fBsudo\fR
 to be suspended and the
 \fIclosure\fR
-pointer.
-This allows the plugin to release resources such as locks that
-should not be held indefinitely on suspend and reacquire them
-on resume.
+pointer from the
+\fRstruct sudo_conv_callback\fR.
+The intended use is to allow the plugin to release resources, such as locks,
+that should not be held indefinitely while suspended and then reacquire them
+when the process is resumed.
 Note that the functions are not actually invoked from within a signal handler.
 .PP
 The plugin is responsible for freeing the reply buffer located in each
@@ -2563,18 +2564,10 @@ will be
 #define GROUP_API_VERSION_MINOR 0
 #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e
                            GROUP_API_VERSION_MINOR)
-
-/* Getters and setters for group version */
-#define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
-#define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
-#define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
-} while(0)
-#define GROUP_API_VERSION_SET_MINOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0xffff0000) | (n); \e
-} while(0)
 .RE
 .fi
+For getters and setters see the
+\fIPolicy plugin API\fR.
 .SH "PLUGIN API CHANGELOG"
 The following revisions have been made to the Sudo Plugin API.
 .TP 6n
index b49699aad7a18e889c13cfd22d9311156bbe47c5..d4a5f9ceb78d8a06d18c74976d6d50e805dfdc28 100644 (file)
@@ -1228,7 +1228,7 @@ will not be called.
 #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e
     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
 } while(0)
-#define SUDO_VERSION_SET_MINOR(vp, n) do { \e
+#define SUDO_API_VERSION_SET_MINOR(vp, n) do { \e
     *(vp) = (*(vp) & 0xffff0000) | (n); \e
 } while(0)
 .Ed
@@ -1910,20 +1910,12 @@ return SUDO_HOOK_RET_STOP;
 /* Hook API version major/minor */
 #define SUDO_HOOK_VERSION_MAJOR 1
 #define SUDO_HOOK_VERSION_MINOR 0
-#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y)
-#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
+#define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
                                               SUDO_HOOK_VERSION_MINOR)
-
-/* Getters and setters for hook API version */
-#define SUDO_HOOK_VERSION_GET_MAJOR(v) ((v) >> 16)
-#define SUDO_HOOK_VERSION_GET_MINOR(v) ((v) & 0xffff)
-#define SUDO_HOOK_VERSION_SET_MAJOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
-} while(0)
-#define SUDO_HOOK_VERSION_SET_MINOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0xffff0000) | (n); \e
-} while(0)
 .Ed
+.Pp
+For getters and setters see the
+.Sx Policy plugin API .
 .Ss Remote command execution
 The
 .Nm sudo
@@ -1980,6 +1972,11 @@ A
 function is also available that can be used to display informational
 or error messages to the user, which is usually more convenient for
 simple messages where no use input is required.
+.Pp
+.Em Conversation function structures
+.Pp
+The conversation function takes as arguments pointers to the following
+structures:
 .Bd -literal
 struct sudo_conv_message {
 #define SUDO_CONV_PROMPT_ECHO_OFF  0x0001 /* do not echo user input */
@@ -1999,14 +1996,6 @@ struct sudo_conv_reply {
     char *reply;
 };
 
-/* Conversation callback API version major/minor */
-#define SUDO_CONV_CALLBACK_VERSION_MAJOR 1
-#define SUDO_CONV_CALLBACK_VERSION_MINOR 0
-#define SUDO_CONV_CALLBACK_MKVERSION(x, y) ((x << 16) | y)
-#define SUDO_CONV_CALLBACK_VERSION \e
-    SUDO_CONV_CALLBACK_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, \e
-    SUDO_CONV_CALLBACK_VERSION_MINOR)
-
 typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
 struct sudo_conv_callback {
     unsigned int version;
@@ -2014,13 +2003,6 @@ struct sudo_conv_callback {
     sudo_conv_callback_fn_t on_suspend;
     sudo_conv_callback_fn_t on_resume;
 };
-
-typedef int (*sudo_conv_t)(int num_msgs,
-             const struct sudo_conv_message msgs[],
-             struct sudo_conv_reply replies[],
-            struct sudo_conv_callback *callback);
-
-typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
 .Ed
 .Pp
 Pointers to the
@@ -2031,6 +2013,17 @@ functions are passed
 in to the plugin's
 .Fn open
 function when the plugin is initialized.
+The following type definitions can be used in the declaration of the
+.Fn open
+function:
+.Bd -literal
+typedef int (*sudo_conv_t)(int num_msgs,
+             const struct sudo_conv_message msgs[],
+             struct sudo_conv_reply replies[],
+            struct sudo_conv_callback *callback);
+
+typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
+.Ed
 .Pp
 To use the
 .Fn conversation
@@ -2049,17 +2042,22 @@ The
 .Li struct sudo_conv_callback
 pointer, if not
 .Dv NULL ,
-contains function pointers that are called when the
+should contain function pointers to be called when the
 .Nm sudo
 process is suspended and/or resumed during conversation input.
-The functions are passed the signal that caused
+The
+.Fa on_suspend
+and
+.Fa on_resume
+functions are called with the signal that caused
 .Nm sudo
 to be suspended and the
 .Fa closure
-pointer.
-This allows the plugin to release resources such as locks that
-should not be held indefinitely on suspend and reacquire them
-on resume.
+pointer from the
+.Li struct sudo_conv_callback .
+The intended use is to allow the plugin to release resources, such as locks,
+that should not be held indefinitely while suspended and then reacquire them
+when the process is resumed.
 Note that the functions are not actually invoked from within a signal handler.
 .Pp
 The plugin is responsible for freeing the reply buffer located in each
@@ -2239,17 +2237,9 @@ will be
 #define GROUP_API_VERSION_MINOR 0
 #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e
                            GROUP_API_VERSION_MINOR)
-
-/* Getters and setters for group version */
-#define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
-#define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
-#define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
-} while(0)
-#define GROUP_API_VERSION_SET_MINOR(vp, n) do { \e
-    *(vp) = (*(vp) & 0xffff0000) | (n); \e
-} while(0)
 .Ed
+For getters and setters see the
+.Sx Policy plugin API .
 .Sh PLUGIN API CHANGELOG
 The following revisions have been made to the Sudo Plugin API.
 .Bl -tag -width 4n
index b8fa44591ed369c4767eb3491483defb4a9b9260..dd1df8d69ea527253e8f591a3ceb7f8256856928 100644 (file)
@@ -23,7 +23,7 @@
 #define SUDO_API_MKVERSION(x, y) ((x << 16) | y)
 #define SUDO_API_VERSION SUDO_API_MKVERSION(SUDO_API_VERSION_MAJOR, SUDO_API_VERSION_MINOR)
 
-/* Getters and setters for API version */
+/* Getters and setters for plugin API versions */
 #define SUDO_API_VERSION_GET_MAJOR(v) ((v) >> 16)
 #define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
 #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
@@ -64,8 +64,7 @@ struct sudo_conv_reply {
 /* Conversation callback API version major/minor */
 #define SUDO_CONV_CALLBACK_VERSION_MAJOR       1
 #define SUDO_CONV_CALLBACK_VERSION_MINOR       0
-#define SUDO_CONV_CALLBACK_MKVERSION(x, y) ((x << 16) | y)
-#define SUDO_CONV_CALLBACK_VERSION SUDO_CONV_CALLBACK_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, SUDO_CONV_CALLBACK_VERSION_MINOR)
+#define SUDO_CONV_CALLBACK_VERSION SUDO_API_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, SUDO_CONV_CALLBACK_VERSION_MINOR)
 
 /*
  * Callback struct to be passed to the conversation function.
@@ -106,18 +105,7 @@ struct sudo_hook {
 /* Hook API version major/minor */
 #define SUDO_HOOK_VERSION_MAJOR        1
 #define SUDO_HOOK_VERSION_MINOR        0
-#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y)
-#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR, SUDO_HOOK_VERSION_MINOR)
-
-/* Getters and setters for hook API version */
-#define SUDO_HOOK_VERSION_GET_MAJOR(v) ((v) >> 16)
-#define SUDO_HOOK_VERSION_GET_MINOR(v) ((v) & 0xffff)
-#define SUDO_HOOK_VERSION_SET_MAJOR(vp, n) do { \
-    *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
-} while(0)
-#define SUDO_HOOK_VERSION_SET_MINOR(vp, n) do { \
-    *(vp) = (*(vp) & 0xffff0000) | (n); \
-} while(0)
+#define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR, SUDO_HOOK_VERSION_MINOR)
 
 /*
  * Hook function return values.
@@ -185,17 +173,13 @@ struct io_plugin {
 /* Sudoers group plugin version major/minor */
 #define GROUP_API_VERSION_MAJOR 1
 #define GROUP_API_VERSION_MINOR 0
-#define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | GROUP_API_VERSION_MINOR)
+#define GROUP_API_VERSION SUDO_API_MKVERSION(GROUP_API_VERSION_MAJOR, GROUP_API_VERSION_MINOR)
 
-/* Getters and setters for group version */
-#define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
-#define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
-#define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \
-    *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
-} while(0)
-#define GROUP_API_VERSION_SET_MINOR(vp, n) do { \
-    *(vp) = (*(vp) & 0xffff0000) | (n); \
-} while(0)
+/* Getters and setters for group version (for source compat only) */
+#define GROUP_API_VERSION_GET_MAJOR(v) SUDO_API_VERSION_GET_MAJOR(v)
+#define GROUP_API_VERSION_GET_MINOR(v) SUDO_API_VERSION_GET_MINOR(v)
+#define GROUP_API_VERSION_SET_MAJOR(vp, n) SUDO_API_VERSION_SET_MAJOR(vp, n)
+#define GROUP_API_VERSION_SET_MINOR(vp, n) SUDO_API_VERSION_SET_MINOR(vp, n)
 
 /*
  * version: for compatibility checking
index 788eb8d0c683c3383b587987293854ac0c25034a..f475b698fd6daf17ca976272617643f92580b757 100644 (file)
@@ -62,10 +62,10 @@ sample_init(int version, sudo_printf_t sudo_printf, char *const argv[])
 
     sudo_log = sudo_printf;
 
-    if (GROUP_API_VERSION_GET_MAJOR(version) != GROUP_API_VERSION_MAJOR) {
+    if (SUDO_API_VERSION_GET_MAJOR(version) != GROUP_API_VERSION_MAJOR) {
        sudo_log(SUDO_CONV_ERROR_MSG,
            "group_file: incompatible major version %d, expected %d\n",
-           GROUP_API_VERSION_GET_MAJOR(version),
+           SUDO_API_VERSION_GET_MAJOR(version),
            GROUP_API_VERSION_MAJOR);
        return -1;
     }
index d16d86883ee042a8393f8a264620d6d9407fdb1f..4914250f9ff452f9bae25c5279a0b86f34105870 100644 (file)
@@ -100,10 +100,10 @@ group_plugin_load(char *plugin_info)
        return -1;
     }
 
-    if (GROUP_API_VERSION_GET_MAJOR(group_plugin->version) != GROUP_API_VERSION_MAJOR) {
+    if (SUDO_API_VERSION_GET_MAJOR(group_plugin->version) != GROUP_API_VERSION_MAJOR) {
        fprintf(stderr,
            "%s: incompatible group plugin major version %d, expected %d\n",
-           path, GROUP_API_VERSION_GET_MAJOR(group_plugin->version),
+           path, SUDO_API_VERSION_GET_MAJOR(group_plugin->version),
            GROUP_API_VERSION_MAJOR);
        return -1;
     }
index bbd7d5c290e144e3870b118397d30205ea9c30d5..b26a076a87e4d86afa3712125ba9d89aca6be893 100644 (file)
@@ -104,9 +104,9 @@ group_plugin_load(char *plugin_info)
        goto done;
     }
 
-    if (GROUP_API_VERSION_GET_MAJOR(group_plugin->version) != GROUP_API_VERSION_MAJOR) {
+    if (SUDO_API_VERSION_GET_MAJOR(group_plugin->version) != GROUP_API_VERSION_MAJOR) {
        sudo_warnx(U_("%s: incompatible group plugin major version %d, expected %d"),
-           path, GROUP_API_VERSION_GET_MAJOR(group_plugin->version),
+           path, SUDO_API_VERSION_GET_MAJOR(group_plugin->version),
            GROUP_API_VERSION_MAJOR);
        goto done;
     }
index 3dafb7ebf49dcc43c43fc9de08e0902b256eb699..4b8e6539ae914d66a8b2258fd0dcf0627ec288ab 100644 (file)
@@ -812,8 +812,8 @@ sudoers_policy_register_hooks(int version, int (*register_hook)(struct sudo_hook
        if (register_hook(hook) != 0) {
            sudo_warn_nodebug(
                U_("unable to register hook of type %d (version %d.%d)"),
-               hook->hook_type,SUDO_HOOK_VERSION_GET_MAJOR(hook->hook_version),
-               SUDO_HOOK_VERSION_GET_MINOR(hook->hook_version));
+               hook->hook_type, SUDO_API_VERSION_GET_MAJOR(hook->hook_version),
+               SUDO_API_VERSION_GET_MINOR(hook->hook_version));
        }
     }
 }
index 6093fc32401c8345651c0132b07dd5ae28bd6d8e..1561ec0dfba6d2c363571921a68bea38f9486e42 100644 (file)
@@ -69,10 +69,10 @@ sysgroup_init(int version, sudo_printf_t sudo_printf, char *const argv[])
 
     sudo_log = sudo_printf;
 
-    if (GROUP_API_VERSION_GET_MAJOR(version) != GROUP_API_VERSION_MAJOR) {
+    if (SUDO_API_VERSION_GET_MAJOR(version) != GROUP_API_VERSION_MAJOR) {
        sudo_log(SUDO_CONV_ERROR_MSG,
            "sysgroup_group: incompatible major version %d, expected %d\n",
-           GROUP_API_VERSION_GET_MAJOR(version),
+           SUDO_API_VERSION_GET_MAJOR(version),
            GROUP_API_VERSION_MAJOR);
        return -1;
     }
index 6c867094cc0ef8a0b875237cb8f0ba24c2a207fc..d4e14c88fb3864b0d2f11bc4b4dceea289ba8666 100644 (file)
@@ -150,7 +150,7 @@ register_hook(struct sudo_hook *hook)
     int rval;
     debug_decl(register_hook, SUDO_DEBUG_HOOKS)
 
-    if (SUDO_HOOK_VERSION_GET_MAJOR(hook->hook_version) != SUDO_HOOK_VERSION_MAJOR) {
+    if (SUDO_API_VERSION_GET_MAJOR(hook->hook_version) != SUDO_HOOK_VERSION_MAJOR) {
        /* Major versions must match. */
        errno = EINVAL;
        rval = -1;
@@ -214,7 +214,7 @@ deregister_hook(struct sudo_hook *hook)
     int rval = 0;
     debug_decl(deregister_hook, SUDO_DEBUG_HOOKS)
 
-    if (SUDO_HOOK_VERSION_GET_MAJOR(hook->hook_version) != SUDO_HOOK_VERSION_MAJOR) {
+    if (SUDO_API_VERSION_GET_MAJOR(hook->hook_version) != SUDO_HOOK_VERSION_MAJOR) {
        /* Major versions must match. */
        rval = -1;
     } else {