oxidize: Initial corrode translation

Includes changes to the original C code needed for `corrode` to accept
the input.

There were a lot of problems with APDU fields. These need to be copied
into the translated Rust code and fixed up manually.

Code otherwise contains the raw `corrode` output.
This commit is contained in:
Tony Arcieri
2019-08-10 10:48:02 -07:00
parent a226b56696
commit 45ba342f57
11 changed files with 7670 additions and 179 deletions
+7 -113
View File
@@ -122,7 +122,7 @@ setting_bool_t _get_bool_env(const char *sz_setting);
/* log */
const char szLOG_SOURCE[] = "YubiKey PIV Library";
const char *szLOG_SOURCE = "YubiKey PIV Library";
/*
** Methods
@@ -533,16 +533,16 @@ setting_bool_t _get_bool_config(const char *sz_setting) {
char sz_line[256];
char *psz_name = 0;
char *psz_value = 0;
char sz_name[256] = { 0 };
char sz_value[256] = { 0 };
char sz_name[256]; /* XXX REMEMBER TO ZERO */
char sz_value[256]; /* XXX REMEMBER TO ZERO */
FILE *pf = 0;
if ((pf = fopen(_CONFIG_FILE, "r"))) {
while (!feof(pf)) {
if (fgets(sz_line, sizeof(sz_line), pf)) {
if (*sz_line == '#') continue;
if (*sz_line == '\r') continue;
if (*sz_line == '\n') continue;
if (sz_line[0] == '#') continue;
if (sz_line[0] == '\r') continue;
if (sz_line[0] == '\n') continue;
if (sscanf(sz_line, "%255[^=]=%255s", sz_name, sz_value) == 2) {
/* strip leading/trailing whitespace */
@@ -569,7 +569,7 @@ setting_bool_t _get_bool_config(const char *sz_setting) {
setting_bool_t _get_bool_env(const char *sz_setting) {
setting_bool_t setting = { false, SETTING_SOURCE_DEFAULT };
char *psz_value = NULL;
char sz_name[256] = { 0 };
char sz_name[256]; /* XXX REMEMBER TO ZERO */
snprintf(sz_name, sizeof(sz_name) - 1, "%s%s", _ENV_PREFIX, sz_setting);
@@ -610,109 +610,3 @@ setting_bool_t setting_get_bool(const char *sz_setting, bool def) {
return setting;
}
/* logging */
void yc_log_event(uint32_t id, yc_log_level_t level, const char * sz_format, ...) {
char rgsz_message[4096];
va_list vl;
#ifdef _WIN32
HANDLE hLog = NULL;
LPCSTR sz_message = rgsz_message;
WORD w_type = EVENTLOG_SUCCESS;
#else
int priority = LOG_INFO;
#endif
va_start(vl, sz_format);
#ifdef _WIN32
switch (level) {
case YC_LOG_LEVEL_ERROR:
w_type = EVENTLOG_ERROR_TYPE;
break;
case YC_LOG_LEVEL_WARN:
w_type = EVENTLOG_WARNING_TYPE;
break;
case YC_LOG_LEVEL_INFO:
w_type = EVENTLOG_INFORMATION_TYPE;
break;
case YC_LOG_LEVEL_VERBOSE:
w_type = EVENTLOG_INFORMATION_TYPE;
break;
default:
case YC_LOG_LEVEL_DEBUG:
w_type = EVENTLOG_SUCCESS;
break;
}
if (!(hLog = RegisterEventSourceA(NULL, szLOG_SOURCE))) {
goto Cleanup;
}
/* format message */
if (FAILED(StringCbVPrintfA(
rgsz_message,
sizeof(rgsz_message),
sz_format,
vl))) {
goto Cleanup;
};
// write to the local event log
ReportEventA(
hLog,
w_type,
0,
(DWORD)id,
NULL,
1,
0,
(LPCSTR *)&sz_message,
NULL);
#else
switch (level) {
case YC_LOG_LEVEL_ERROR:
priority = LOG_ERR;
break;
case YC_LOG_LEVEL_WARN:
priority = LOG_WARNING;
break;
case YC_LOG_LEVEL_INFO:
priority = LOG_NOTICE;
break;
case YC_LOG_LEVEL_VERBOSE:
priority = LOG_INFO;
break;
default:
case YC_LOG_LEVEL_DEBUG:
priority = LOG_DEBUG;
break;
}
if (vsnprintf(rgsz_message, sizeof(rgsz_message), sz_format, vl) < 0) {
goto Cleanup;
}
openlog(szLOG_SOURCE, LOG_PID | LOG_NDELAY, LOG_USER);
syslog(priority, "%s", rgsz_message);
closelog();
#endif
Cleanup:
va_end(vl);
#ifdef _WIN32
if (hLog) {
DeregisterEventSource(hLog);
}
#endif
}