/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
/*
* setuname [-t] [-s name] [-n node]
*/
/*
* Header files referenced:
* <stdio.h> Standard I/O
* <unistd.h> Standard UNIX definitions
* <string.h> String handling
* <fmtmsg.h> Standard message generation
* <ctype.h> Character types
* <errno.h> Error handling
* <signal.h> Signal handling
* <nlist.h> Definitions for Sun symbol table entries
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fmtmsg.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#endif
#if sun
#include <nlist.h>
#include <kvm.h>
#endif
/*
* Externals referenced (and not defined in a header)
* optind index to the next arg for getopt()
* opterr FLAG, TRUE tells getopt() to write messages
* optarg Ptr to an option's argument
* getopt() Gets an option from the command line
* putenv() Writes values into the environment
* exit() Exit the process
* access() Check accessibility of a file
* malloc() Allocate a block of main memory
* free() Free allocated space
* lseek() Seek within a file
* open() Open a file
* close() Close an open file
*/
extern int optind; /* argv[] index of next arg */
extern int opterr; /* TRUE if getopt() is to print msgs */
extern char *optarg; /* Argument to parsed option */
extern int getopt(); /* Get an option from the command line */
extern int putenv(); /* Put a value into the environment */
extern void exit(); /* Exit the process */
extern int access(); /* Check the accessibility of a file */
extern void *malloc(); /* Get a chunk of main memory */
extern void free(); /* Free alloc'd space */
extern long lseek(); /* Seek within a file */
extern int open(); /* Open a file */
extern int close(); /* Close an open a file */
/*
* L O C A L D E F I N I T I O N S
*/
/*
* Constants
*/
#ifndef TRUE
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef NULL
#define NULL (0)
#endif
#define EX_OK 0
/*
* Messages
*/
/*
* Macros:
* stdmsg(r,l,s,t) Write a standard message.
* 'r' is the recoverability flag
* 'l' is the label
* 's' is the severity
* 't' is the text.
* strend(p) Return the address of the end of a string
* but that file has string-handing def'ns that
* conflict with <string.h>, so we can't use it!
* MR dn89-04701 requests this fix.
*/
/*
* Local functions:
* setuname Changes the system name and the network node name
*/
static int setuname(); /* This does the "real" work */
/*
* Local data
* lbl Buffer for the standard message label
* txt Buffer for the standard message text
*/
/*
* int main(argc, argv)
* int argc
* char *argv;
*/
int
int argc; /* Argument count */
char *argv[]; /* Argument vector */
{
/* Automatic data */
char *p; /* Temp pointer */
int c; /* Temp character */
/* Build the standard-message label */
/* Make only the text in standard messages appear (SVR4.0 only) */
(void) putenv("MSGVERB=text");
/* Initializations */
/*
* Parse command
*/
case 'n': /* -n node */
break;
case 's': /* -s name */
break;
case 't': /* -t */
break;
default: /* Something that doesn't exist */
} /* switch() */
/* If there was a usage error, report the error and exit */
}
/* Either -n <node> or -s <name> has to be specified */
}
/*
* Validate arguments:
* - The length of the system name must be less than SYS_NMLN-1
* characters,
* - The length of the network node-name must be less than
* SYS_NMLN-1 characters,
* - The system name must equal [a-zA-Z0-9-_]+,
* - The network node-name must equal [a-zA-Z0-9-_]+.
*/
/* Check the length and the character-set of the system name */
if (s_arg) {
/* Check length of the system name */
}
/* Check the character-set */
}
}
}
/* Check the length and the character-set of the network node-name */
if (n_arg) {
/* Check length of the network node-name */
}
/* Check the character-set */
}
}
}
/*
* Make sure we have access to needed resources:
* - If -t is not specified, read access to /etc/rc2.d/S18setuname
*/
}
}
else {
}
else {
}
}
}
else {
}
/* Attempt the setuname */
else {
}
/* Finished */
return (exitcode);
} /* main() */
/*
* int setuname(temp, name, node)
* int temp
* char *name
* char *node
*
* Set any or all of the following machine parameters, either
* temporarily or permanently, depending on <temp>.
* - System name
* - Network Node-name
*/
static int
int temp; /* Set in kernel only flag */
char *sysname; /* System name */
char *nodename; /* Network node-name */
{
/* Automatic Data */
#endif
#if sun
{"utsname", 0, 0, 0, 0, 0},
{NULL}
};
#endif
char *p; /* Temp pointer */
void (*oldsighup)(); /* Function to call for SIGHUP */
void (*oldsigint)(); /* Function to call for SIGINT */
int i; /* Temp counter */
/* Nothing's gone wrong yet (but we've only just begun!) */
rtncd = 0;
/*
* Get the virtual address of the symbol "utsname" in the kernel
* directly in the kernel's memory space.
*/
p = (char *) symbtbl;
if (i >= 0) utsname_addr = S3BSVAL(p);
else rtncd = -1;
} else rtncd = -1;
/* Check out namelist and memory files. */
rtncd = -1;
rtncd = -1;
rtncd = -1;
else
#else
rtncd = -1;
#endif
/*
* Open the kernel's memory, get the existing "utsname" structure,
* write it back out to kernel memory, then close kernel memory.
*/
#ifdef sun
sizeof (utsname)) {
if (sysname)
if (nodename)
} else
return (-1);
#else /* sun */
} else rtncd = -1;
} else rtncd = -1;
#endif /* sun */
/*
* If the "temp" flag is FALSE, we need to permanently set the
* system name in the file /etc/rc2.d/S18setuname
*/
if (!temp) {
/*
* If a name was specified by the caller, use that, otherwise, use
* whatever was in the "rc" file.
*/
/*
* Write the file /etc/rc2.d/S18setuname so that the system name is
* set on boots and state changes.
*
* DISABLED SIGNALS: SIGHUP, SIGINT
*/
/* Give us a reasonable chance to complete without interruptions */
/* Write the new setuname "rc" file */
} else return(rtncd = -1);
}
int curlen;
for (i = 0; i < curlen; i++) {
if (curname[i] == '\n') {
curname[i] = '\0';
break;
}
}
if (i == curlen) {
}
} else {
curname[0] = '\0';
}
exit(1);
}
exit(1);
}
}
}
/* Restore signal handling */
} /* if (!temp) */
/* Fini */
return(rtncd);
}