/*
*
* U.S. Government Rights - Commercial software. Government users are subject
* to the Sun Microsystems, Inc. standard license agreement and applicable
* provisions of the FAR and its supplements.
*
*
* This distribution may include materials developed by third parties. Sun,
* Sun Microsystems, the Sun logo and Solaris are trademarks or registered
* trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
*
*/
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include "sunProcesses.h"
#include <stdio.h>
#include <errno.h>
#include <procfs.h>
#include <ftw.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <memory.h>
#include <pwd.h>
#include <syslog.h>
#include "snmpvars.h"
#include "agent.h"
#include "asn1.h"
/* The following code is borrowed from ps.c */
#define FALSE 0
#ifndef MAXLOGIN
#endif
char *ttyname();
void usage(); /* print usage message and quit */
static void call_ftw_for_dev(void);
static void wrdata();
static void write_tmp_file();
static int isprocdir();
static void get_ps_data(void);
static void clean_ps(ps_ldata_t *);
static char *get_usr_name(uid_t);
static void pr_ps(void);
/* to by pstable. */
static void
{
}
}
}
static int
{
}
static struct ncache {
/*
* This function assumes that the password file is hashed
* (or some such) to allow fast access based on a uid key.
*/
static char *
{
int cp;
#else
#endif
if (!pw)
return ((char *)0);
}
void
pr_ps(void)
{
int lines;
printf("UID PID PPID SZ USR WCHAN TTY CPU CMD \n\n");
printf("%d %u %u %d %s %s %s %d %s\n",
}
}
/*
* Locate a particular PID.
* Return a pointer to the entry or NULL if not found.
*/
{
/* Should add a cache here */
pstable_lines, sizeof (ps_data_t),
(int (*)())pscomp);
return (psp);
}
void
get_ps_data(void)
{
static char *usrname;
int i = 0;
int pdlen;
char *gettty();
return;
}
pstable_lines = 0;
/*
* Determine root path for remote machine.
*/
if (!readata()) { /* get data from psfile */
wrdata();
}
/*
* Determine which processes to print info about by searching
* the /proc directory and looking at each process.
*/
(void) SYSLOG0("Cannot open PROC directory\n");
return;
}
/* for each active process --- */
int procfd;
continue;
continue;
/*
* Get the info structure for the process and close quickly.
*/
goto retry;
(void) SYSLOG2("read of %s: %s\n",
continue;
}
break;
else
i = 0;
else {
continue;
}
else
}
return;
}
}
}
int
readata()
{
int fd;
return (0);
if (!rd_only) { /* if read-only, believe old data */
return (0);
}
}
/* Read /dev data from psfile. */
return (0);
}
if (devl)
exit(1);
}
return (0);
}
return (1);
}
/*
* call_ftw_for_dev() uses ftw() to pass pathnames under /dev to gdev()
* along with a status buffer.
*/
static void
call_ftw_for_dev(void)
{
int gdev();
int rcode;
ndev = 0;
switch (rcode) {
case 0:
return; /* successful return, devl populated */
case 1:
SYSLOG0(" ftw() encountered problem\n");
break;
case -1:
break;
default:
break;
}
exit(1);
}
/*
* gdev() puts device names and ID into the devl structure for character
* special files in /dev. The "/dev/" string is stripped from the name
* and if the resulting pathname exceeds DNSIZE in length then the highest
* level directory names are stripped until the pathname is DNSIZE or less.
*/
int
char *objptr;
int numb;
{
int i;
switch (numb) {
case FTW_F:
/* Get more and be ready for syscon & systty. */
exit(1);
}
}
/*
* Save systty & syscon entries if the console
* entry hasn't been seen.
*/
lndev++;
return (0);
}
/* Strip off /dev/ */
else {
;
if (i == leng)
else
}
ndev++;
/*
* Put systty & syscon entries in devl when console
* is found.
*/
consflg++;
for (i = 0; i < lndev; i++) {
ndev++;
}
lndev = 0;
}
}
return (0);
case FTW_D:
case FTW_DNR:
case FTW_NS:
return (0);
default:
return (1);
}
}
void
wrdata()
{
char *tfname;
int fd;
(void) umask(02);
SYSLOG1(" mktemp(\"/tmp/mibiisa_ps.XXXXXX\") failed, %s\n",
return;
}
SYSLOG2(" open(\"%s\") for write failed, %s\n",
return;
}
/*
* Make owner root, group sys.
*/
/* write /dev data */
return;
}
}
/*
* gettty returns the user's tty number or ? if none.
*/
char *
int *ip; /* where the search left off last time */
{
int i;
*ip = i + 1;
}
}
}
*ip = -1;
return ("?");
}
/*
* Special read; unlinks psfile on read error.
*/
int
int fd;
char *bp;
unsigned int bs;
{
int rbs;
SYSLOG2("read_tmp_file() error on read, rbs=%d, bs=%d\n",
return (0);
}
return (1);
}
/*
* Special write; unlinks psfile on write error.
*/
void
int fd;
char *bp;
unsigned bs;
{
int wbs;
SYSLOG2("write_tmp_file() error on write, wbs=%d, bs=%d\n",
}
}
/*
* Return true iff dir is a /proc directory.
*
* This works because of the fact that "/proc/0" and "/proc/00" are the
* same file, namely process 0, and are not linked to each other. Ugly.
*/
static int
char *dir;
{
char *p;
/*
* Make a copy of the directory name without trailing '/'s
*/
else {
while (p > path && *--p == '/')
*p = '\0';
if (*path == '\0')
}
/*
* Append "/0" to the directory path and stat() the file.
*/
*p++ = '/';
*p++ = '0';
*p = '\0';
return (FALSE);
/*
* Append "/00" to the directory path and stat() the file.
*/
*p++ = '0';
*p = '\0';
return (FALSE);
/*
* See if we ended up with the same file.
*/
return (FALSE);
/*
* Return TRUE iff we have a regular file with a single link.
*/
}
/*
* Initialize the sunProcessTable table by defining its contents and how
* it's structured
*/
void initialize_table_sunProcessTable(void) {
/* create the table structure itself */
/*
* if your table is read only, it's easiest to change the
* HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY
*/
return; /* mallocs failed */
/*
* Setting up the table's definition
*/
/* iterator access routines */
/*
* registering the table with the master agent
*/
DEBUGMSGTL(("initialize_table_sunProcessTable",
"Registering table sunProcessTable as a table iterator\n"));
}
/* Initializes the sunProcesses module */
void init_sunProcesses(void) {
/* here we initialize all the tables we're planning on supporting */
}
/*
* returns the first data point within the sunProcessTable table data.
*
* Set the my_loop_context variable to the first data point structure
* of your choice (from which you can find the next one). This could
* be anything from the first node in a linked list, to an integer
* pointer containing the beginning of an array variable.
*
* Set the my_data_context variable to something to be returned to
* you later that will provide you with the data to return in a given
* row. * This could be the same pointer as what my_loop_context is
* set to, or something different.
*
* The put_index_data variable contains a list of snmp variable
* bindings, one for each index in your table. * Set the values of
* each appropriately according to the data matching the first row
* and return the put_index_data variable at the end of the function.
*/
void **my_data_context,
long long_type;
get_ps_data();
return (NULL);
}
/* vptr = vptr->next_variable; */
/*
pr_ps();
*/
return (put_index_data);
}
/*
* functionally the same as sunProcessTable_get_first_data_point, but
* my_loop_context has already been set to a previous value and should
* be updated to the next in the list. For example, if it was a
* linked list, you might want to cast it and the return
* my_loop_context->next. The my_data_context pointer should be set
* to something you need later and the indexes in put_index_data
* updated again.
*/
void **my_data_context,
{
long long_type;
get_ps_data();
ps_ptr++;
return (NULL);
}
/* vptr = vptr->next_variable; */
return (put_index_data);
}
/*
* handles requests for the sunProcessTable table,
* if anything else needs to be done
*/
long long_type;
/* For caching purposes, find out what the time is now */
continue;
/* perform anything here that you need to do before each */
/* request is processed. */
/* the following extracts the my_data_context pointer set in */
/* the loop functions above. You can then use the results to */
/* help return data for the columns of the sunProcessTable */
/* table in question */
continue;
}
/*
* XXX: no row existed, if you support creation and this is a
* set, start dealing with it here, else continue
*/
}
/* extracts the information about the table from the request */
/* table_info->colnum contains the column number requested */
/* table_info->indexes contains a linked list of snmp variable */
/* bindings for the indexes of the table. Values in the list */
/* have been set corresponding to the indexes of the request */
if (table_info == NULL) {
continue;
}
/*
* the table_iterator helper should change all GETNEXTs
* into GETs for you automatically, so you don't have to
* worry about the GETNEXT case. Only GETs and SETs need
* to be dealt with here
*/
case MODE_GET:
switch (table_info->colnum) {
case COLUMN_PSPROCESSID:
sizeof (long_type));
break;
case COLUMN_PSPARENTPROCESSID:
sizeof (long_type));
break;
case COLUMN_PSPROCESSSIZE:
sizeof (long_type));
break;
case COLUMN_PSPROCESSCPUTIME:
sizeof (long_type));
break;
case COLUMN_PSPROCESSSTATE:
break;
break;
case COLUMN_PSPROCESSTTY:
break;
case COLUMN_PSPROCESSUSERNAME:
break;
case COLUMN_PSPROCESSUSERID:
sizeof (long_type));
break;
case COLUMN_PSPROCESSNAME:
break;
case COLUMN_PSPROCESSSTATUS:
sizeof (long_type));
break;
default:
/* We shouldn't get here */
"problem encountered in sunProcessTable_handler: unknown column\n");
}
break;
case MODE_SET_RESERVE1:
break;
case MODE_SET_RESERVE2:
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
/* set handling... */
/* XXX don't know about 64 bit */
}
break;
case MODE_SET_COMMIT:
break;
case MODE_SET_UNDO:
break;
default:
"problem encountered in sunProcessTable_handler: unsupported mode\n");
}
}
return (SNMP_ERR_NOERROR);
}