#endif /* HAVE_STRINGS_H */
#include <unistd.h>
#include <stdarg.h>
+#include <time.h>
#include <ctype.h>
#include "sudoers.h"
struct cmndspec *next = *nextp;
struct json_value value;
struct member *m;
+ struct tm *tp;
bool last_one;
+ char timebuf[sizeof("20120727121554Z")];
debug_decl(print_cmndspec_json, SUDOERS_DEBUG_UTIL)
/* Open Cmnd_Spec object. */
}
/* Print tags */
- if (cs->timeout > 0 || TAGS_SET(cs->tags)) {
+ if (cs->timeout > 0 || cs->notbefore != UNSPEC || cs->notafter != UNSPEC ||
+ TAGS_SET(cs->tags)) {
struct cmndtag tag = cs->tags;
fprintf(fp, "%*s\"Options\": [\n", indent, "");
print_pair_json(fp, "{ ", "command_timeout", &value,
TAGS_SET(tag) ? " },\n" : " }\n", indent);
}
+ if (cs->notbefore != UNSPEC) {
+ if ((tp = gmtime(&cs->notbefore)) == NULL) {
+ sudo_warn(U_("unable to get GMT time"));
+ } else {
+ if (strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", tp) == 0) {
+ sudo_warnx(U_("unable to format timestamp"));
+ } else {
+ value.type = JSON_STRING;
+ value.u.string = timebuf;
+ print_pair_json(fp, "{ ", "notbefore", &value,
+ (TAGS_SET(tag) || cs->notafter != UNSPEC) ?
+ " },\n" : " }\n", indent);
+ }
+ }
+ }
+ if (cs->notafter != UNSPEC) {
+ if ((tp = gmtime(&cs->notafter)) == NULL) {
+ sudo_warn(U_("unable to get GMT time"));
+ } else {
+ if (strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", tp) == 0) {
+ sudo_warnx(U_("unable to format timestamp"));
+ } else {
+ value.type = JSON_STRING;
+ value.u.string = timebuf;
+ print_pair_json(fp, "{ ", "notafter", &value,
+ TAGS_SET(tag) ? " },\n" : " }\n", indent);
+ }
+ }
+ }
if (tag.nopasswd != UNSPEC) {
value.type = JSON_BOOL;
value.u.boolean = !tag.nopasswd;
{
struct cmndspec *next = *nextp;
struct member *m;
+ struct tm *tp;
bool last_one;
+ char timebuf[sizeof("20120727121554Z")];
debug_decl(print_cmndspec_ldif, SUDOERS_DEBUG_UTIL)
/* Print runasuserlist as sudoRunAsUser attributes */
}
}
+ /* Print sudoNotBefore and sudoNotAfter attributes */
+ if (cs->notbefore != UNSPEC) {
+ if ((tp = gmtime(&cs->notbefore)) == NULL) {
+ sudo_warn(U_("unable to get GMT time"));
+ } else {
+ if (strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", tp) == 0) {
+ sudo_warnx(U_("unable to format timestamp"));
+ } else {
+ fprintf(fp, "sudoNotBefore: %s\n", timebuf);
+ }
+ }
+ }
+ if (cs->notafter != UNSPEC) {
+ if ((tp = gmtime(&cs->notafter)) == NULL) {
+ sudo_warn(U_("unable to get GMT time"));
+ } else {
+ if (strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", tp) == 0) {
+ sudo_warnx(U_("unable to format timestamp"));
+ } else {
+ fprintf(fp, "sudoNotAfter: %s\n", timebuf);
+ }
+ }
+ }
+
/* Print tags as sudoOption attributes */
if (cs->timeout > 0 || TAGS_SET(cs->tags)) {
struct cmndtag tag = cs->tags;
sudo_fatalx(U_("The SUDOERS_BASE environment variable is not set"));
}
- if (strcmp(output_file, "-") != 0) {
+ if (strcmp(output_file, "-") != 0) {
if ((output_fp = fopen(output_file, "w")) == NULL)
sudo_fatal(U_("unable to open %s"), output_file);
}
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" },
+ { "notafter": "20170301083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" },
{ "command": "/bin/ls" }
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" },
{ "command": "/bin/ls" }
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083018Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214080000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214082400Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]
],
"Cmnd_Specs": [
{
+ "Options": [
+ { "notbefore": "20170214083000Z" }
+ ],
"Commands": [
{ "command": "/usr/bin/id" }
]