From c40b2d3a70ce582de46db237b483184f060eb4e9 Mon Sep 17 00:00:00 2001 From: John Dennis Date: Mon, 1 Apr 2013 00:14:14 -0400 Subject: Add Python scription: realmd-cim Add RealmName property to LMI_RealmdRealm class --- LMI_RealmdKerberosRealm.h | 106 ++++++++++---------- LMI_RealmdRealm.h | 66 ++++++++++-- doc/examples/realmd-cim | 249 ++++++++++++++++++++++++++++++++++++++++++++++ mof/LMI_Realmd.mof | 5 + rdcp_realmdrealm.h | 4 + 5 files changed, 366 insertions(+), 64 deletions(-) create mode 100755 doc/examples/realmd-cim diff --git a/LMI_RealmdKerberosRealm.h b/LMI_RealmdKerberosRealm.h index 641fb29..cf6930d 100644 --- a/LMI_RealmdKerberosRealm.h +++ b/LMI_RealmdKerberosRealm.h @@ -258,6 +258,7 @@ typedef struct _LMI_RealmdKerberosRealm /* LMI_RealmdRealm features */ const KString SystemCreationClassName; const KString SystemName; + const KString RealmName; const KString Configured; const KStringA SupportedInterfaces; const KStringA DetailNames; @@ -267,7 +268,6 @@ typedef struct _LMI_RealmdKerberosRealm const KString LoginPolicy; const KStringA PermittedLogins; /* LMI_RealmdKerberosRealm features */ - const KString RealmName; const KString DomainName; const KString SuggestedAdministrator; const KUint32A SupportedJoinCredentialTypes; @@ -297,16 +297,16 @@ static const unsigned char __LMI_RealmdKerberosRealm_sig[] = 0x61,0x72,0x79,0x53,0x74,0x61,0x74,0x75,0x73,0x00,0x4c,0x17,0x53,0x79,0x73, 0x74,0x65,0x6d,0x43,0x72,0x65,0x61,0x74,0x69,0x6f,0x6e,0x43,0x6c,0x61,0x73, 0x73,0x4e,0x61,0x6d,0x65,0x00,0x4c,0x0a,0x53,0x79,0x73,0x74,0x65,0x6d,0x4e, - 0x61,0x6d,0x65,0x00,0x0c,0x0a,0x43,0x6f,0x6e,0x66,0x69,0x67,0x75,0x72,0x65, - 0x64,0x00,0x8c,0x13,0x53,0x75,0x70,0x70,0x6f,0x72,0x74,0x65,0x64,0x49,0x6e, - 0x74,0x65,0x72,0x66,0x61,0x63,0x65,0x73,0x00,0x8c,0x0b,0x44,0x65,0x74,0x61, - 0x69,0x6c,0x4e,0x61,0x6d,0x65,0x73,0x00,0x8c,0x0c,0x44,0x65,0x74,0x61,0x69, - 0x6c,0x56,0x61,0x6c,0x75,0x65,0x73,0x00,0x8c,0x10,0x52,0x65,0x71,0x75,0x69, - 0x72,0x65,0x64,0x50,0x61,0x63,0x6b,0x61,0x67,0x65,0x73,0x00,0x8c,0x0c,0x4c, - 0x6f,0x67,0x69,0x6e,0x46,0x6f,0x72,0x6d,0x61,0x74,0x73,0x00,0x0c,0x0b,0x4c, - 0x6f,0x67,0x69,0x6e,0x50,0x6f,0x6c,0x69,0x63,0x79,0x00,0x8c,0x0f,0x50,0x65, - 0x72,0x6d,0x69,0x74,0x74,0x65,0x64,0x4c,0x6f,0x67,0x69,0x6e,0x73,0x00,0x0c, - 0x09,0x52,0x65,0x61,0x6c,0x6d,0x4e,0x61,0x6d,0x65,0x00,0x0c,0x0a,0x44,0x6f, + 0x61,0x6d,0x65,0x00,0x0c,0x09,0x52,0x65,0x61,0x6c,0x6d,0x4e,0x61,0x6d,0x65, + 0x00,0x0c,0x0a,0x43,0x6f,0x6e,0x66,0x69,0x67,0x75,0x72,0x65,0x64,0x00,0x8c, + 0x13,0x53,0x75,0x70,0x70,0x6f,0x72,0x74,0x65,0x64,0x49,0x6e,0x74,0x65,0x72, + 0x66,0x61,0x63,0x65,0x73,0x00,0x8c,0x0b,0x44,0x65,0x74,0x61,0x69,0x6c,0x4e, + 0x61,0x6d,0x65,0x73,0x00,0x8c,0x0c,0x44,0x65,0x74,0x61,0x69,0x6c,0x56,0x61, + 0x6c,0x75,0x65,0x73,0x00,0x8c,0x10,0x52,0x65,0x71,0x75,0x69,0x72,0x65,0x64, + 0x50,0x61,0x63,0x6b,0x61,0x67,0x65,0x73,0x00,0x8c,0x0c,0x4c,0x6f,0x67,0x69, + 0x6e,0x46,0x6f,0x72,0x6d,0x61,0x74,0x73,0x00,0x0c,0x0b,0x4c,0x6f,0x67,0x69, + 0x6e,0x50,0x6f,0x6c,0x69,0x63,0x79,0x00,0x8c,0x0f,0x50,0x65,0x72,0x6d,0x69, + 0x74,0x74,0x65,0x64,0x4c,0x6f,0x67,0x69,0x6e,0x73,0x00,0x0c,0x0a,0x44,0x6f, 0x6d,0x61,0x69,0x6e,0x4e,0x61,0x6d,0x65,0x00,0x0c,0x16,0x53,0x75,0x67,0x67, 0x65,0x73,0x74,0x65,0x64,0x41,0x64,0x6d,0x69,0x6e,0x69,0x73,0x74,0x72,0x61, 0x74,0x6f,0x72,0x00,0x85,0x1c,0x53,0x75,0x70,0x70,0x6f,0x72,0x74,0x65,0x64, @@ -1446,6 +1446,48 @@ KINLINE void LMI_RealmdKerberosRealm_Clr_SystemName( } } +KINLINE void LMI_RealmdKerberosRealm_SetString_RealmName( + LMI_RealmdKerberosRealm* self, + CMPIString* x) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_SetString(field, x); + } +} + +KINLINE void LMI_RealmdKerberosRealm_Set_RealmName( + LMI_RealmdKerberosRealm* self, + const char* s) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_Set(field, self->__base.cb, s); + } +} + +KINLINE void LMI_RealmdKerberosRealm_Null_RealmName( + LMI_RealmdKerberosRealm* self) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_Null(field); + } +} + +KINLINE void LMI_RealmdKerberosRealm_Clr_RealmName( + LMI_RealmdKerberosRealm* self) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_Clr(field); + } +} + KINLINE void LMI_RealmdKerberosRealm_SetString_Configured( LMI_RealmdKerberosRealm* self, CMPIString* x) @@ -2094,48 +2136,6 @@ KINLINE void LMI_RealmdKerberosRealm_Clr_PermittedLogins( } } -KINLINE void LMI_RealmdKerberosRealm_SetString_RealmName( - LMI_RealmdKerberosRealm* self, - CMPIString* x) -{ - if (self && self->__base.magic == KMAGIC) - { - KString* field = (KString*)&self->RealmName; - KString_SetString(field, x); - } -} - -KINLINE void LMI_RealmdKerberosRealm_Set_RealmName( - LMI_RealmdKerberosRealm* self, - const char* s) -{ - if (self && self->__base.magic == KMAGIC) - { - KString* field = (KString*)&self->RealmName; - KString_Set(field, self->__base.cb, s); - } -} - -KINLINE void LMI_RealmdKerberosRealm_Null_RealmName( - LMI_RealmdKerberosRealm* self) -{ - if (self && self->__base.magic == KMAGIC) - { - KString* field = (KString*)&self->RealmName; - KString_Null(field); - } -} - -KINLINE void LMI_RealmdKerberosRealm_Clr_RealmName( - LMI_RealmdKerberosRealm* self) -{ - if (self && self->__base.magic == KMAGIC) - { - KString* field = (KString*)&self->RealmName; - KString_Clr(field); - } -} - KINLINE void LMI_RealmdKerberosRealm_SetString_DomainName( LMI_RealmdKerberosRealm* self, CMPIString* x) diff --git a/LMI_RealmdRealm.h b/LMI_RealmdRealm.h index 6f3963e..bba2089 100644 --- a/LMI_RealmdRealm.h +++ b/LMI_RealmdRealm.h @@ -256,6 +256,7 @@ typedef struct _LMI_RealmdRealm /* LMI_RealmdRealm features */ const KString SystemCreationClassName; const KString SystemName; + const KString RealmName; const KString Configured; const KStringA SupportedInterfaces; const KStringA DetailNames; @@ -270,7 +271,7 @@ LMI_RealmdRealm; static const unsigned char __LMI_RealmdRealm_sig[] = { 0x0f,0x4c,0x4d,0x49,0x5f,0x52,0x65,0x61,0x6c,0x6d,0x64,0x52,0x65,0x61,0x6c, - 0x6d,0x00,0x18,0x4c,0x0a,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44, + 0x6d,0x00,0x19,0x4c,0x0a,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44, 0x00,0x0c,0x07,0x43,0x61,0x70,0x74,0x69,0x6f,0x6e,0x00,0x0c,0x0b,0x44,0x65, 0x73,0x63,0x72,0x69,0x70,0x74,0x69,0x6f,0x6e,0x00,0x0c,0x0b,0x45,0x6c,0x65, 0x6d,0x65,0x6e,0x74,0x4e,0x61,0x6d,0x65,0x00,0x0d,0x0b,0x49,0x6e,0x73,0x74, @@ -286,16 +287,17 @@ static const unsigned char __LMI_RealmdRealm_sig[] = 0x00,0x03,0x0d,0x50,0x72,0x69,0x6d,0x61,0x72,0x79,0x53,0x74,0x61,0x74,0x75, 0x73,0x00,0x4c,0x17,0x53,0x79,0x73,0x74,0x65,0x6d,0x43,0x72,0x65,0x61,0x74, 0x69,0x6f,0x6e,0x43,0x6c,0x61,0x73,0x73,0x4e,0x61,0x6d,0x65,0x00,0x4c,0x0a, - 0x53,0x79,0x73,0x74,0x65,0x6d,0x4e,0x61,0x6d,0x65,0x00,0x0c,0x0a,0x43,0x6f, - 0x6e,0x66,0x69,0x67,0x75,0x72,0x65,0x64,0x00,0x8c,0x13,0x53,0x75,0x70,0x70, - 0x6f,0x72,0x74,0x65,0x64,0x49,0x6e,0x74,0x65,0x72,0x66,0x61,0x63,0x65,0x73, - 0x00,0x8c,0x0b,0x44,0x65,0x74,0x61,0x69,0x6c,0x4e,0x61,0x6d,0x65,0x73,0x00, - 0x8c,0x0c,0x44,0x65,0x74,0x61,0x69,0x6c,0x56,0x61,0x6c,0x75,0x65,0x73,0x00, - 0x8c,0x10,0x52,0x65,0x71,0x75,0x69,0x72,0x65,0x64,0x50,0x61,0x63,0x6b,0x61, - 0x67,0x65,0x73,0x00,0x8c,0x0c,0x4c,0x6f,0x67,0x69,0x6e,0x46,0x6f,0x72,0x6d, - 0x61,0x74,0x73,0x00,0x0c,0x0b,0x4c,0x6f,0x67,0x69,0x6e,0x50,0x6f,0x6c,0x69, - 0x63,0x79,0x00,0x8c,0x0f,0x50,0x65,0x72,0x6d,0x69,0x74,0x74,0x65,0x64,0x4c, - 0x6f,0x67,0x69,0x6e,0x73,0x00, + 0x53,0x79,0x73,0x74,0x65,0x6d,0x4e,0x61,0x6d,0x65,0x00,0x0c,0x09,0x52,0x65, + 0x61,0x6c,0x6d,0x4e,0x61,0x6d,0x65,0x00,0x0c,0x0a,0x43,0x6f,0x6e,0x66,0x69, + 0x67,0x75,0x72,0x65,0x64,0x00,0x8c,0x13,0x53,0x75,0x70,0x70,0x6f,0x72,0x74, + 0x65,0x64,0x49,0x6e,0x74,0x65,0x72,0x66,0x61,0x63,0x65,0x73,0x00,0x8c,0x0b, + 0x44,0x65,0x74,0x61,0x69,0x6c,0x4e,0x61,0x6d,0x65,0x73,0x00,0x8c,0x0c,0x44, + 0x65,0x74,0x61,0x69,0x6c,0x56,0x61,0x6c,0x75,0x65,0x73,0x00,0x8c,0x10,0x52, + 0x65,0x71,0x75,0x69,0x72,0x65,0x64,0x50,0x61,0x63,0x6b,0x61,0x67,0x65,0x73, + 0x00,0x8c,0x0c,0x4c,0x6f,0x67,0x69,0x6e,0x46,0x6f,0x72,0x6d,0x61,0x74,0x73, + 0x00,0x0c,0x0b,0x4c,0x6f,0x67,0x69,0x6e,0x50,0x6f,0x6c,0x69,0x63,0x79,0x00, + 0x8c,0x0f,0x50,0x65,0x72,0x6d,0x69,0x74,0x74,0x65,0x64,0x4c,0x6f,0x67,0x69, + 0x6e,0x73,0x00, }; KINLINE void LMI_RealmdRealm_Init( @@ -1424,6 +1426,48 @@ KINLINE void LMI_RealmdRealm_Clr_SystemName( } } +KINLINE void LMI_RealmdRealm_SetString_RealmName( + LMI_RealmdRealm* self, + CMPIString* x) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_SetString(field, x); + } +} + +KINLINE void LMI_RealmdRealm_Set_RealmName( + LMI_RealmdRealm* self, + const char* s) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_Set(field, self->__base.cb, s); + } +} + +KINLINE void LMI_RealmdRealm_Null_RealmName( + LMI_RealmdRealm* self) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_Null(field); + } +} + +KINLINE void LMI_RealmdRealm_Clr_RealmName( + LMI_RealmdRealm* self) +{ + if (self && self->__base.magic == KMAGIC) + { + KString* field = (KString*)&self->RealmName; + KString_Clr(field); + } +} + KINLINE void LMI_RealmdRealm_SetString_Configured( LMI_RealmdRealm* self, CMPIString* x) diff --git a/doc/examples/realmd-cim b/doc/examples/realmd-cim new file mode 100755 index 0000000..01d59a4 --- /dev/null +++ b/doc/examples/realmd-cim @@ -0,0 +1,249 @@ +#!/usr/bin/python + +import sys +import os +import optparse +import urlparse +import pywbem + +#---------------------------------------------------------------------- + +REALM_DBUS_KERBEROS_MEMBERSHIP_INTERFACE = "org.freedesktop.realmd.KerberosMembership" + +#---------------------------------------------------------------------- + +def do_list(conn, options, args): + realms = conn.EnumerateInstances('LMI_RealmdKerberosRealm') + + print "%d realms" % (len(realms)) + + for realm in realms: + if options.verbose > 1: + # Very verbose, dump all properties + property_names = sorted(realm.keys()) + for name in property_names: + value = realm[name] + print " %s: %s" % (name, value) + + print realm['RealmName'] + print " type: kerberos" + print " realm-name: %s" % realm['RealmName'] + print " domain-name: %s" % realm['DomainName'] + + is_configured = True + configured = realm['Configured'] + if not configured: + configured = "no" + is_configured = False + elif configured == REALM_DBUS_KERBEROS_MEMBERSHIP_INTERFACE: + configured = "kerberos-member" + + print " configured: %s" % configured + + for detail in zip(realm['DetailNames'], realm['DetailValues']): + print " %s: %s" % (detail[0], detail[1]) + + if is_configured: + print " login-formats: %s" % ", ".join(realm['LoginFormats']) + print " login-policy: %s" % realm['LoginPolicy'] + print " permitted-logins: %s" % ", ".join(realm['PermittedLogins']) + + print + +def do_join(conn, options, args): + # Validate arguments + if len(args) != 3: + raise ValueError("You must supply exacly 3 arguments (user, password, domain)") + + user, password, domain = args + + if (options.verbose): + print "Joining domain: %s" % domain + + try: + realmd_service_instance_name = conn.EnumerateInstanceNames('LMI_RealmdService')[0] + except Exception, e: + raise ValueError("could not obtain realmd service") + + try: + retval, outparams = conn.InvokeMethod("JoinDomain", realmd_service_instance_name, + Domain=domain, + User=user, + Password=password) + except Exception, e: + raise ValueError("Join failed (%s)" % (e)) + + + +def do_leave(conn, options, args): + # Validate arguments + if len(args) != 3: + raise ValueError("You must supply exacly 3 arguments (user, password, domain)") + + user, password, domain = args + + if (options.verbose): + print "Leave domain: %s" % domain + + try: + realmd_service_instance_name = conn.EnumerateInstanceNames('LMI_RealmdService')[0] + except Exception, e: + raise ValueError("could not obtain realmd service") + + try: + retval, outparams = conn.InvokeMethod("LeaveDomain", realmd_service_instance_name, + Domain=domain, + User=user, + Password=password) + except Exception, e: + raise ValueError("Leave failed (%s)" % (e)) + + + +def do_discover(conn, options, args): + # Validate arguments + if len(args) != 1: + raise ValueError("You must supply exactly 1 domain.") + + domain = args[0] + + if (options.verbose): + print "Discovering domain: %s" % domain + + try: + realmd_service_instance_name = conn.EnumerateInstanceNames('LMI_RealmdService')[0] + except Exception, e: + raise ValueError("could not obtain realmd service") + + try: + retval, outparams = conn.InvokeMethod("Discover", realmd_service_instance_name, + Target=domain) + except Exception, e: + raise ValueError("Join failed (%s)" % (e)) + + realm_refs = outparams['DiscoveredRealms'] + + print "%d Discovered" % len(realm_refs) + for realm_ref in realm_refs: + #print realm_ref + realm = conn.GetInstance(realm_ref) + print realm['RealmName'] + print " Name: %s" % realm['RealmName'] + print " Configured: %s" % realm['Configured'] + print " Supported Interfaces: %s" % ", ".join(realm['SupportedInterfaces']) + for detail in zip(realm['DetailNames'], realm['DetailValues']): + print " %s: %s" % (detail[0], detail[1]) + print " login-formats: %s" % ", ".join(realm['LoginFormats']) + print " login-policy: %s" % realm['LoginPolicy'] + print " permitted-logins: %s" % ", ".join(realm['PermittedLogins']) + + + +#---------------------------------------------------------------------- + +def main(): + + actions = {'list': do_list, + 'discover': do_discover, + 'join': do_join, + 'leave': do_leave, + } + + usage =''' + %%prog [options] ... + + %%prog [options] list + %%prog [options] discover domain + %%prog [options] join user password domain + %%prog [options] leave user password domain + + Available Actions: %(actions)s + ''' % {'actions': ", ".join(sorted(actions.keys()))} + + # Set-up defaults + + default_cimom_port = 5989 + default_url = os.environ.get("LMI_CIMOM_URL", "https://localhost:5989") + + parsed_default_url = urlparse.urlparse(default_url) + + if parsed_default_url.port: + default_port = parsed_default_url.port or default_cimom_port + + default_username = os.environ.get("LMI_CIMOM_USERNAME", "root") + default_password = os.environ.get("LMI_CIMOM_PASSWORD", "") + + # Set-up arg parser + parser = optparse.OptionParser(usage=usage) + + parser.add_option('-c', '--url', dest='url', default=default_url, + help='CIMOM URL or hostname to connect to') + + parser.add_option('-u', '--username', dest='username', default=default_username, + help='Username for CIMOM authentication') + + parser.add_option('-p', '--password', dest='password', default=default_password, + help='Password for CIMOM authentication') + + parser.add_option('-v', '--verbose', dest='verbose', default=0, + action='count', + help='Turn on verbose output, increases verbosity level by one each time specified') + + options, args = parser.parse_args() + + # Validate arguments + + try: + action = args.pop(0) + except IndexError: + print >>sys.stderr, "You must supply an action to execute" + parser.print_help() + return 1 + + try: + action_func = actions[action] + except KeyError: + print >>sys.stderr, "Unknown action (%s)" % (action) + parser.print_help() + return 1 + + # Get CIMOM URL + + parsed_url = urlparse.urlparse(options.url) + + if not parsed_url.netloc: + # Handle case where URL was bare hostname + parsed_url = urlparse.urlparse('//' + options.url) + + scheme = 'https' + hostname = parsed_url.hostname + port = parsed_url.port or default_port + + url = urlparse.urlunparse((scheme, "%s:%d" % (hostname, port), '', None, None, None)) + + # Connect to CIMOM + + if (options.verbose): + print "Connecting to: %s" % url + + try: + conn = pywbem.WBEMConnection(url, (options.username, options.password)) + except Exception, e: + print >>sys.stderr, "Unable to connect to %s (%s)" % (options.url, e) + return 1 + + + # Execute action + + try: + action_func(conn, options, args) + except Exception, e: + print >>sys.stderr, "%s failed: %s" % (action, e) + return 1 + + return 0 + +#---------------------------------------------------------------------- + +if __name__ == "__main__": + sys.exit(main()) diff --git a/mof/LMI_Realmd.mof b/mof/LMI_Realmd.mof index 8f2e77b..20792e9 100644 --- a/mof/LMI_Realmd.mof +++ b/mof/LMI_Realmd.mof @@ -176,6 +176,11 @@ class LMI_RealmdRealm : CIM_LogicalElement Propagated ( "CIM_System.Name" )] string SystemName; + [Description ( + "Name of the realm, " + "appropriate for display to end users where necessary.")] + string RealmName; + [Description ( "If this property is NULL then the realm is not configured." "Otherwise the realm is configured and the property contains " diff --git a/rdcp_realmdrealm.h b/rdcp_realmdrealm.h index 57ec069..cc70395 100644 --- a/rdcp_realmdrealm.h +++ b/rdcp_realmdrealm.h @@ -170,6 +170,10 @@ KINLINE bool SupportsDBusInterface(GVariant *dbus_props, const char *dbus_interf GVariantIter *iter; \ CMPICount i; \ \ + if (g_variant_lookup(dbus_props, "Name", "&s", &value)) { \ + klass##_Set_RealmName(obj, value); \ + } \ + \ if (g_variant_lookup(dbus_props, "Configured", "&s", &value)) { \ klass##_Set_Configured(obj, value); \ } \ -- cgit