Update Files in a Solaris Package without Rebuilding the Package

Posted April 1, 2004 by Michilimackinac in Solaris




Note: Please save a backup copy of your package before attempting this.


% grep "sudoers " pkgmap
1 f none /etc/sudoers 0440 root root 324 27801 1080878491
%

where 324 is the size of the file (ls -l)
where 27801 is the checksum (/usr/bin/sum)
and 1080878491 is the modification time of the file in seconds since the epoch (modtime)

I created the modtime program since I knew no way to obtain a file’s modification time in units of seconds since the epoch.

Here is the source (solaris 9):


/*
* modtime
*
* This Program was created to display the modification time of
* a file in units of seconds since the epoch
*
*/

#include
#include
#include

int main(int argc, char *argv[])
{
struct stat filestats;
stat(argv[1],&filestats);
printf("modification time: %15d\n",filestats.st_mtim.tv_sec);
}

I also created a script (pkgremap) to combine the size, sum, and modtime in a format similar to pkgmap:


#!/bin/sh
#
# pkgremap

/usr/bin/ls -l $1 | /usr/bin/awk '{printf "%s ",$5}'
/usr/bin/sum $1 | /usr/bin/awk '{printf "%s ",$1}'
/path_to_modtime/modtime $1 | /usr/bin/awk '{printf "%s\n",$NF}'

Knowing this, assume we want to update a package that we have created for using “sudo”. Let’s say this is our original sudoers file that comes with the package.


# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# User privilege specification
victoria ALL=(ALL) ALL

Here we see another system admin has been added though we do not want to compile another version of the package. Let us assume we are in the directory of the package. (You should see a pkginfo and a pkgmap here with an “ls”.) We can cd to the location of the file in this case root/etc. Now, we can make our addition to the file:


# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# User privilege specification
victoria ALL=(ALL) ALL
mackenzie ALL=(ALL) ALL

Run the script pkgremap:


% ~/pkgremap sudoers
348 29596 1080878786
%

Edit the pkgmap entry:
1 f none /etc/sudoers 0440 root root 348 29596 1080878786

Install the package with the updated sudoers file.

The Conversation

Follow the reactions below and share your own thoughts.