int main(int argc,char *argv[]) { int sockfd; enum mode mode; if(argc != 3) usage(); syslog(LOG_INFO, "Eddie: %s %s %s", argv[0], argv[1], argv[2]); check_rights(argv[0]); if(strcmp(argv[1],"ip") == 0) mode=IP; else if(strcmp(argv[1],"if") == 0) mode=IF; else if(strcmp(argv[1],"hw") == 0) mode=HW; else usage(); if((sockfd=socket(AF_INET,SOCK_DGRAM,0)) == -1) error(2,"ifget: Bad socket"); ifget(sockfd, mode, argv[2]); return(0); }
/* * Function: create_default_fdisk_partition * * Parameters: op - CCIMObjectPath pointer that points to the object path * of the device to fdisk. * * Returns: Returns a CCIMProperty pointer. The CCIMProperty referenced * by the pointer will contain an mValue of cim_true for * success or cim_false on failure. * * Description: Executes the fdisk command on the device pointed to my 'op' * with the -B parameter. * * Notes: The calling program is responsible for releasing the memory * used by the returned CCIMProperty. */ CCIMProperty * create_default_fdisk_partition(CCIMObjectPath *op) { char devpath[MAXPATHLEN]; char err_file[L_tmpnam]; char command_line[CMDLEN]; int len; int error; /* This function is called from Solaris_DiskDrive, not Solaris_Disk. */ if (!check_rights("Solaris_DiskDrive") || op == NULL) { return (create_result(PROPFALSE)); } if (get_devpath(op, devpath, sizeof (devpath)) == cim_false) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, CIM_ERR_FAILED, NULL, &error); return (create_result(PROPFALSE)); } make_fdisk_path(devpath); (void) tmpnam(err_file); /* * Build the fdisk command line. Some combinations of * parameters can cause fdisk to output a message and wait * for a y/n response, echo'ing an 'n' and piping it to * fdisk solves this problem. * * Using the form of fdisk (-F) that takes partition information * from a disk file so that multiple partitions can be created * by one request. */ len = snprintf(command_line, sizeof (command_line), "echo n | /usr/sbin/fdisk -B %s 2> %s", devpath, err_file); if (len < 0 || (len + 1) > sizeof (command_line)) { util_handleError(INVOKE_METHOD, CIM_ERR_FAILED, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Execute the command. */ if (!execute_cmd(command_line, err_file)) { return (create_result(PROPFALSE)); } return (create_result(PROPTRUE)); }
int main(int argc,char *argv[]) { char *interface; char *pif; char *alias; char *ip; if(argc != 4) { fprintf(stderr,"Usage: routeadd interface alias ip-address\n"); exit(2); } syslog(LOG_INFO, "Eddie: %s %s %s %s", argv[0], argv[1], argv[2], argv[3]); check_rights(argv[0]); pif = argv[1]; alias = argv[2]; ip = argv[3]; #if defined(LINUX) if((interface=(char *)malloc(strlen(pif)+strlen(alias)+2)) == NULL) { fprintf(stderr,"routeadd: Out of memory"); exit(2); } strcpy(interface,pif); strcat(interface,":"); strcat(interface,alias); /* This stinks! It should be done using ioctl calls. */ if(execl(ROUTE,ROUTE,"add","-host",ip,interface,NULL) == -1) { perror("routeadd"); exit(2); } free(interface); #elif defined(BSD) /* freebsd does not need a route added */ #elif defined(SOLARIS) /* solaris does not need a route added */ #elif # error "routeadd action not defined" #endif return(0); }
/* * Function: writeVolumeName * * Parameters: params - CCIMPropertyList pointer. Property list * containing the new disk label name. * op - CCIMObjectPath pointer. Object path containing * the deviceId of the disk to label. * * Returns: Returns a CCIMProperty pointer. The CCIMProperty referenced * by the pointer will contain an mValue of cim_true for * success or cim_false on failure. * * Description: Executes the fmthard -n volume_name command on the device * pointed to by 'op'. */ CCIMProperty * label_disk(CCIMPropertyList *params, CCIMObjectPath *op) { char devpath[MAXPATHLEN]; char command_line[CMDLEN]; int len; cimchar *label; int error; if (!check_rights("Solaris_Disk") || op == NULL || params == NULL) { return (create_result(PROPFALSE)); } if (get_devpath(op, devpath, sizeof (devpath)) == cim_false) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Extract the label from the input parameters */ if ((label = get_prop_val(params->mDataObject)) == NULL) { return (create_result(PROPFALSE)); } if (strlen(label) > 8) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Build the command line to execute */ len = snprintf(command_line, sizeof (command_line), "/usr/sbin/fmthard -n '%s' %s 2> /dev/null", label, devpath); if (len < 0 || (len + 1) > sizeof (command_line)) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Execute the command. */ if (!execute_cmd(command_line, "/dev/null")) { return (create_result(PROPFALSE)); } return (create_result(PROPTRUE)); }
CCIMProperty * create_partitions(CCIMPropertyList *params, CCIMObjectPath *op) { char devpath[MAXPATHLEN]; char fmt_file[L_tmpnam]; char command_line[CMDLEN]; int len; int error; if (!check_rights("Solaris_Disk") || op == NULL || params == NULL) { return (create_result(PROPFALSE)); } if (get_devpath(op, devpath, sizeof (devpath)) == cim_false) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Create a format data file to be used by the fmthard command. */ if (build_fmt_file(fmt_file, params) == cim_false) { /* last error is set in build_fmt_file function */ util_removeFile(fmt_file); return (create_result(PROPFALSE)); } /* Create 'fmthard' command line */ len = snprintf(command_line, sizeof (command_line), "/usr/sbin/fmthard -s %s %s 2> /dev/null", fmt_file, devpath); if (len < 0 || (len + 1) > sizeof (command_line)) { util_handleError(INVOKE_METHOD, CIM_ERR_FAILED, CIM_ERR_FAILED, NULL, &error); util_removeFile(fmt_file); return (create_result(PROPFALSE)); } /* Execute the command. */ if (!execute_cmd(command_line, "/dev/null")) { util_removeFile(fmt_file); return (create_result(PROPFALSE)); } util_removeFile(fmt_file); return (create_result(PROPTRUE)); }
CCIMProperty * create_filesystem(CCIMObjectPath *op) { char devpath[MAXPATHLEN]; char command_line[CMDLEN]; int len; int error; /* check to make sure caller has admin write rights */ if (!check_rights("Solaris_DiskPartition")) { return (create_result(PROPFALSE)); } if (get_devpath(op, devpath, sizeof (devpath)) == cim_false) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Create 'newfs' command line */ len = snprintf(command_line, sizeof (command_line), "echo y | /usr/sbin/newfs %s 2>/dev/null", devpath); if (len < 0 || (len + 1) > sizeof (command_line)) { util_handleError(INVOKE_METHOD, CIM_ERR_FAILED, CIM_ERR_FAILED, NULL, &error); return (create_result(PROPFALSE)); } /* Execute the command. */ if (!execute_cmd(command_line, "/dev/null")) { return (create_result(PROPFALSE)); } return (create_result(PROPTRUE)); }