2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

Post-process protoc-c files to avoid depending on anonymous unions.

Based on a patch from Michael Osipov.
GitHub issue #60
This commit is contained in:
Todd C. Miller 2020-09-04 13:17:51 -06:00
parent 24b35393e3
commit eaa95acb31
10 changed files with 174 additions and 121 deletions

View File

@ -981,6 +981,7 @@ scripts/mkdep.pl
scripts/mkinstalldirs
scripts/mkpkg
scripts/pp
scripts/unanon
src/Makefile.in
src/conversation.c
src/copy_file.c

View File

@ -78,7 +78,7 @@ struct _ClientMessage
ChangeWindowSize *winsize_event;
CommandSuspend *suspend_event;
ClientHello *hello_msg;
};
} u;
};
#define CLIENT_MESSAGE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&client_message__descriptor) \
@ -170,7 +170,7 @@ struct _InfoMessage
char *strval;
InfoMessage__StringList *strlistval;
InfoMessage__NumberList *numlistval;
};
} u;
};
#define INFO_MESSAGE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&info_message__descriptor) \
@ -398,7 +398,7 @@ struct _ServerMessage
* abort message, kill command
*/
char *abort;
};
} u;
};
#define SERVER_MESSAGE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&server_message__descriptor) \

View File

@ -111,6 +111,8 @@ $(devdir)/log_server.pb-c.c: $(srcdir)/log_server.proto
@if [ -n "$(DEVEL)" ]; then \
cmd='protoc-c --c_out=$(devdir) --proto_path=$(srcdir) $(srcdir)/log_server.proto'; \
echo "$$cmd"; eval $$cmd; \
cmd='$(scriptdir)/unanon $(devdir)/log_server.pb-c.h $(devdir)/log_server.pb-c.c'; \
echo "$$cmd"; eval $$cmd; \
if [ "$(devdir)" == "$(srcdir)" ]; then \
cmd='mv -f $(devdir)/log_server.pb-c.h $(incdir)/log_server.pb-c.h'; \
else \

View File

@ -657,7 +657,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, accept_msg),
offsetof(ClientMessage, u.accept_msg),
&accept_message__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -669,7 +669,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, reject_msg),
offsetof(ClientMessage, u.reject_msg),
&reject_message__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -681,7 +681,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, exit_msg),
offsetof(ClientMessage, u.exit_msg),
&exit_message__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -693,7 +693,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, restart_msg),
offsetof(ClientMessage, u.restart_msg),
&restart_message__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -705,7 +705,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, alert_msg),
offsetof(ClientMessage, u.alert_msg),
&alert_message__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -717,7 +717,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, ttyin_buf),
offsetof(ClientMessage, u.ttyin_buf),
&io_buffer__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -729,7 +729,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, ttyout_buf),
offsetof(ClientMessage, u.ttyout_buf),
&io_buffer__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -741,7 +741,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, stdin_buf),
offsetof(ClientMessage, u.stdin_buf),
&io_buffer__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -753,7 +753,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, stdout_buf),
offsetof(ClientMessage, u.stdout_buf),
&io_buffer__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -765,7 +765,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, stderr_buf),
offsetof(ClientMessage, u.stderr_buf),
&io_buffer__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -777,7 +777,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, winsize_event),
offsetof(ClientMessage, u.winsize_event),
&change_window_size__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -789,7 +789,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, suspend_event),
offsetof(ClientMessage, u.suspend_event),
&command_suspend__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -801,7 +801,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[13] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, type_case),
offsetof(ClientMessage, hello_msg),
offsetof(ClientMessage, u.hello_msg),
&client_hello__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1041,7 +1041,7 @@ static const ProtobufCFieldDescriptor info_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT64,
offsetof(InfoMessage, value_case),
offsetof(InfoMessage, numval),
offsetof(InfoMessage, u.numval),
NULL,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1053,7 +1053,7 @@ static const ProtobufCFieldDescriptor info_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
offsetof(InfoMessage, value_case),
offsetof(InfoMessage, strval),
offsetof(InfoMessage, u.strval),
NULL,
&protobuf_c_empty_string,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1065,7 +1065,7 @@ static const ProtobufCFieldDescriptor info_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(InfoMessage, value_case),
offsetof(InfoMessage, strlistval),
offsetof(InfoMessage, u.strlistval),
&info_message__string_list__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1077,7 +1077,7 @@ static const ProtobufCFieldDescriptor info_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(InfoMessage, value_case),
offsetof(InfoMessage, numlistval),
offsetof(InfoMessage, u.numlistval),
&info_message__number_list__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1592,7 +1592,7 @@ static const ProtobufCFieldDescriptor server_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ServerMessage, type_case),
offsetof(ServerMessage, hello),
offsetof(ServerMessage, u.hello),
&server_hello__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1604,7 +1604,7 @@ static const ProtobufCFieldDescriptor server_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ServerMessage, type_case),
offsetof(ServerMessage, commit_point),
offsetof(ServerMessage, u.commit_point),
&time_spec__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1616,7 +1616,7 @@ static const ProtobufCFieldDescriptor server_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
offsetof(ServerMessage, type_case),
offsetof(ServerMessage, log_id),
offsetof(ServerMessage, u.log_id),
NULL,
&protobuf_c_empty_string,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1628,7 +1628,7 @@ static const ProtobufCFieldDescriptor server_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
offsetof(ServerMessage, type_case),
offsetof(ServerMessage, error),
offsetof(ServerMessage, u.error),
NULL,
&protobuf_c_empty_string,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
@ -1640,7 +1640,7 @@ static const ProtobufCFieldDescriptor server_message__field_descriptors[5] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
offsetof(ServerMessage, type_case),
offsetof(ServerMessage, abort),
offsetof(ServerMessage, u.abort),
NULL,
&protobuf_c_empty_string,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */

View File

@ -371,18 +371,18 @@ format_json(ClientMessage__TypeCase event_type, const char *reason,
switch (info->value_case) {
case INFO_MESSAGE__VALUE_NUMVAL:
json_value.type = JSON_NUMBER;
json_value.u.number = info->numval;
json_value.u.number = info->u.numval;
if (!sudo_json_add_value(&json, info->key, &json_value))
goto bad;
break;
case INFO_MESSAGE__VALUE_STRVAL:
json_value.type = JSON_STRING;
json_value.u.string = info->strval;
json_value.u.string = info->u.strval;
if (!sudo_json_add_value(&json, info->key, &json_value))
goto bad;
break;
case INFO_MESSAGE__VALUE_STRLISTVAL: {
InfoMessage__StringList *strlist = info->strlistval;
InfoMessage__StringList *strlist = info->u.strlistval;
size_t n;
if (!sudo_json_open_array(&json, info->key))

View File

@ -172,17 +172,17 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
if (!has_numval(info)) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"columns specified but not a number");
} else if (info->numval <= 0 || info->numval > INT_MAX) {
} else if (info->u.numval <= 0 || info->u.numval > INT_MAX) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"columns (%" PRId64 ") out of range", info->numval);
"columns (%" PRId64 ") out of range", info->u.numval);
} else {
details->columns = info->numval;
details->columns = info->u.numval;
}
continue;
}
if (strcmp(key, "command") == 0) {
if (has_strval(info)) {
if ((details->command = strdup(info->strval)) == NULL) {
if ((details->command = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -200,11 +200,11 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
if (!has_numval(info)) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"lines specified but not a number");
} else if (info->numval <= 0 || info->numval > INT_MAX) {
} else if (info->u.numval <= 0 || info->u.numval > INT_MAX) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"lines (%" PRId64 ") out of range", info->numval);
"lines (%" PRId64 ") out of range", info->u.numval);
} else {
details->lines = info->numval;
details->lines = info->u.numval;
}
continue;
}
@ -212,10 +212,10 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
case 'r':
if (strcmp(key, "runargv") == 0) {
if (has_strlistval(info)) {
details->argv = strlist_copy(info->strlistval);
details->argv = strlist_copy(info->u.strlistval);
if (details->argv == NULL)
goto done;
details->argc = info->strlistval->n_strings;
details->argc = info->u.strlistval->n_strings;
} else {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"runargv specified but not a string list");
@ -224,7 +224,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
}
if (strcmp(key, "runchroot") == 0) {
if (has_strval(info)) {
if ((details->runchroot = strdup(info->strval)) == NULL) {
if ((details->runchroot = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -238,7 +238,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
}
if (strcmp(key, "runcwd") == 0) {
if (has_strval(info)) {
if ((details->runcwd = strdup(info->strval)) == NULL) {
if ((details->runcwd = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -252,7 +252,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
}
if (strcmp(key, "runenv") == 0) {
if (has_strlistval(info)) {
details->envp = strlist_copy(info->strlistval);
details->envp = strlist_copy(info->u.strlistval);
if (details->envp == NULL)
goto done;
} else {
@ -265,17 +265,17 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
if (!has_numval(info)) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"rungid specified but not a number");
} else if (info->numval < 0 || info->numval > INT_MAX) {
} else if (info->u.numval < 0 || info->u.numval > INT_MAX) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"rungid (%" PRId64 ") out of range", info->numval);
"rungid (%" PRId64 ") out of range", info->u.numval);
} else {
details->rungid = info->numval;
details->rungid = info->u.numval;
}
continue;
}
if (strcmp(key, "rungroup") == 0) {
if (has_strval(info)) {
if ((details->rungroup = strdup(info->strval)) == NULL) {
if ((details->rungroup = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -291,17 +291,17 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
if (!has_numval(info)) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"runuid specified but not a number");
} else if (info->numval < 0 || info->numval > INT_MAX) {
} else if (info->u.numval < 0 || info->u.numval > INT_MAX) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"runuid (%" PRId64 ") out of range", info->numval);
"runuid (%" PRId64 ") out of range", info->u.numval);
} else {
details->runuid = info->numval;
details->runuid = info->u.numval;
}
continue;
}
if (strcmp(key, "runuser") == 0) {
if (has_strval(info)) {
if ((details->runuser = strdup(info->strval)) == NULL) {
if ((details->runuser = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -317,7 +317,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
case 's':
if (strcmp(key, "submitcwd") == 0) {
if (has_strval(info)) {
if ((details->cwd = strdup(info->strval)) == NULL) {
if ((details->cwd = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -331,7 +331,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
}
if (strcmp(key, "submitgroup") == 0) {
if (has_strval(info)) {
if ((details->submitgroup = strdup(info->strval)) == NULL) {
if ((details->submitgroup = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -345,7 +345,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
}
if (strcmp(key, "submithost") == 0) {
if (has_strval(info)) {
if ((details->submithost = strdup(info->strval)) == NULL) {
if ((details->submithost = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -359,7 +359,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
}
if (strcmp(key, "submituser") == 0) {
if (has_strval(info)) {
if ((details->submituser = strdup(info->strval)) == NULL) {
if ((details->submituser = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");
@ -375,7 +375,7 @@ iolog_details_fill(struct iolog_details *details, TimeSpec *submit_time,
case 't':
if (strcmp(key, "ttyname") == 0) {
if (has_strval(info)) {
if ((details->ttyname = strdup(info->strval)) == NULL) {
if ((details->ttyname = strdup(info->u.strval)) == NULL) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"strdup");

View File

@ -186,7 +186,7 @@ fmt_hello_message(struct connection_buffer *buf, bool tls)
/* TODO: implement redirect and servers array. */
hello.server_id = (char *)server_id;
msg.hello = &hello;
msg.u.hello = &hello;
msg.type_case = SERVER_MESSAGE__TYPE_HELLO;
debug_return_bool(fmt_server_message(buf, &msg));
@ -198,7 +198,7 @@ fmt_log_id_message(const char *id, struct connection_buffer *buf)
ServerMessage msg = SERVER_MESSAGE__INIT;
debug_decl(fmt_log_id_message, SUDO_DEBUG_UTIL);
msg.log_id = (char *)id;
msg.u.log_id = (char *)id;
msg.type_case = SERVER_MESSAGE__TYPE_LOG_ID;
debug_return_bool(fmt_server_message(buf, &msg));
@ -210,7 +210,7 @@ fmt_error_message(const char *errstr, struct connection_buffer *buf)
ServerMessage msg = SERVER_MESSAGE__INIT;
debug_decl(fmt_error_message, SUDO_DEBUG_UTIL);
msg.error = (char *)errstr;
msg.u.error = (char *)errstr;
msg.type_case = SERVER_MESSAGE__TYPE_ERROR;
debug_return_bool(fmt_server_message(buf, &msg));
@ -586,43 +586,43 @@ handle_client_message(uint8_t *buf, size_t len,
switch (msg->type_case) {
case CLIENT_MESSAGE__TYPE_ACCEPT_MSG:
ret = handle_accept(msg->accept_msg, closure);
ret = handle_accept(msg->u.accept_msg, closure);
break;
case CLIENT_MESSAGE__TYPE_REJECT_MSG:
ret = handle_reject(msg->reject_msg, closure);
ret = handle_reject(msg->u.reject_msg, closure);
break;
case CLIENT_MESSAGE__TYPE_EXIT_MSG:
ret = handle_exit(msg->exit_msg, closure);
ret = handle_exit(msg->u.exit_msg, closure);
break;
case CLIENT_MESSAGE__TYPE_RESTART_MSG:
ret = handle_restart(msg->restart_msg, closure);
ret = handle_restart(msg->u.restart_msg, closure);
break;
case CLIENT_MESSAGE__TYPE_ALERT_MSG:
ret = handle_alert(msg->alert_msg, closure);
ret = handle_alert(msg->u.alert_msg, closure);
break;
case CLIENT_MESSAGE__TYPE_TTYIN_BUF:
ret = handle_iobuf(IOFD_TTYIN, msg->ttyin_buf, closure);
ret = handle_iobuf(IOFD_TTYIN, msg->u.ttyin_buf, closure);
break;
case CLIENT_MESSAGE__TYPE_TTYOUT_BUF:
ret = handle_iobuf(IOFD_TTYOUT, msg->ttyout_buf, closure);
ret = handle_iobuf(IOFD_TTYOUT, msg->u.ttyout_buf, closure);
break;
case CLIENT_MESSAGE__TYPE_STDIN_BUF:
ret = handle_iobuf(IOFD_STDIN, msg->stdin_buf, closure);
ret = handle_iobuf(IOFD_STDIN, msg->u.stdin_buf, closure);
break;
case CLIENT_MESSAGE__TYPE_STDOUT_BUF:
ret = handle_iobuf(IOFD_STDOUT, msg->stdout_buf, closure);
ret = handle_iobuf(IOFD_STDOUT, msg->u.stdout_buf, closure);
break;
case CLIENT_MESSAGE__TYPE_STDERR_BUF:
ret = handle_iobuf(IOFD_STDERR, msg->stderr_buf, closure);
ret = handle_iobuf(IOFD_STDERR, msg->u.stderr_buf, closure);
break;
case CLIENT_MESSAGE__TYPE_WINSIZE_EVENT:
ret = handle_winsize(msg->winsize_event, closure);
ret = handle_winsize(msg->u.winsize_event, closure);
break;
case CLIENT_MESSAGE__TYPE_SUSPEND_EVENT:
ret = handle_suspend(msg->suspend_event, closure);
ret = handle_suspend(msg->u.suspend_event, closure);
break;
case CLIENT_MESSAGE__TYPE_HELLO_MSG:
ret = handle_client_hello(msg->hello_msg, closure);
ret = handle_client_hello(msg->u.hello_msg, closure);
break;
default:
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
@ -952,7 +952,7 @@ server_commit_cb(int unused, int what, void *v)
/* Send the client an acknowledgement of what has been committed to disk. */
commit_point.tv_sec = closure->elapsed_time.tv_sec;
commit_point.tv_nsec = closure->elapsed_time.tv_nsec;
msg.commit_point = &commit_point;
msg.u.commit_point = &commit_point;
msg.type_case = SERVER_MESSAGE__TYPE_COMMIT_POINT;
sudo_debug_printf(SUDO_DEBUG_INFO, "%s: sending commit point [%lld, %ld]",

View File

@ -332,7 +332,7 @@ fmt_client_hello(struct client_closure *closure)
hello_msg.client_id = "Sudo Sendlog " PACKAGE_VERSION;
/* Schedule ClientMessage */
client_msg.hello_msg = &hello_msg;
client_msg.u.hello_msg = &hello_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_HELLO_MSG;
ret = fmt_client_message(&closure->write_buf, &client_msg);
if (ret) {
@ -354,8 +354,8 @@ free_info_messages(InfoMessage **info_msgs, size_t n_info_msgs)
while (n_info_msgs-- > 0) {
if (info_msgs[n_info_msgs]->value_case == INFO_MESSAGE__VALUE_STRLISTVAL) {
/* Only strlistval was dynamically allocated */
free(info_msgs[n_info_msgs]->strlistval->strings);
free(info_msgs[n_info_msgs]->strlistval);
free(info_msgs[n_info_msgs]->u.strlistval->strings);
free(info_msgs[n_info_msgs]->u.strlistval);
}
free(info_msgs[n_info_msgs]);
}
@ -398,55 +398,55 @@ fmt_info_messages(struct iolog_info *log_info, char *hostname,
/* Fill in info_msgs */
n = 0;
info_msgs[n]->key = "command";
info_msgs[n]->strval = log_info->cmd;
info_msgs[n]->u.strval = log_info->cmd;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
info_msgs[n]->key = "columns";
info_msgs[n]->numval = log_info->cols;
info_msgs[n]->u.numval = log_info->cols;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_NUMVAL;
n++;
info_msgs[n]->key = "lines";
info_msgs[n]->numval = log_info->lines;
info_msgs[n]->u.numval = log_info->lines;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_NUMVAL;
n++;
info_msgs[n]->key = "runargv";
info_msgs[n]->strlistval = runargv;
info_msgs[n]->u.strlistval = runargv;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRLISTVAL;
runargv = NULL;
n++;
if (log_info->runas_group != NULL) {
info_msgs[n]->key = "rungroup";
info_msgs[n]->strval = log_info->runas_group;
info_msgs[n]->u.strval = log_info->runas_group;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
}
info_msgs[n]->key = "runuser";
info_msgs[n]->strval = log_info->runas_user;
info_msgs[n]->u.strval = log_info->runas_user;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
info_msgs[n]->key = "submitcwd";
info_msgs[n]->strval = log_info->cwd;
info_msgs[n]->u.strval = log_info->cwd;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
info_msgs[n]->key = "submithost";
info_msgs[n]->strval = hostname;
info_msgs[n]->u.strval = hostname;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
info_msgs[n]->key = "submituser";
info_msgs[n]->strval = log_info->user;
info_msgs[n]->u.strval = log_info->user;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
info_msgs[n]->key = "ttyname";
info_msgs[n]->strval = log_info->tty;
info_msgs[n]->u.strval = log_info->tty;
info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
@ -515,7 +515,7 @@ fmt_reject_message(struct client_closure *closure)
"%s: sending RejectMessage, array length %zu", __func__, n_info_msgs);
/* Schedule ClientMessage */
client_msg.reject_msg = &reject_msg;
client_msg.u.reject_msg = &reject_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_REJECT_MSG;
ret = fmt_client_message(&closure->write_buf, &client_msg);
if (ret) {
@ -574,7 +574,7 @@ fmt_accept_message(struct client_closure *closure)
"%s: sending AcceptMessage, array length %zu", __func__, n_info_msgs);
/* Schedule ClientMessage */
client_msg.accept_msg = &accept_msg;
client_msg.u.accept_msg = &accept_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_ACCEPT_MSG;
ret = fmt_client_message(&closure->write_buf, &client_msg);
if (ret) {
@ -613,7 +613,7 @@ fmt_restart_message(struct client_closure *closure)
restart_msg.log_id = (char *)closure->iolog_id;
/* Schedule ClientMessage */
client_msg.restart_msg = &restart_msg;
client_msg.u.restart_msg = &restart_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_RESTART_MSG;
ret = fmt_client_message(&closure->write_buf, &client_msg);
if (ret) {
@ -649,7 +649,7 @@ fmt_exit_message(struct client_closure *closure)
__func__, exit_msg.exit_value);
/* Send ClientMessage */
client_msg.exit_msg = &exit_msg;
client_msg.u.exit_msg = &exit_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_EXIT_MSG;
if (!fmt_client_message(&closure->write_buf, &client_msg))
goto done;
@ -691,7 +691,7 @@ fmt_io_buf(int type, struct client_closure *closure,
iobuf_msg.data.len, type, io_buffer__get_packed_size(&iobuf_msg));
/* Send ClientMessage, it doesn't matter which IoBuffer we set. */
client_msg.ttyout_buf = &iobuf_msg;
client_msg.u.ttyout_buf = &iobuf_msg;
client_msg.type_case = type;
if (!fmt_client_message(buf, &client_msg))
goto done;
@ -728,7 +728,7 @@ fmt_winsize(struct client_closure *closure, struct connection_buffer *buf)
__func__, winsize_msg.rows, winsize_msg.cols);
/* Send ClientMessage */
client_msg.winsize_event = &winsize_msg;
client_msg.u.winsize_event = &winsize_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_WINSIZE_EVENT;
if (!fmt_client_message(buf, &client_msg))
goto done;
@ -766,7 +766,7 @@ fmt_suspend(struct client_closure *closure, struct connection_buffer *buf)
"%s: sending CommandSuspend, SIG%s", __func__, suspend_msg.signal);
/* Send ClientMessage */
client_msg.suspend_event = &suspend_msg;
client_msg.u.suspend_event = &suspend_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_SUSPEND_EVENT;
if (!fmt_client_message(buf, &client_msg))
goto done;
@ -1014,7 +1014,7 @@ handle_server_message(uint8_t *buf, size_t len,
switch (msg->type_case) {
case SERVER_MESSAGE__TYPE_HELLO:
if ((ret = handle_server_hello(msg->hello, closure))) {
if ((ret = handle_server_hello(msg->u.hello, closure))) {
if (sudo_timespecisset(&closure->restart)) {
closure->state = SEND_RESTART;
ret = fmt_restart_message(closure);
@ -1028,7 +1028,7 @@ handle_server_message(uint8_t *buf, size_t len,
}
break;
case SERVER_MESSAGE__TYPE_COMMIT_POINT:
ret = handle_commit_point(msg->commit_point, closure);
ret = handle_commit_point(msg->u.commit_point, closure);
if (sudo_timespeccmp(&closure->elapsed, &closure->committed, ==)) {
sudo_ev_del(closure->evbase, closure->read_ev);
closure->state = FINISHED;
@ -1037,14 +1037,14 @@ handle_server_message(uint8_t *buf, size_t len,
}
break;
case SERVER_MESSAGE__TYPE_LOG_ID:
ret = handle_log_id(msg->log_id, closure);
ret = handle_log_id(msg->u.log_id, closure);
break;
case SERVER_MESSAGE__TYPE_ERROR:
ret = handle_server_error(msg->error, closure);
ret = handle_server_error(msg->u.error, closure);
closure->state = ERROR;
break;
case SERVER_MESSAGE__TYPE_ABORT:
ret = handle_server_abort(msg->abort, closure);
ret = handle_server_abort(msg->u.abort, closure);
closure->state = ERROR;
break;
default:

View File

@ -733,7 +733,7 @@ fmt_client_hello(struct client_closure *closure)
hello_msg.client_id = "sudoers " PACKAGE_VERSION;
/* Schedule ClientMessage */
client_msg.hello_msg = &hello_msg;
client_msg.u.hello_msg = &hello_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_HELLO_MSG;
ret = fmt_client_message(closure, &client_msg);
@ -805,38 +805,38 @@ fmt_accept_message(struct client_closure *closure)
/* TODO: clientsid */
accept_msg.info_msgs[n]->key = "columns";
accept_msg.info_msgs[n]->numval = details->cols;
accept_msg.info_msgs[n]->u.numval = details->cols;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_NUMVAL;
n++;
accept_msg.info_msgs[n]->key = "command";
accept_msg.info_msgs[n]->strval = (char *)details->command;
accept_msg.info_msgs[n]->u.strval = (char *)details->command;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
accept_msg.info_msgs[n]->key = "lines";
accept_msg.info_msgs[n]->numval = details->lines;
accept_msg.info_msgs[n]->u.numval = details->lines;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_NUMVAL;
n++;
accept_msg.info_msgs[n]->key = "runargv";
accept_msg.info_msgs[n]->strlistval = &runargv;
accept_msg.info_msgs[n]->u.strlistval = &runargv;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRLISTVAL;
n++;
accept_msg.info_msgs[n]->key = "runenv";
accept_msg.info_msgs[n]->strlistval = &runenv;
accept_msg.info_msgs[n]->u.strlistval = &runenv;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRLISTVAL;
n++;
if (details->runas_gr!= NULL) {
accept_msg.info_msgs[n]->key = "rungid";
accept_msg.info_msgs[n]->numval = details->runas_gr->gr_gid;
accept_msg.info_msgs[n]->u.numval = details->runas_gr->gr_gid;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_NUMVAL;
n++;
accept_msg.info_msgs[n]->key = "rungroup";
accept_msg.info_msgs[n]->strval = details->runas_gr->gr_name;
accept_msg.info_msgs[n]->u.strval = details->runas_gr->gr_name;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
}
@ -845,32 +845,32 @@ fmt_accept_message(struct client_closure *closure)
/* TODO - rungroups */
accept_msg.info_msgs[n]->key = "runuid";
accept_msg.info_msgs[n]->numval = details->runas_pw->pw_uid;
accept_msg.info_msgs[n]->u.numval = details->runas_pw->pw_uid;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_NUMVAL;
n++;
accept_msg.info_msgs[n]->key = "runuser";
accept_msg.info_msgs[n]->strval = details->runas_pw->pw_name;
accept_msg.info_msgs[n]->u.strval = details->runas_pw->pw_name;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
if (details->cwd != NULL) {
accept_msg.info_msgs[n]->key = "submitcwd";
accept_msg.info_msgs[n]->strval = (char *)details->cwd;
accept_msg.info_msgs[n]->u.strval = (char *)details->cwd;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
}
if (details->runcwd != NULL) {
accept_msg.info_msgs[n]->key = "runcwd";
accept_msg.info_msgs[n]->strval = (char *)details->runcwd;
accept_msg.info_msgs[n]->u.strval = (char *)details->runcwd;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
}
if (details->runchroot != NULL) {
accept_msg.info_msgs[n]->key = "runchroot";
accept_msg.info_msgs[n]->strval = (char *)details->runchroot;
accept_msg.info_msgs[n]->u.strval = (char *)details->runchroot;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
}
@ -882,20 +882,20 @@ fmt_accept_message(struct client_closure *closure)
/* TODO - submitgroups */
accept_msg.info_msgs[n]->key = "submithost";
accept_msg.info_msgs[n]->strval = (char *)details->host;
accept_msg.info_msgs[n]->u.strval = (char *)details->host;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
/* TODO - submituid */
accept_msg.info_msgs[n]->key = "submituser";
accept_msg.info_msgs[n]->strval = (char *)details->user;
accept_msg.info_msgs[n]->u.strval = (char *)details->user;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
if (details->tty != NULL) {
accept_msg.info_msgs[n]->key = "ttyname";
accept_msg.info_msgs[n]->strval = (char *)details->tty;
accept_msg.info_msgs[n]->u.strval = (char *)details->tty;
accept_msg.info_msgs[n]->value_case = INFO_MESSAGE__VALUE_STRVAL;
n++;
}
@ -907,7 +907,7 @@ fmt_accept_message(struct client_closure *closure)
"%s: sending AcceptMessage, array length %zu", __func__, n);
/* Schedule ClientMessage */
client_msg.accept_msg = &accept_msg;
client_msg.u.accept_msg = &accept_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_ACCEPT_MSG;
ret = fmt_client_message(closure, &client_msg);
@ -1009,7 +1009,7 @@ fmt_exit_message(struct client_closure *closure, int exit_status, int error)
exit_msg.dumped_core ? "yes" : "no");
/* Send ClientMessage */
client_msg.exit_msg = &exit_msg;
client_msg.u.exit_msg = &exit_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_EXIT_MSG;
if (!fmt_client_message(closure, &client_msg))
goto done;
@ -1048,7 +1048,7 @@ fmt_io_buf(struct client_closure *closure, int type, const char *buf,
iobuf_msg.data.len, type, io_buffer__get_packed_size(&iobuf_msg));
/* Schedule ClientMessage, it doesn't matter which IoBuffer we set. */
client_msg.ttyout_buf = &iobuf_msg;
client_msg.u.ttyout_buf = &iobuf_msg;
client_msg.type_case = type;
if (!fmt_client_message(closure, &client_msg))
goto done;
@ -1085,7 +1085,7 @@ fmt_winsize(struct client_closure *closure, unsigned int lines,
__func__, winsize_msg.rows, winsize_msg.cols);
/* Send ClientMessage */
client_msg.winsize_event = &winsize_msg;
client_msg.u.winsize_event = &winsize_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_WINSIZE_EVENT;
if (!fmt_client_message(closure, &client_msg))
goto done;
@ -1120,7 +1120,7 @@ fmt_suspend(struct client_closure *closure, const char *signame, struct timespec
"%s: sending CommandSuspend, SIG%s", __func__, suspend_msg.signal);
/* Send ClientMessage */
client_msg.suspend_event = &suspend_msg;
client_msg.u.suspend_event = &suspend_msg;
client_msg.type_case = CLIENT_MESSAGE__TYPE_SUSPEND_EVENT;
if (!fmt_client_message(closure, &client_msg))
goto done;
@ -1365,7 +1365,7 @@ handle_server_message(uint8_t *buf, size_t len,
switch (msg->type_case) {
case SERVER_MESSAGE__TYPE_HELLO:
if (handle_server_hello(msg->hello, closure)) {
if (handle_server_hello(msg->u.hello, closure)) {
/* Format and schedule accept message. */
closure->state = SEND_ACCEPT;
if ((ret = fmt_accept_message(closure))) {
@ -1378,17 +1378,17 @@ handle_server_message(uint8_t *buf, size_t len,
}
break;
case SERVER_MESSAGE__TYPE_COMMIT_POINT:
ret = handle_commit_point(msg->commit_point, closure);
ret = handle_commit_point(msg->u.commit_point, closure);
break;
case SERVER_MESSAGE__TYPE_LOG_ID:
ret = handle_log_id(msg->log_id, closure);
ret = handle_log_id(msg->u.log_id, closure);
break;
case SERVER_MESSAGE__TYPE_ERROR:
ret = handle_server_error(msg->error, closure);
ret = handle_server_error(msg->u.error, closure);
closure->state = ERROR;
break;
case SERVER_MESSAGE__TYPE_ABORT:
ret = handle_server_abort(msg->abort, closure);
ret = handle_server_abort(msg->u.abort, closure);
closure->state = ERROR;
break;
default:

50
scripts/unanon Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env perl
#
# Post-process files generated by protoc-c to remove anonymous unions.
# Works on the generated files but probably little else.
use warnings;
use strict;
sub unanon {
my $hfile = shift;
my $cfile = shift;
my ($fh, $content);
my %members;
open $fh, "<", $hfile or die $!;
local $/; # enable localized slurp mode
$content = <$fh>;
close $fh;
# Detect and replace anonymous unions in .h file.
# Assumes there is only one anonymous union in scope.
while ($content =~ s/^(struct\s+_(\w+)[^}]+)(union\s+{([^}]+)}\s*);/$1$3 u;/sm) {
my $s = $2;
my $u = $4;
$u =~ s:/\*((?!\*/).)*\*/::sg;
foreach (split(/\n+/, $u)) {
if (/^.*\s+\**([^;]+);/) {
$members{$1} = $s;
}
}
}
open $fh, ">", $hfile or die $!;
print $fh $content;
close $fh;
# Replace anonymous union access in generated .c file.
open $fh, "<", $cfile or die $!;
$content = <$fh>;
close $fh;
while (my ($key, $val) = each %members) {
# We only support access via offsetof()
$content =~ s/offsetof\($val, $key\)/offsetof($val, u.$key)/g;
}
open $fh, ">", $cfile or die $!;
print $fh $content;
close $fh;
}
unanon(@ARGV);