No need to have version macros for hooks, callbacks and the sudoers

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.
This commit is contained in:
Todd C. Miller
2015-09-09 14:56:52 -06:00
parent c45559e6c8
commit edfeee6a7a
10 changed files with 115 additions and 166 deletions

View File

@@ -799,7 +799,7 @@ DDEESSCCRRIIPPTTIIOONN
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \ #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \ *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
} while(0) } while(0)
#define SUDO_VERSION_SET_MINOR(vp, n) do { \ #define SUDO_API_VERSION_SET_MINOR(vp, n) do { \
*(vp) = (*(vp) & 0xffff0000) | (n); \ *(vp) = (*(vp) & 0xffff0000) | (n); \
} while(0) } while(0)
@@ -1232,19 +1232,10 @@ DDEESSCCRRIIPPTTIIOONN
/* Hook API version major/minor */ /* Hook API version major/minor */
#define SUDO_HOOK_VERSION_MAJOR 1 #define SUDO_HOOK_VERSION_MAJOR 1
#define SUDO_HOOK_VERSION_MINOR 0 #define SUDO_HOOK_VERSION_MINOR 0
#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y) #define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\
#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\
SUDO_HOOK_VERSION_MINOR) SUDO_HOOK_VERSION_MINOR)
/* Getters and setters for hook API version */ For getters and setters see the _P_o_l_i_c_y _p_l_u_g_i_n _A_P_I.
#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)
RReemmoottee ccoommmmaanndd eexxeeccuuttiioonn RReemmoottee ccoommmmaanndd eexxeeccuuttiioonn
The ssuuddoo front end does not have native support for running remote The ssuuddoo front end does not have native support for running remote
@@ -1279,6 +1270,11 @@ DDEESSCCRRIIPPTTIIOONN
informational or error messages to the user, which is usually more informational or error messages to the user, which is usually more
convenient for simple messages where no use input is required. convenient for simple messages where no use input is required.
_C_o_n_v_e_r_s_a_t_i_o_n _f_u_n_c_t_i_o_n _s_t_r_u_c_t_u_r_e_s
The conversation function takes as arguments pointers to the following
structures:
struct sudo_conv_message { struct sudo_conv_message {
#define SUDO_CONV_PROMPT_ECHO_OFF 0x0001 /* do not echo user input */ #define SUDO_CONV_PROMPT_ECHO_OFF 0x0001 /* do not echo user input */
#define SUDO_CONV_PROMPT_ECHO_ON 0x0002 /* echo user input */ #define SUDO_CONV_PROMPT_ECHO_ON 0x0002 /* echo user input */
@@ -1297,14 +1293,6 @@ DDEESSCCRRIIPPTTIIOONN
char *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 \
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); typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
struct sudo_conv_callback { struct sudo_conv_callback {
unsigned int version; unsigned int version;
@@ -1313,6 +1301,11 @@ DDEESSCCRRIIPPTTIIOONN
sudo_conv_callback_fn_t on_resume; sudo_conv_callback_fn_t on_resume;
}; };
Pointers to the ccoonnvveerrssaattiioonn() and pprriinnttff()-style functions are passed in
to the plugin's ooppeenn() function when the plugin is initialized. The
following type definitions can be used in the declaration of the ooppeenn()
function:
typedef int (*sudo_conv_t)(int num_msgs, typedef int (*sudo_conv_t)(int num_msgs,
const struct sudo_conv_message msgs[], const struct sudo_conv_message msgs[],
struct sudo_conv_reply replies[], struct sudo_conv_reply replies[],
@@ -1320,20 +1313,18 @@ DDEESSCCRRIIPPTTIIOONN
typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...); typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
Pointers to the ccoonnvveerrssaattiioonn() and pprriinnttff()-style functions are passed in
to the plugin's ooppeenn() function when the plugin is initialized.
To use the ccoonnvveerrssaattiioonn() function, the plugin must pass an array of To use the ccoonnvveerrssaattiioonn() 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 sudo_conv_reply structures. There must be a struct
sudo_conv_message and struct sudo_conv_reply for each message in the sudo_conv_message and struct sudo_conv_reply for each message in the
conversation. The struct sudo_conv_callback pointer, if not NULL, conversation. The struct sudo_conv_callback pointer, if not NULL, should
contains function pointers that are called when the ssuuddoo process is contain function pointers to be called when the ssuuddoo process is suspended
suspended and/or resumed during conversation input. The functions are and/or resumed during conversation input. The _o_n___s_u_s_p_e_n_d and _o_n___r_e_s_u_m_e
passed the signal that caused ssuuddoo to be suspended and the _c_l_o_s_u_r_e functions are called with the signal that caused ssuuddoo to be suspended and
pointer. This allows the plugin to release resources such as locks that the _c_l_o_s_u_r_e pointer from the struct sudo_conv_callback. The intended use
should not be held indefinitely on suspend and reacquire them on resume. is to allow the plugin to release resources, such as locks, that should
Note that the functions are not actually invoked from within a signal not be held indefinitely while suspended and then reacquire them when the
handler. 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 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 struct sudo_conv_reply, if it is not NULL. SUDO_CONV_REPL_MAX represents
@@ -1440,16 +1431,7 @@ DDEESSCCRRIIPPTTIIOONN
#define GROUP_API_VERSION_MINOR 0 #define GROUP_API_VERSION_MINOR 0
#define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \ #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \
GROUP_API_VERSION_MINOR) GROUP_API_VERSION_MINOR)
For getters and setters see the _P_o_l_i_c_y _p_l_u_g_i_n _A_P_I.
/* 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)
PPLLUUGGIINN AAPPII CCHHAANNGGEELLOOGG PPLLUUGGIINN AAPPII CCHHAANNGGEELLOOGG
The following revisions have been made to the Sudo Plugin API. The following revisions have been made to the Sudo Plugin API.

View File

@@ -1391,7 +1391,7 @@ will not be called.
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
} while(0) } 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 *(vp) = (*(vp) & 0xffff0000) | (n); \e
} while(0) } while(0)
.RE .RE
@@ -2201,21 +2201,13 @@ return SUDO_HOOK_RET_STOP;
/* Hook API version major/minor */ /* Hook API version major/minor */
#define SUDO_HOOK_VERSION_MAJOR 1 #define SUDO_HOOK_VERSION_MAJOR 1
#define SUDO_HOOK_VERSION_MINOR 0 #define SUDO_HOOK_VERSION_MINOR 0
#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y) #define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
SUDO_HOOK_VERSION_MINOR) 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 .RE
.fi .fi
.PP
For getters and setters see the
\fIPolicy plugin API\fR.
.SS "Remote command execution" .SS "Remote command execution"
The The
\fBsudo\fR \fBsudo\fR
@@ -2272,6 +2264,11 @@ A
function is also available that can be used to display informational function is also available that can be used to display informational
or error messages to the user, which is usually more convenient for or error messages to the user, which is usually more convenient for
simple messages where no use input is required. 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 .nf
.sp .sp
.RS 0n .RS 0n
@@ -2293,14 +2290,6 @@ struct sudo_conv_reply {
char *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); typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
struct sudo_conv_callback { struct sudo_conv_callback {
unsigned int version; unsigned int version;
@@ -2308,13 +2297,6 @@ struct sudo_conv_callback {
sudo_conv_callback_fn_t on_suspend; sudo_conv_callback_fn_t on_suspend;
sudo_conv_callback_fn_t on_resume; 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 .RE
.fi .fi
.PP .PP
@@ -2326,6 +2308,20 @@ functions are passed
in to the plugin's in to the plugin's
\fBopen\fR() \fBopen\fR()
function when the plugin is initialized. 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 .PP
To use the To use the
\fBconversation\fR() \fBconversation\fR()
@@ -2344,17 +2340,22 @@ The
\fRstruct sudo_conv_callback\fR \fRstruct sudo_conv_callback\fR
pointer, if not pointer, if not
\fRNULL\fR, \fRNULL\fR,
contains function pointers that are called when the should contain function pointers to be called when the
\fBsudo\fR \fBsudo\fR
process is suspended and/or resumed during conversation input. 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 \fBsudo\fR
to be suspended and the to be suspended and the
\fIclosure\fR \fIclosure\fR
pointer. pointer from the
This allows the plugin to release resources such as locks that \fRstruct sudo_conv_callback\fR.
should not be held indefinitely on suspend and reacquire them The intended use is to allow the plugin to release resources, such as locks,
on resume. 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. Note that the functions are not actually invoked from within a signal handler.
.PP .PP
The plugin is responsible for freeing the reply buffer located in each 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_MINOR 0
#define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e
GROUP_API_VERSION_MINOR) 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 .RE
.fi .fi
For getters and setters see the
\fIPolicy plugin API\fR.
.SH "PLUGIN API CHANGELOG" .SH "PLUGIN API CHANGELOG"
The following revisions have been made to the Sudo Plugin API. The following revisions have been made to the Sudo Plugin API.
.TP 6n .TP 6n

View File

@@ -1228,7 +1228,7 @@ will not be called.
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
} while(0) } 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 *(vp) = (*(vp) & 0xffff0000) | (n); \e
} while(0) } while(0)
.Ed .Ed
@@ -1910,20 +1910,12 @@ return SUDO_HOOK_RET_STOP;
/* Hook API version major/minor */ /* Hook API version major/minor */
#define SUDO_HOOK_VERSION_MAJOR 1 #define SUDO_HOOK_VERSION_MAJOR 1
#define SUDO_HOOK_VERSION_MINOR 0 #define SUDO_HOOK_VERSION_MINOR 0
#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y) #define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
SUDO_HOOK_VERSION_MINOR) 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 .Ed
.Pp
For getters and setters see the
.Sx Policy plugin API .
.Ss Remote command execution .Ss Remote command execution
The The
.Nm sudo .Nm sudo
@@ -1980,6 +1972,11 @@ A
function is also available that can be used to display informational function is also available that can be used to display informational
or error messages to the user, which is usually more convenient for or error messages to the user, which is usually more convenient for
simple messages where no use input is required. 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 .Bd -literal
struct sudo_conv_message { struct sudo_conv_message {
#define SUDO_CONV_PROMPT_ECHO_OFF 0x0001 /* do not echo user input */ #define SUDO_CONV_PROMPT_ECHO_OFF 0x0001 /* do not echo user input */
@@ -1999,14 +1996,6 @@ struct sudo_conv_reply {
char *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); typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
struct sudo_conv_callback { struct sudo_conv_callback {
unsigned int version; unsigned int version;
@@ -2014,13 +2003,6 @@ struct sudo_conv_callback {
sudo_conv_callback_fn_t on_suspend; sudo_conv_callback_fn_t on_suspend;
sudo_conv_callback_fn_t on_resume; 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 .Ed
.Pp .Pp
Pointers to the Pointers to the
@@ -2031,6 +2013,17 @@ functions are passed
in to the plugin's in to the plugin's
.Fn open .Fn open
function when the plugin is initialized. 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 .Pp
To use the To use the
.Fn conversation .Fn conversation
@@ -2049,17 +2042,22 @@ The
.Li struct sudo_conv_callback .Li struct sudo_conv_callback
pointer, if not pointer, if not
.Dv NULL , .Dv NULL ,
contains function pointers that are called when the should contain function pointers to be called when the
.Nm sudo .Nm sudo
process is suspended and/or resumed during conversation input. 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 .Nm sudo
to be suspended and the to be suspended and the
.Fa closure .Fa closure
pointer. pointer from the
This allows the plugin to release resources such as locks that .Li struct sudo_conv_callback .
should not be held indefinitely on suspend and reacquire them The intended use is to allow the plugin to release resources, such as locks,
on resume. 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. Note that the functions are not actually invoked from within a signal handler.
.Pp .Pp
The plugin is responsible for freeing the reply buffer located in each 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_MINOR 0
#define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e
GROUP_API_VERSION_MINOR) 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 .Ed
For getters and setters see the
.Sx Policy plugin API .
.Sh PLUGIN API CHANGELOG .Sh PLUGIN API CHANGELOG
The following revisions have been made to the Sudo Plugin API. The following revisions have been made to the Sudo Plugin API.
.Bl -tag -width 4n .Bl -tag -width 4n

View File

@@ -23,7 +23,7 @@
#define SUDO_API_MKVERSION(x, y) ((x << 16) | y) #define SUDO_API_MKVERSION(x, y) ((x << 16) | y)
#define SUDO_API_VERSION SUDO_API_MKVERSION(SUDO_API_VERSION_MAJOR, SUDO_API_VERSION_MINOR) #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_MAJOR(v) ((v) >> 16)
#define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff) #define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \ #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
@@ -64,8 +64,7 @@ struct sudo_conv_reply {
/* Conversation callback API version major/minor */ /* Conversation callback API version major/minor */
#define SUDO_CONV_CALLBACK_VERSION_MAJOR 1 #define SUDO_CONV_CALLBACK_VERSION_MAJOR 1
#define SUDO_CONV_CALLBACK_VERSION_MINOR 0 #define SUDO_CONV_CALLBACK_VERSION_MINOR 0
#define SUDO_CONV_CALLBACK_MKVERSION(x, y) ((x << 16) | y) #define SUDO_CONV_CALLBACK_VERSION SUDO_API_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, SUDO_CONV_CALLBACK_VERSION_MINOR)
#define SUDO_CONV_CALLBACK_VERSION SUDO_CONV_CALLBACK_MKVERSION(SUDO_CONV_CALLBACK_VERSION_MAJOR, SUDO_CONV_CALLBACK_VERSION_MINOR)
/* /*
* Callback struct to be passed to the conversation function. * Callback struct to be passed to the conversation function.
@@ -106,18 +105,7 @@ struct sudo_hook {
/* Hook API version major/minor */ /* Hook API version major/minor */
#define SUDO_HOOK_VERSION_MAJOR 1 #define SUDO_HOOK_VERSION_MAJOR 1
#define SUDO_HOOK_VERSION_MINOR 0 #define SUDO_HOOK_VERSION_MINOR 0
#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y) #define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR, SUDO_HOOK_VERSION_MINOR)
#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)
/* /*
* Hook function return values. * Hook function return values.
@@ -185,17 +173,13 @@ struct io_plugin {
/* Sudoers group plugin version major/minor */ /* Sudoers group plugin version major/minor */
#define GROUP_API_VERSION_MAJOR 1 #define GROUP_API_VERSION_MAJOR 1
#define GROUP_API_VERSION_MINOR 0 #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 */ /* Getters and setters for group version (for source compat only) */
#define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16) #define GROUP_API_VERSION_GET_MAJOR(v) SUDO_API_VERSION_GET_MAJOR(v)
#define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff) #define GROUP_API_VERSION_GET_MINOR(v) SUDO_API_VERSION_GET_MINOR(v)
#define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \ #define GROUP_API_VERSION_SET_MAJOR(vp, n) SUDO_API_VERSION_SET_MAJOR(vp, n)
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \ #define GROUP_API_VERSION_SET_MINOR(vp, n) SUDO_API_VERSION_SET_MINOR(vp, n)
} while(0)
#define GROUP_API_VERSION_SET_MINOR(vp, n) do { \
*(vp) = (*(vp) & 0xffff0000) | (n); \
} while(0)
/* /*
* version: for compatibility checking * version: for compatibility checking

View File

@@ -62,10 +62,10 @@ sample_init(int version, sudo_printf_t sudo_printf, char *const argv[])
sudo_log = sudo_printf; 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, sudo_log(SUDO_CONV_ERROR_MSG,
"group_file: incompatible major version %d, expected %d\n", "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); GROUP_API_VERSION_MAJOR);
return -1; return -1;
} }

View File

@@ -100,10 +100,10 @@ group_plugin_load(char *plugin_info)
return -1; 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, fprintf(stderr,
"%s: incompatible group plugin major version %d, expected %d\n", "%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); GROUP_API_VERSION_MAJOR);
return -1; return -1;
} }

View File

@@ -104,9 +104,9 @@ group_plugin_load(char *plugin_info)
goto done; 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"), 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); GROUP_API_VERSION_MAJOR);
goto done; goto done;
} }

View File

@@ -812,8 +812,8 @@ sudoers_policy_register_hooks(int version, int (*register_hook)(struct sudo_hook
if (register_hook(hook) != 0) { if (register_hook(hook) != 0) {
sudo_warn_nodebug( sudo_warn_nodebug(
U_("unable to register hook of type %d (version %d.%d)"), U_("unable to register hook of type %d (version %d.%d)"),
hook->hook_type,SUDO_HOOK_VERSION_GET_MAJOR(hook->hook_version), hook->hook_type, SUDO_API_VERSION_GET_MAJOR(hook->hook_version),
SUDO_HOOK_VERSION_GET_MINOR(hook->hook_version)); SUDO_API_VERSION_GET_MINOR(hook->hook_version));
} }
} }
} }

View File

@@ -69,10 +69,10 @@ sysgroup_init(int version, sudo_printf_t sudo_printf, char *const argv[])
sudo_log = sudo_printf; 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, sudo_log(SUDO_CONV_ERROR_MSG,
"sysgroup_group: incompatible major version %d, expected %d\n", "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); GROUP_API_VERSION_MAJOR);
return -1; return -1;
} }

View File

@@ -150,7 +150,7 @@ register_hook(struct sudo_hook *hook)
int rval; int rval;
debug_decl(register_hook, SUDO_DEBUG_HOOKS) 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. */ /* Major versions must match. */
errno = EINVAL; errno = EINVAL;
rval = -1; rval = -1;
@@ -214,7 +214,7 @@ deregister_hook(struct sudo_hook *hook)
int rval = 0; int rval = 0;
debug_decl(deregister_hook, SUDO_DEBUG_HOOKS) 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. */ /* Major versions must match. */
rval = -1; rval = -1;
} else { } else {