sudo_printf_t sudo_printf = visudo_printf;
static struct sudoersfile_list sudoerslist;
static struct rbtree *alias_freelist;
+static bool checkonly;
int
main(int argc, char *argv[])
struct sudoersfile *sp;
char *args, *editor, *sudoers_path;
int ch;
- bool checkonly, quiet, strict, oldperms;
+ bool quiet, strict, oldperms;
#if defined(SUDO_DEVEL) && defined(__OpenBSD__)
extern char *malloc_options;
malloc_options = "AFGJPR";
{
struct sudoersfile *entry;
FILE *fp;
+ int open_flags;
+
+ if (checkonly)
+ open_flags = O_RDONLY;
+ else
+ open_flags = O_RDWR | O_CREAT;
/* Check for existing entry */
tq_foreach_fwd(&sudoerslist, entry) {
entry->modified = 0;
entry->prev = entry;
entry->next = NULL;
- entry->fd = open(entry->path, O_RDWR | O_CREAT, SUDOERS_MODE);
+ entry->fd = open(entry->path, open_flags, SUDOERS_MODE);
entry->tpath = NULL;
entry->doedit = doedit;
if (entry->fd == -1) {
efree(entry);
return NULL;
}
- if (!lock_file(entry->fd, SUDO_TLOCK))
+ if (!checkonly && !lock_file(entry->fd, SUDO_TLOCK))
errorx(1, _("%s busy, try again later"), entry->path);
if ((fp = fdopen(entry->fd, "r")) == NULL)
error(1, "%s", entry->path);