return(1);
}
+/*
+ * Print a record in the short form, ala file sudoers.
+ */
+int
+sudo_ldap_display_entry_short(ld, entry, lbuf)
+ LDAP *ld;
+ LDAPMessage *entry;
+ struct lbuf *lbuf;
+{
+ struct berval **bv, **p;
+ int count = 0;
+
+ lbuf_append(lbuf, " (", NULL);
+
+ /* get the RunAsUser Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoRunAsUser");
+ if (bv == NULL)
+ bv = ldap_get_values_len(ld, entry, "sudoRunAs");
+ if (bv != NULL) {
+ for (p = bv; *p != NULL; p++) {
+ if (p != bv)
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, (*p)->bv_val, NULL);
+ }
+ ldap_value_free_len(bv);
+ } else
+ lbuf_append(lbuf, def_runas_default, NULL);
+
+ /* get the RunAsGroup Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoRunAsGroup");
+ if (bv != NULL) {
+ lbuf_append(lbuf, " : ", NULL);
+ for (p = bv; *p != NULL; p++) {
+ if (p != bv)
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, (*p)->bv_val, NULL);
+ }
+ ldap_value_free_len(bv);
+ }
+ lbuf_append(lbuf, ") ", NULL);
+
+ /* get the Option Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoOption");
+ if (bv != NULL) {
+ char *cp, *tag;
+
+ for (p = bv; *p != NULL; p++) {
+ cp = (*p)->bv_val;
+ if (*cp == '!')
+ cp++;
+ tag = NULL;
+ if (strcmp(cp, "authenticate") == 0)
+ tag = (*p)->bv_val[0] == '!' ?
+ "NOPASSWD: " : "PASSWD: ";
+ else if (strcmp(cp, "noexec") == 0)
+ tag = (*p)->bv_val[0] == '!' ?
+ "EXEC: " : "NOEXEC: ";
+ else if (strcmp(cp, "setenv") == 0)
+ tag = (*p)->bv_val[0] == '!' ?
+ "NOSETENV: " : "SETENV: ";
+ if (tag != NULL)
+ lbuf_append(lbuf, tag, NULL);
+ /* XXX - ignores other options */
+ }
+ ldap_value_free_len(bv);
+ }
+
+ /* get the Command Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoCommand");
+ if (bv != NULL) {
+ for (p = bv; *p != NULL; p++) {
+ if (p != bv)
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, (*p)->bv_val, NULL);
+ count++;
+ }
+ ldap_value_free_len(bv);
+ }
+
+ lbuf_print(lbuf); /* forces a newline */
+ return(count);
+}
+
+/*
+ * Print a record in the long form.
+ */
+int
+sudo_ldap_display_entry_long(ld, entry, lbuf)
+ LDAP *ld;
+ LDAPMessage *entry;
+ struct lbuf *lbuf;
+{
+ struct berval **bv, **p;
+ char *rdn;
+ int count = 0;
+
+ /* extract the dn, only show the first rdn */
+ rdn = sudo_ldap_get_first_rdn(ld, entry);
+ lbuf_print(lbuf); /* force a newline */
+ lbuf_append(lbuf, "LDAP Role: ", rdn ? rdn : "UNKNOWN", NULL);
+ lbuf_print(lbuf);
+ if (rdn)
+ ldap_memfree(rdn);
+
+ /* get the RunAsUser Values from the entry */
+ lbuf_append(lbuf, " RunAsUsers: ", NULL);
+ bv = ldap_get_values_len(ld, entry, "sudoRunAsUser");
+ if (bv == NULL)
+ bv = ldap_get_values_len(ld, entry, "sudoRunAs");
+ if (bv != NULL) {
+ for (p = bv; *p != NULL; p++) {
+ if (p != bv)
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, (*p)->bv_val, NULL);
+ }
+ ldap_value_free_len(bv);
+ } else
+ lbuf_append(lbuf, def_runas_default, NULL);
+ lbuf_print(lbuf);
+
+ /* get the RunAsGroup Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoRunAsGroup");
+ if (bv != NULL) {
+ lbuf_append(lbuf, " RunAsGroups: ", NULL);
+ for (p = bv; *p != NULL; p++) {
+ if (p != bv)
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, (*p)->bv_val, NULL);
+ }
+ ldap_value_free_len(bv);
+ lbuf_print(lbuf);
+ }
+
+ /* get the Option Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoOption");
+ if (bv != NULL) {
+ lbuf_append(lbuf, " Options: ", NULL);
+ for (p = bv; *p != NULL; p++) {
+ if (p != bv)
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, (*p)->bv_val, NULL);
+ }
+ ldap_value_free_len(bv);
+ lbuf_print(lbuf);
+ }
+
+ /* get the Command Values from the entry */
+ bv = ldap_get_values_len(ld, entry, "sudoCommand");
+ if (bv != NULL) {
+ lbuf_append(lbuf, " Commands:", NULL);
+ lbuf_print(lbuf);
+ for (p = bv; *p != NULL; p++) {
+ lbuf_append(lbuf, "\t", (*p)->bv_val, NULL);
+ lbuf_print(lbuf);
+ count++;
+ }
+ ldap_value_free_len(bv);
+ }
+
+ return(count);
+}
+
/*
* Like sudo_ldap_lookup(), except we just print entries.
*/
struct passwd *pw;
struct lbuf *lbuf;
{
- struct berval **bv, **p;
LDAP *ld = (LDAP *) nss->handle;
LDAPMessage *entry = NULL, *result = NULL;
- char *filt, *rdn;
+ char *filt;
int rc, do_netgr, count = 0;
if (ld == NULL)
sudo_ldap_check_user_netgroup(ld, entry, pw->pw_name)) &&
sudo_ldap_check_host(ld, entry)) {
-#if 0
- /* extract the dn, only show the first rdn */
- /* XXX - how to display the role sudo-style? */
- rdn = sudo_ldap_get_first_rdn(ld, entry);
- printf("LDAP Role: %s\n", rdn ? rdn : "UNKNOWN");
- if (rdn)
- ldap_memfree(rdn);
-#endif
- lbuf_append(lbuf, " (", NULL);
-
- /* get the RunAsUser Values from the entry */
- bv = ldap_get_values_len(ld, entry, "sudoRunAsUser");
- if (bv == NULL)
- bv = ldap_get_values_len(ld, entry, "sudoRunAs");
- if (bv != NULL) {
- for (p = bv; *p != NULL; p++) {
- if (p != bv)
- lbuf_append(lbuf, ", ", NULL);
- lbuf_append(lbuf, (*p)->bv_val, NULL);
- }
- ldap_value_free_len(bv);
- } else
- lbuf_append(lbuf, def_runas_default, NULL);
-
- /* get the RunAsGroup Values from the entry */
- bv = ldap_get_values_len(ld, entry, "sudoRunAsGroup");
- if (bv != NULL) {
- lbuf_append(lbuf, " : ", NULL);
- for (p = bv; *p != NULL; p++) {
- if (p != bv)
- lbuf_append(lbuf, ", ", NULL);
- lbuf_append(lbuf, (*p)->bv_val, NULL);
- }
- ldap_value_free_len(bv);
- }
- lbuf_append(lbuf, ") ", NULL);
-
- /* get the Option Values from the entry */
- bv = ldap_get_values_len(ld, entry, "sudoOption");
- if (bv != NULL) {
- char *cp, *tag;
-
- for (p = bv; *p != NULL; p++) {
- cp = (*p)->bv_val;
- if (*cp == '!')
- cp++;
- tag = NULL;
- if (strcmp(cp, "authenticate") == 0)
- tag = (*p)->bv_val[0] == '!' ?
- "NOPASSWD: " : "PASSWD: ";
- else if (strcmp(cp, "noexec") == 0)
- tag = (*p)->bv_val[0] == '!' ?
- "EXEC: " : "NOEXEC: ";
- else if (strcmp(cp, "setenv") == 0)
- tag = (*p)->bv_val[0] == '!' ?
- "NOSETENV: " : "SETENV: ";
- if (tag != NULL)
- lbuf_append(lbuf, tag, NULL);
- /* XXX - ignores other options */
- }
- ldap_value_free_len(bv);
- }
-
- /* get the Command Values from the entry */
- bv = ldap_get_values_len(ld, entry, "sudoCommand");
- if (bv != NULL) {
- for (p = bv; *p != NULL; p++) {
- if (p != bv)
- lbuf_append(lbuf, ", ", NULL);
- lbuf_append(lbuf, (*p)->bv_val, NULL);
- count++;
- }
- ldap_value_free_len(bv);
- }
+ if (long_list)
+ count += sudo_ldap_display_entry_long(ld, entry, lbuf);
+ else
+ count += sudo_ldap_display_entry_short(ld, entry, lbuf);
}
- lbuf_print(lbuf); /* forces a newline */
}
ldap_msgfree(result);
result = NULL;
}
#define TAG_CHANGED(t) \
- (cs->tags.t != UNSPEC && cs->tags.t != IMPLIED && cs->tags.t != tags.t)
+ (cs->tags.t != UNSPEC && cs->tags.t != IMPLIED && cs->tags.t != tags->t)
-int
-sudo_file_display_privs(nss, pw, lbuf)
- struct sudo_nss *nss;
+static void
+sudo_file_append_cmnd(cs, tags, lbuf)
+ struct cmndspec *cs;
+ struct cmndtag *tags;
+ struct lbuf *lbuf;
+{
+ struct member *m;
+
+ if (TAG_CHANGED(setenv)) {
+ lbuf_append(lbuf, cs->tags.setenv ? "SETENV: " :
+ "NOSETENV: ", NULL);
+ tags->setenv = cs->tags.setenv;
+ }
+ if (TAG_CHANGED(noexec)) {
+ lbuf_append(lbuf, cs->tags.noexec ? "NOEXEC: " :
+ "EXEC: ", NULL);
+ tags->noexec = cs->tags.noexec;
+ }
+ if (TAG_CHANGED(nopasswd)) {
+ lbuf_append(lbuf, cs->tags.nopasswd ? "NOPASSWD: " :
+ "PASSWD: ", NULL);
+ tags->nopasswd = cs->tags.nopasswd;
+ }
+ m = cs->cmnd;
+ print_member(lbuf, m->name, m->type, m->negated,
+ CMNDALIAS);
+}
+
+static int
+sudo_file_display_priv_short(pw, us, lbuf)
struct passwd *pw;
+ struct userspec *us;
struct lbuf *lbuf;
{
struct cmndspec *cs;
struct member *m;
struct privilege *priv;
+ struct cmndtag tags;
+ int nfound = 0;
+
+ tq_foreach_fwd(&us->privileges, priv) {
+ tags.noexec = def_noexec;
+ tags.setenv = def_setenv;
+ tags.nopasswd = !def_authenticate;
+ lbuf_append(lbuf, " ", NULL);
+ tq_foreach_fwd(&priv->cmndlist, cs) {
+ if (cs != tq_first(&priv->cmndlist))
+ lbuf_append(lbuf, ", ", NULL);
+ lbuf_append(lbuf, "(", NULL);
+ if (!tq_empty(&cs->runasuserlist)) {
+ tq_foreach_fwd(&cs->runasuserlist, m) {
+ if (m != tq_first(&cs->runasuserlist))
+ lbuf_append(lbuf, ", ", NULL);
+ print_member(lbuf, m->name, m->type, m->negated,
+ RUNASALIAS);
+ }
+ } else {
+ lbuf_append(lbuf, def_runas_default, NULL);
+ }
+ if (!tq_empty(&cs->runasgrouplist)) {
+ lbuf_append(lbuf, " : ", NULL);
+ tq_foreach_fwd(&cs->runasgrouplist, m) {
+ if (m != tq_first(&cs->runasgrouplist))
+ lbuf_append(lbuf, ", ", NULL);
+ print_member(lbuf, m->name, m->type, m->negated,
+ RUNASALIAS);
+ }
+ }
+ lbuf_append(lbuf, ") ", NULL);
+ sudo_file_append_cmnd(cs, &tags, lbuf);
+ nfound++;
+ }
+ lbuf_print(lbuf); /* forces a newline */
+ }
+ return(nfound);
+}
+
+static int
+sudo_file_display_priv_long(pw, us, lbuf)
+ struct passwd *pw;
struct userspec *us;
+ struct lbuf *lbuf;
+{
+ struct cmndspec *cs;
+ struct member *m;
+ struct privilege *priv;
struct cmndtag tags;
int nfound = 0;
+ tq_foreach_fwd(&us->privileges, priv) {
+ tags.noexec = def_noexec;
+ tags.setenv = def_setenv;
+ tags.nopasswd = !def_authenticate;
+ lbuf_print(lbuf); /* force a newline */
+ lbuf_append(lbuf, "Sudoers entry:", NULL);
+ lbuf_print(lbuf);
+ tq_foreach_fwd(&priv->cmndlist, cs) {
+ lbuf_append(lbuf, " RunAsUsers: ", NULL);
+ if (!tq_empty(&cs->runasuserlist)) {
+ tq_foreach_fwd(&cs->runasuserlist, m) {
+ if (m != tq_first(&cs->runasuserlist))
+ lbuf_append(lbuf, ", ", NULL);
+ print_member(lbuf, m->name, m->type, m->negated,
+ RUNASALIAS);
+ }
+ } else {
+ lbuf_append(lbuf, def_runas_default, NULL);
+ }
+ lbuf_print(lbuf);
+ if (!tq_empty(&cs->runasgrouplist)) {
+ lbuf_append(lbuf, " RunAsGroups: ", NULL);
+ tq_foreach_fwd(&cs->runasgrouplist, m) {
+ if (m != tq_first(&cs->runasgrouplist))
+ lbuf_append(lbuf, ", ", NULL);
+ print_member(lbuf, m->name, m->type, m->negated,
+ RUNASALIAS);
+ }
+ lbuf_print(lbuf);
+ }
+ lbuf_append(lbuf, " Commands: ", NULL);
+ lbuf_print(lbuf);
+ lbuf_append(lbuf, "\t", NULL);
+ sudo_file_append_cmnd(cs, &tags, lbuf);
+ lbuf_print(lbuf);
+ nfound++;
+ }
+ }
+ return(nfound);
+}
+
+int
+sudo_file_display_privs(nss, pw, lbuf)
+ struct sudo_nss *nss;
+ struct passwd *pw;
+ struct lbuf *lbuf;
+{
+ struct userspec *us;
+ int nfound = 0;
+
if (nss->handle == NULL)
return(-1);
hostlist_matches(&us->privileges.first->hostlist) != ALLOW)
continue;
- tq_foreach_fwd(&us->privileges, priv) {
- tags.noexec = def_noexec;
- tags.setenv = def_setenv;
- tags.nopasswd = !def_authenticate;
- lbuf_append(lbuf, " ", NULL);
- tq_foreach_fwd(&priv->cmndlist, cs) {
- if (cs != tq_first(&priv->cmndlist))
- lbuf_append(lbuf, ", ", NULL);
- lbuf_append(lbuf, "(", NULL);
- if (!tq_empty(&cs->runasuserlist)) {
- tq_foreach_fwd(&cs->runasuserlist, m) {
- if (m != tq_first(&cs->runasuserlist))
- lbuf_append(lbuf, ", ", NULL);
- print_member(lbuf, m->name, m->type, m->negated,
- RUNASALIAS);
- }
- } else {
- lbuf_append(lbuf, def_runas_default, NULL);
- }
- if (!tq_empty(&cs->runasgrouplist)) {
- lbuf_append(lbuf, " : ", NULL);
- tq_foreach_fwd(&cs->runasgrouplist, m) {
- if (m != tq_first(&cs->runasgrouplist))
- lbuf_append(lbuf, ", ", NULL);
- print_member(lbuf, m->name, m->type, m->negated,
- RUNASALIAS);
- }
- }
- lbuf_append(lbuf, ") ", NULL);
- if (TAG_CHANGED(setenv)) {
- lbuf_append(lbuf, cs->tags.setenv ? "SETENV: " :
- "NOSETENV: ", NULL);
- tags.setenv = cs->tags.setenv;
- }
- if (TAG_CHANGED(noexec)) {
- lbuf_append(lbuf, cs->tags.noexec ? "NOEXEC: " :
- "EXEC: ", NULL);
- tags.noexec = cs->tags.noexec;
- }
- if (TAG_CHANGED(nopasswd)) {
- lbuf_append(lbuf, cs->tags.nopasswd ? "NOPASSWD: " :
- "PASSWD: ", NULL);
- tags.nopasswd = cs->tags.nopasswd;
- }
- m = cs->cmnd;
- print_member(lbuf, m->name, m->type, m->negated,
- CMNDALIAS);
- nfound++;
- }
- lbuf_print(lbuf); /* forces a newline */
- }
+ if (long_list)
+ nfound += sudo_file_display_priv_long(pw, us, lbuf);
+ else
+ nfound += sudo_file_display_priv_short(pw, us, lbuf);
}
return(nfound);
}