res.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include "impl.h"
#include "error.h"
#include "trace.h"
#include "pdu.h"
#include "agent.h"
#include "subtree.h"
#include "session.h"
#include "res.h"
#include "dispatcher.h"
#include "snmprelay_msg.h"
#include <pwd.h>
#define MAX_RES_NAME 128
#define CLOCK_TICK 100
typedef struct _PidRec {
char res_name[MAX_RES_NAME];
char agent_name[MAX_RES_NAME];
int pid;
int port;
} PidRec;
/****************************************************************/
void mark_all_resources_not_visit()
{
}
void trace_resources()
{
trace("RESOURCES:\n");
{
trace("\t%Name: %s Dir: %s Personal: %s Sec: %s Policy: %s Type: %s Cmd: %s Agent: %s\n",
}
trace("\n");
}
{
{
{
break;
}
}
{
}
else
{
}
}
/****************************************************************/
/* We must invoke subtree_list_delete() before invoking */
/* this function because the first_agent_subtree member */
/* of the agent structures should be NULL */
void resource_list_delete()
{
while(ap)
{
}
return;
}
/****************************************************************/
{
{
return;
}
/* free the extra element */
return;
}
{
}
return NULL;
}
{
}
return NULL;
}
{
}
return NULL;
}
{
static char fullname[256];
static char dirname[256];
fullname[0]='\0';
dirname[0]='\0';
}
return(fullname);
}
/* if two string are NULL, we treat them as equal */
/* equal return 0, otherwise 1 */
{
return 0;
}
/* return TRUE same, otherwise FALSE */
/* s1 is the new one, s2 is old one */
{
/* res_name may be nil */
/* check the time stamp of the personal file */
/* hack, somehow didnt't initialize */
return TRUE;
/* same in name, personal_file, policy, start_cmd, type */
}
{
int fd;
*file_time = 0;
{
return;
}
/*
* get the size of the file
*/
{
return;
}
/* file time stamp */
}
/****************************************************************/
void resource_handle_child_signal()
{
}
int switch_to_user_id(char *user_name)
{
return TRUE;
}else{
return FALSE;
}
}
/*
* try to get a port, 5 times
*/
static int get_a_non_reserved_port()
{
struct sockaddr_in me;
int sd;
if(sd<0) return 0;
}
return 0;
}
/****************************************************************/
{
}
static int match_pattern_port(char* pat)
{
return FALSE;
}
{
static char cmd_full_path[256];
static char port_str[100];
static char sec_str[100];
static char per_str[100];
char *cmd ;
static char *cmd_arg[10];
int num_of_args =0;
cmd_full_path[0] = '\0';
port_str[0]='\0';
sec_str[0]='\0';
per_str[0]='\0';
else
for(i=path_len-1;i>=0 ;i--){
if(cmd_full_path[i] == '/') break;
}
exit(1);
}else if( pid == 0) {
/* always check for $PORT */
*eptr = '\0';
else
}
/* last argument */
else
}
{
}
/*setsid();*/
/* if the above function < 0, mark the agent dies */
exit(1);
}else{ /* parent */
return pid;
}
exit(1);
}
{
return NULL;
}
int res_agent_is_alive(char *res_name)
{
/* find the res_name in the pid_list, and send a get pdu to it */
/* assume community string is public,
* agent_address is localhost,
* timeout is 5 sec
*/
}
/******** Resource handling (5-28-96) *********/
void
{
/*
*scan the resource list
*if the policy is legacy then
*read the personal file for the subagent.
*spawn the subagent with the given command and the required argument
*/
char fullname[1024];
char dirname[1024];
char buf[1024];
int error_free, port_num;
/* read the config. file */
if (!rp->personal_file) {
return;
}
/*
* assume that the personal file containing only one
* subagent, then first_agent will point to the previous
* formed subagent
*/
dirname[0] = '\0';
/* init the res_name as the agentName */
buf[0] = '\0';
}
fullname[0] = '\0';
}
fullname[0] = '\0';
}
fullname[0] = '\0';
}
/*
* check the global flag recovery_on, to decide
* spawn or not, recovery flag should set then reset
*/
/*
* get the port if not exist
* and store it in rp and agent
*/
if (port_num == 0)
error("can't find a valid port"
"for the agent %s",
}
} else {
if (first_agent->agentPortNumber == 0) {
}
}
}
/* activate the agent, subtree, table */
}
if (first_agent == NULL) {
error_exit("No SNMP agent configured");
}
}
{
/*
* assume community string is public
*/
}
void trace_pid_rec()
{
trace("PID_REC:\n");
{
trace("\t%ResName: %s AgentName: %s Pid: %d Port: %d\n",
}
trace("\n");
}
void delete_pid_rec_list()
{
while(ap)
{
}
}
void read_pid_file(char *filename)
{
int res=4;
{
/* file not exist, ignore it
error(ERR_MSG_OPEN, filename, errno_string());
*/
return;
}
while(res ==4)
{
error("malloc() failed");
return;
}
if(res==4){
}else{
}
}else{
}
}
}
void
write_pid_file(char *filename)
{
char name[256];
error("can't open the file");
return;
}
/* write the tuple { resouce_name, agent_name, pid, port } */
continue;
continue;
} else {
}
name,
}
}
/*
* Add the port number and pid of relay agent to
*/
void
write_pid_file1(char *filename)
{
char name[256];
return;
error("can't save the pid file");
}
error("can't open the file");
return;
}
}
}
}
}
void merging_resource_list()
{
int port_num;
/* scan the reconfig list, find same name resource,
if found, see difference, */
while(sp){
/* exists before */
/* no need to reread the personal file */
/* spawn process ? */
{
/* get the port if not exist
* and store it in rp and agent */
}
}
}
}else{
/* new info for the agent */
}
}
}else{
/* non-exist resource */
}
if(merge_res_list==NULL){
}else{
}
merge_res_list = sp;
}
/* update the PID file */
}
{
{
}
{
}else{
}
}
{
return FALSE;
}
void watch_dog_in_action()
{
int port_num;
static int start_time=0;
static int end_time=0;
int time_diff;
if(any_outstanding_session()==TRUE) return;
if (trace_level > 0)
/* the agent was probably deleted by the timeout mechanism */
}
{
/* get the port if not exist
* and store it in rp and agent */
if(port_num==0)
}
if (trace_level > 0)
}
}
}
}
}
int already_bound_port(int port_num) {
int socket_handle;
struct sockaddr_in in_addr;
char errmsg[100];
if (socket_handle < 0) {
return 0;
}
return 1;
}else {
return 0;
}
}
void kill_all_pid_rec_list()
{
}
}
}
void kill_part_pid_rec_list()
{
}
}
}