nis_servlist.c revision a506a34ceb0e9dcc6c61bf0560202f8538928650
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <malloc.h>
#include <strings.h>
#include "nis_servlist.h"
#include "nisdb_rw.h"
#ifdef MEM_DEBUG
#ifdef __STDC__
extern void xfree(void *);
extern char *xstrdup(char *);
extern char *xmalloc(int);
extern char *xcalloc(int, int);
#else /* __STDC__ */
extern void xfree();
extern char *xstrdup();
extern char *xmalloc();
extern char *xcalloc();
#endif /* __STDC__ */
#else /* MEM_DEBUG */
#endif /* MEM_DEBUG */
extern char *nis_data(char *s);
/* Imported from rpc.nisd/nis_subr_proc.c */
/*
* This is a link list of all the directories served by this server.
*/
struct nis_dir_list {
char *name;
struct nis_dir_list *next;
};
/* this function must be protected by dirlist */
static int init_dir_list(const char *filename)
{
struct nis_dir_list *tmp;
/* initialize only once */
if (dir_init)
return (1);
/* The server is just starting out */
return (-1);
}
name++;
end++;
/* Should never really happen */
return (0);
}
/* Should never really happen */
return (0);
}
dirlisthead = tmp;
}
return (1);
}
/*
* nis_server_control() controls various aspects of server administration.
*/
int
enum NIS_SERVER_INFO infotype;
enum NIS_SERVER_OP op;
void *argp;
{
int ss;
char oldval;
char *dirs;
int i;
int ret;
switch (infotype) {
case SERVING_LIST:
/*
* The file "serving_list" contains one directory name per
* line.
*/
switch (op) {
case DIR_ADD:
(void) init_dir_list(filename);
/* Check whether I already serve this directory? */
return (1);
}
}
"could not open file %s for updating",
filename);
return (0);
}
}
/* Add it to the incore copy */
/* Should never really happen */
return (0);
}
/* Should never really happen */
return (0);
}
dirlisthead = tmp;
/* Add it to the file */
name++;
end++;
/* already exists */
return (1);
}
}
return (1);
case DIR_DELETE:
(void) init_dir_list(filename);
prev = dirlisthead;
if (tmp == dirlisthead)
else
break;
}
}
/* It wasnt found, so return success */
return (1);
}
"could not open file %s for reading",
filename);
return (0);
}
"could not open file %s for updating",
tmpname);
return (0);
}
name++;
end++;
continue; /* skip this one */
}
}
return (1);
case DIR_INITLIST:
return (ret);
case DIR_GETLIST:
/* don't acquire write lock unless not inited */
if (!dir_init) {
(void) init_dir_list(filename);
}
i = 0;
}
if (i == 0)
i = 1;
return (0);
}
dirs[0] = '\0';
if (*dirs != '\0')
}
return (1);
case DIR_SERVED: /* Do I serve this directory */
/* don't acquire write lock unless not inited */
if (!dir_init) {
(void) init_dir_list(filename);
}
return (1);
}
return (0);
default:
return (0);
}
default:
return (0);
}
}
/*
* nis_isserving()
*
* This function returns state indicating whether or not we serve the
* indicated directory.
* 0 = we don't serve it
* n = which server we are (1 == master)
*/
int
{
int ns, i; /* number of servers */
return (0);
/*
* POLICY : Should host names be compared in a case independent
* mode?
* ANSWER : Yes, to support the semantics of DNS and existing
* software which assume hostnames are case insensitive.
*/
return (1);
/* Not master, check to see if we serve as a replica */
for (i = 1; i < ns; i++) {
return (i+1);
}
return (0);
}