#include <assert.h>
#include <libintl.h>
#include <strings.h>
#include "ns_sldap.h"
#include "ns_internal.h"
ns_standalone_conf_t standaloneDefaults =
{ {NULL,
0,
NULL,
"default",
NULL,
NULL,
NSLDAPDIRECTORY,
NULL,
NULL},
NS_CACHEMGR};
int
separatePort(char *peer, char **name, uint16_t *port)
{
char *chr, *portStr = NULL;
chr = strchr(peer, '[');
if (chr != NULL) {
*name = chr + 1;
chr = strchr(peer, ']');
if (chr == NULL) {
(void) fprintf(stderr,
gettext("Server address is wrong: "
"unbalanced [\n"));
return (1);
}
*chr++ = '\0';
chr = strchr(chr, ':');
if (chr != NULL && *(chr + 1) != '\0') {
portStr = chr + 1;
}
} else {
chr = strchr(peer, ']');
if (chr != NULL) {
(void) fprintf(stderr,
gettext("Server address is wrong: "
"unbalanced ]\n"));
return (1);
}
chr = strchr(peer, ':');
if (chr != NULL && *(chr + 1) != '\0') {
*chr++ = '\0';
portStr = chr;
}
*name = peer;
}
if ((*name)[0] == '\0') {
(void) fprintf(stderr,
gettext("Server address or name must be"
" specified.\n"));
return (1);
}
if (portStr && sscanf(portStr, "%hu", port) != 1) {
(void) fprintf(stderr,
gettext("Server port is wrong. "
"The default port 389/636 "
"will be used.\n"));
}
return (0);
}
char *
readPwd(char *pwd_file)
{
FILE *f;
char *pwd;
char passwdBuf[BUFSIZE];
if ((f = fopen(pwd_file, "r")) == NULL) {
(void) fprintf(stderr,
gettext("Unable to open '%s' file\n"), pwd_file);
return (NULL);
}
if (fgets(passwdBuf, BUFSIZE, f) == NULL) {
(void) fprintf(stderr,
gettext("Unable to read '%s' file\n"), pwd_file);
(void) fclose(f);
return (NULL);
}
(void) fclose(f);
if (passwdBuf[strlen(passwdBuf) - 1] == '\n') {
passwdBuf[strlen(passwdBuf) - 1] = '\0';
}
if ((pwd = strdup(passwdBuf)) == NULL) {
(void) fprintf(stderr,
gettext("Memory allocation error\n"));
return (NULL);
}
return (pwd);
}