Hello,

ipa-nis-manage: add status option

https://bugzilla.redhat.com/show_bug.cgi?id=1329275

-- 
Petr^2 Spacek
From abbc34feb5b360694c9afc94fd75a9b0dbb5ab7f Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspa...@redhat.com>
Date: Mon, 25 Apr 2016 16:56:08 +0200
Subject: [PATCH] ipa-nis-manage: add status option

https://bugzilla.redhat.com/show_bug.cgi?id=1329275
---
 install/tools/ipa-nis-manage       | 20 +++++++++++++++++---
 install/tools/man/ipa-nis-manage.1 |  8 ++++++--
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/install/tools/ipa-nis-manage b/install/tools/ipa-nis-manage
index 3aa1507b205eaa679edebda2a3705b494369abc3..ac21e65df8b7c7e064315c2944869ff9ee8ab3bc 100755
--- a/install/tools/ipa-nis-manage
+++ b/install/tools/ipa-nis-manage
@@ -47,7 +47,7 @@ nis_config_dn = DN(('cn', 'NIS Server'), ('cn', 'plugins'), ('cn', 'config'))
 compat_dn = DN(('cn', 'Schema Compatibility'), ('cn', 'plugins'), ('cn', 'config'))
 
 def parse_options():
-    usage = "%prog [options] <enable|disable>\n"
+    usage = "%prog [options] <enable|disable|status>\n"
     usage += "%prog [options]\n"
     parser = OptionParser(usage=usage, formatter=config.IPAFormatter())
 
@@ -97,7 +97,7 @@ def main():
 
     if len(args) != 1:
         sys.exit("You must specify one action, either enable or disable")
-    elif args[0] != "enable" and args[0] != "disable":
+    elif args[0] != "enable" and args[0] != "disable" and args[0] != "status":
         sys.exit("Unrecognized action [" + args[0] + "]")
 
     standard_logging_setup(None, debug=options.debug)
@@ -187,11 +187,25 @@ def main():
                 print(lde)
                 retval = 1
 
+        elif args[0] == "status":
+            nis_entry = get_entry(nis_config_dn, conn)
+            enabled = (nis_entry and
+                       nis_entry.get(
+                           'nsslapd-pluginenabled', '')[0].lower() == "on")
+            if enabled:
+                print("Plugin is enabled")
+                retval = 0
+            else:
+                print("Plugin is not enabled")
+                retval = 4
+
         else:
             retval = 1
 
         if retval == 0:
-            print("This setting will not take effect until you restart Directory Server.")
+            if args[0] in {"enable", "disable"}:
+                print("This setting will not take effect until you restart "
+                      "Directory Server.")
 
             if args[0] == "enable":
                 print("The %s service may need to be started." % servicemsg)
diff --git a/install/tools/man/ipa-nis-manage.1 b/install/tools/man/ipa-nis-manage.1
index d60fda788fb7b97d6fa97544f63f346eb13e956a..93278487c1adb50f4ae49804d0214841e2bef30c 100644
--- a/install/tools/man/ipa-nis-manage.1
+++ b/install/tools/man/ipa-nis-manage.1
@@ -20,13 +20,15 @@
 .SH "NAME"
 ipa\-nis\-manage \- Enables or disables the NIS listener plugin
 .SH "SYNOPSIS"
-ipa\-nis\-manage [options] <enable|disable>
+ipa\-nis\-manage [options] <enable|disable|status>
 .SH "DESCRIPTION"
 Run the command with the \fBenable\fR option to enable the NIS plugin.
 
 Run the command with the \fBdisable\fR option to disable the NIS plugin.
 
-In both cases the user will be prompted to provide the Directory Manager's password unless option \fB\-y\fR is used.
+Run the command with the \fBstatus\fR option to read status of the NIS plugin. Return code 0 indicates enabled plugin, return code 4 indicates disabled plugin.
+
+In all cases the user will be prompted to provide the Directory Manager's password unless option \fB\-y\fR is used.
 
 Directory Server will need to be restarted after the NIS listener plugin has been enabled.
 
@@ -45,3 +47,5 @@ File containing the Directory Manager password
 2 if the plugin is already in the required status (enabled or disabled)
 
 3 if RPC services cannot be enabled.
+
+4 if status command detected plugin in disabled state.
-- 
2.5.5

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to