# This file is part of owperlprovider. # Copyright (c) 2004-2005 Jason Long. All rights reserved. This program # is free software; you can redistribute it and/or modify it under the # same terms as Perl itself. # USAGE: # Import the associated schema file (person.mof) into the OpenWBEM # CIMOM using owmofc. # Copy this file into /usr/local/lib/openwbem/perlproviders/ use Net::OpenWBEM::Provider; use User::pwent; use strict; use warnings; use constant CLASSNAME => 'owperl_Person'; # # This provider implements CIM_Person (User27_Org.mof) # # perform initialization tasks print "Initializing PersonProvider.pl\n"; print "time = ", time, "\n"; sub canUnload { return 1; } END { print "Unloading PersonProvider.pl\n"; print "time = ", time, "\n"; } sub enumInstanceNames { my ($env, $ns, $className, $result, $cimClass) = @_; print "Entering enumInstanceNames\n"; while (my $pw = getpwent) { my $mcop = Net::OpenWBEM::CIMObjectPath->new($className, $ns); $mcop->setStringKeyValue('CreationClassName', CLASSNAME); $mcop->setStringKeyValue('Name', $pw->name); $result->handle($mcop); } endpwent; print "Leaving enumInstanceNames\n"; } sub enumInstances { my ($env, $ns, $className, $localOnly, $deep, $includeQualifiers, $includeClassOrigin, $result, $cimClass, $requestedClass) = @_; print "Entering enumInstances\n"; while (my $pw = getpwent) { # build a new instance using the current $pw and # return it to the caller $result->handle(pw2instance($pw, $cimClass)); } endpwent; print "Leaving enumInstances\n"; } sub getInstance { my ($env, $ns, $instanceName, $localOnly, $includeQualifiers, $includeClassOrigin, $propertyList, $cimClass) = @_; print "Entering getInstance\n"; # what username is requested? my $username = $instanceName->getStringKeyValue('Name'); # look up that user my $pw = getpwnam($username); # generate a CIMInstance from the given $pw and return it # to the caller return pw2instance($pw, $cimClass); } sub pw2instance { my ($pw, $cimClass) = @_; # create a new instance using the provided CIMClass object my $ci = $cimClass->newInstance; # set key properties $ci->CreationClassName(CLASSNAME); $ci->Name($pw->name); # set other properties $ci->CommonName($pw->gecos); $ci->UserId($pw->uid); $ci->ElementName($pw->name); $ci->GroupID($pw->gid); $ci->HomeDirectory($pw->dir); $ci->Password($pw->passwd); return $ci; } sub modifyInstance { my ($env, $ns, $modifiedInstance, $previousInstance, $includeQualifiers, $propertyList, $theClass) = @_; print "Entering modifyInstance\n"; # throw an exception die "You cannot modify a person!\n"; print "Leaving modifyInstance\n"; }