static obj_ptr _map_find(obj_ptr args, obj_ptr env) { int ct = _length(args); obj_ptr map, key, res; if (ct < 2 || ct > 3) return MKERROR_STRING(MKSTRING("Syntax: (map-find map key [default])")); map = CAR(args); if (NMAPP(map)) return MKERROR(MKSTRING("Expected a map in first arg to map-find"), map); key = CADR(args); res = map_find(&MAP(map), key); if (!res) { if (ct == 3) return CADDR(args); else return MKERROR(MKSTRING("Key not found."), key); } return res; }
static obj_ptr _mod(obj_ptr arg1, obj_ptr arg2, obj_ptr env) { if (NINTP(arg1)) return MKERROR(MKSTRING("Expected an integer first argument in %"), arg1); if (NINTP(arg2)) return MKERROR(MKSTRING("Expected an integer second argument in %"), arg2); return MKINT(INT(arg1) % INT(arg2)); }
static obj_ptr _cdr(obj_ptr arg, obj_ptr env) { if (NCONSP(arg)) return MKERROR(MKSTRING("Expected a pair in cdr"), arg); return CDR(arg); }
static obj_ptr _map_size(obj_ptr arg, obj_ptr env) { if (NMAPP(arg)) return MKERROR(MKSTRING("Expected a map in map-clear"), arg); return MKINT(map_size(&MAP(arg))); }
static obj_ptr _add(obj_ptr args, obj_ptr env) { obj_ptr res = MKINT(0); for (; CONSP(args); args = CDR(args)) { obj_ptr arg = CAR(args); if (INTP(arg)) { if (FLOATP(res)) FLOAT(res) += (double)INT(arg); else INT(res) += INT(arg); } else if (FLOATP(arg)) { if (INTP(res)) { int n = INT(res); res->type = TYPE_FLOAT; FLOAT(res) = (double)n; } FLOAT(res) += FLOAT(arg); } else { res = MKERROR(MKSTRING("Expected a number in +"), arg); break; } } return res; }
static obj_ptr _map_delete(obj_ptr arg1, obj_ptr arg2, obj_ptr env) { if (NMAPP(arg1)) return MKERROR(MKSTRING("Expected a map in map-delete"), arg1); return MKBOOL(map_delete(&MAP(arg1), arg2)); }
static obj_ptr _load(obj_ptr arg, obj_ptr env) { if (NSTRINGP(arg)) return MKERROR(MKSTRING("Expected a string argument in (load ...)"), arg); return _load_imp(CPTR(arg), env); }
static obj_ptr _vec_length(obj_ptr arg, obj_ptr env) { if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-length"), arg); return MKINT(vec_length(&VEC(arg))); }
static obj_ptr _vec_clear(obj_ptr arg, obj_ptr env) { if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-clear"), arg); vec_clear(&VEC(arg)); return NIL; }
static obj_ptr _decrement(obj_ptr arg, obj_ptr env) { if (INTP(arg)) return MKINT(INT(arg) - 1); if (FLOATP(arg)) return MKFLOAT(FLOAT(arg) - 1.0); return MKERROR(MKSTRING("Expected a number in --"), arg); }
static obj_ptr _map_clear(obj_ptr arg, obj_ptr env) { if (NMAPP(arg)) return MKERROR(MKSTRING("Expected a map in map-clear"), arg); map_clear(&MAP(arg)); return NIL; }
static obj_ptr _map_add(obj_ptr arg1, obj_ptr arg2, obj_ptr arg3, obj_ptr env) { if (NMAPP(arg1)) return MKERROR(MKSTRING("Expected a map in map-add"), arg1); map_add(&MAP(arg1), arg2, arg3); return NIL; }
static obj_ptr _vec_get(obj_ptr arg1, obj_ptr arg2, obj_ptr env) { vec_ptr v; int n; if (NVECP(arg1)) return MKERROR(MKSTRING("Expected a vector for the first arg in vec-get"), arg1); if (NINTP(arg2)) return MKERROR(MKSTRING("Expected an integer for the second arg in vec-get"), arg2); v = &VEC(arg1); n = INT(arg2); if (n < 0 || n >= vec_length(v)) return MKERROR(MKSTRING("Index out of bounds in vec-get"), arg2); return vec_get(v, n); }
static obj_ptr _vec_add(obj_ptr args, obj_ptr env) { obj_ptr arg = CAR(args); if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-add"), arg); _vec_add_imp(&VEC(arg), CDR(args), env); return NIL; }
static obj_ptr _sub(obj_ptr args, obj_ptr env) { obj_ptr res = MKINT(0); int ct = 0; for (; CONSP(args); args = CDR(args)) { obj_ptr arg = CAR(args); ct++; if (NINTP(arg) && NFLOATP(arg)) { res = MKERROR(MKSTRING("Expected a number in -"), arg); return res; } else if (ct == 1) { if (INTP(arg)) INT(res) = INT(arg); else { res->type = TYPE_FLOAT; FLOAT(res) = FLOAT(arg); } } else if (INTP(arg)) { if (FLOATP(res)) FLOAT(res) -= (double)INT(arg); else INT(res) -= INT(arg); } else if (FLOATP(arg)) { if (INTP(res)) { int n = INT(res); res->type = TYPE_FLOAT; FLOAT(res) = (double)n; } FLOAT(res) -= FLOAT(arg); } } if (ct == 1) { if (INTP(res)) INT(res) *= -1; else FLOAT(res) *= -1; } return res; }
ns_ldap_error_t * __ns_ldap_LoadConfiguration() { ns_ldap_error_t *error = NULL; ns_config_t *ptr = NULL; char errstr[MAXERROR]; ns_parse_status ret; ptr = __s_api_create_config(); if (ptr == NULL) { (void) snprintf(errstr, sizeof (errstr), gettext("__ns_ldap_LoadConfiguration: Out of memory.")); MKERROR(LOG_ERR, error, NS_CONFIG_NOTLOADED, strdup(errstr), NULL); return (error); } /* Load in Configuration file */ ret = read_file(ptr, 0, &error); if (ret != NS_SUCCESS) { __s_api_destroy_config(ptr); return (error); } /* Load in Credential file */ ret = read_file(ptr, 1, &error); if (ret != NS_SUCCESS) { __s_api_destroy_config(ptr); return (error); } if (__s_api_crosscheck(ptr, errstr, B_TRUE) != NS_SUCCESS) { __s_api_destroy_config(ptr); MKERROR(LOG_ERR, error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); return (error); } __s_api_init_config(ptr); return (NULL); }
static obj_ptr _floor(obj_ptr arg, obj_ptr env) { if (INTP(arg)) return arg; if (FLOATP(arg)) { int x = (int)FLOAT(arg); return MKINT(x); } return MKERROR(MKSTRING("Expected a number in floor"), arg); }
static obj_ptr _map_keys(obj_ptr arg, obj_ptr env) { obj_ptr res = NIL; map_iter_t i; map_node_ptr n; if (NMAPP(arg)) return MKERROR(MKSTRING("Expected a map in map-keys"), arg); i = map_get_iter(&MAP(arg)); for (n = map_next(&i); n; n = map_next(&i)) res = CONS(n->key, res); return res; }
static obj_ptr _div(obj_ptr args, obj_ptr env) { obj_ptr res = MKFLOAT(0); int ct = 0; for (; CONSP(args); args = CDR(args)) { obj_ptr arg = CAR(args); ct++; if (NINTP(arg) && NFLOATP(arg)) { res = MKERROR(MKSTRING("Expected a number in /"), arg); return res; } else if (ct == 1) { if (INTP(arg)) FLOAT(res) = (double)INT(arg); else FLOAT(res) = FLOAT(arg); } else if (INTP(arg)) { FLOAT(res) /= (double)INT(arg); } else if (FLOATP(arg)) { FLOAT(res) /= FLOAT(arg); } } if (ct == 1) { FLOAT(res) = 1 / FLOAT(res); } return res; }
static ns_ldap_return_code set_attr(ns_config_t *config_struct, char *attr_name, char *attr_val, ns_ldap_error_t **errorp) { ParamIndexType idx; char errmsg[MAXERROR]; if (errorp == NULL) { return (NS_LDAP_INVALID_PARAM); } *errorp = NULL; /* * This double call is made due to the presence of * two sets of LDAP config. attribute names. * An LDAP configuration can be obtained either from a server * or from SMF. The former sends a DUA with attributes' names * styled like "preferredServerList". But local configurations * will have names inherited from the /var/ldap/ldap* files such as * "NS_LDAP_SERVER_PREF". * So, the standalone bits are able to process both sets of * attributes' names. */ if (__s_api_get_profiletype(attr_name, &idx) < 0 && __s_api_get_versiontype(config_struct, attr_name, &idx) < 0) { (void) snprintf(errmsg, sizeof (errmsg), gettext("Illegal DUAProfile property: <%s>."), attr_name); MKERROR(LOG_ERR, *errorp, NS_LDAP_CONFIG, strdup(errmsg), NULL); return (NS_LDAP_CONFIG); } return (__ns_ldap_setParamValue(config_struct, idx, attr_val, errorp)); }
static ns_parse_status read_file(ns_config_t *ptr, int cred_file, ns_ldap_error_t **error) { ParamIndexType i = 0; char errstr[MAXERROR]; char buffer[BUFSIZE], *name, *value; int emptyfile, lineno; FILE *fp; int ret; int linelen; char *file; int first = 1; if (cred_file) { file = NSCREDFILE; } else { file = NSCONFIGFILE; } fp = fopen(file, "rF"); if (fp == NULL) { (void) snprintf(errstr, sizeof (errstr), gettext("Unable to open filename '%s' " "for reading (errno=%d)."), file, errno); MKERROR(LOG_ERR, *error, NS_CONFIG_FILE, strdup(errstr), NULL); return (NS_NOTFOUND); } emptyfile = 1; lineno = 0; for (; ; ) { if ((linelen = read_line(fp, buffer, sizeof (buffer), errstr)) < 0) /* End of file */ break; lineno++; if (linelen == 0) continue; /* get rid of comment lines */ if (buffer[0] == '#') continue; emptyfile = 0; name = NULL; value = NULL; __s_api_split_key_value(buffer, &name, &value); if (name == NULL || value == NULL) { (void) snprintf(errstr, sizeof (errstr), gettext("Missing Name or Value on line %d."), lineno); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); (void) fclose(fp); return (NS_PARSE_ERR); } if (__s_api_get_versiontype(ptr, name, &i) != 0) { (void) snprintf(errstr, sizeof (errstr), gettext("Illegal profile type on line %d."), lineno); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); (void) fclose(fp); return (NS_PARSE_ERR); } if (!first && i == NS_LDAP_FILE_VERSION_P) { (void) snprintf(errstr, sizeof (errstr), gettext("Illegal NS_LDAP_FILE_VERSION " "on line %d."), lineno); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); (void) fclose(fp); return (NS_PARSE_ERR); } first = 0; switch (__s_api_get_configtype(i)) { case SERVERCONFIG: case CLIENTCONFIG: if (cred_file == 0) { ret = __ns_ldap_setParamValue(ptr, i, value, error); if (ret != NS_SUCCESS) { (void) fclose(fp); return (ret); } } else if (i != NS_LDAP_FILE_VERSION_P) { (void) snprintf(errstr, sizeof (errstr), gettext("Illegal entry in '%s' on " "line %d"), file, lineno); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); (void) fclose(fp); return (NS_PARSE_ERR); } break; case CREDCONFIG: if (i == NS_LDAP_FILE_VERSION_P) break; if (cred_file) { ret = __ns_ldap_setParamValue(ptr, i, value, error); if (ret != NS_SUCCESS) { (void) fclose(fp); return (ret); } } else { (void) snprintf(errstr, sizeof (errstr), gettext("Illegal entry in '%s' on " "line %d"), file, lineno); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); (void) fclose(fp); return (NS_PARSE_ERR); } } } (void) fclose(fp); if (!cred_file && emptyfile) { /* Error in read_line */ (void) snprintf(errstr, sizeof (errstr), gettext("Empty config file: '%s'"), file); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); return (NS_PARSE_ERR); } if (linelen == -2) { /* Error in read_line */ (void) snprintf(errstr, sizeof (errstr), gettext("Line too long in '%s'"), file); MKERROR(LOG_ERR, *error, NS_CONFIG_SYNTAX, strdup(errstr), NULL); return (NS_PARSE_ERR); } return (NS_SUCCESS); }
/* * This function creates a configuration which will be used * for all LDAP requests in the Standalone mode. * * INPUT: * config - a buffer returned by __ns_ldap_getConnectionInfo()'s * dua_profile parameter. * */ ns_config_t * __s_api_create_config_door_str(char *config, ns_ldap_error_t **errorp) { char *attr, *attrName, *attrVal, *rest; ns_config_t *configStruct = NULL; char errmsg[MAXERROR]; if (config == NULL || errorp == NULL) return (NULL); if ((configStruct = __s_api_create_config()) == NULL) { return (NULL); } *errorp = NULL; attr = strtok_r(config, DOORLINESEP, &rest); if (!attr) { __s_api_destroy_config(configStruct); (void) snprintf(errmsg, sizeof (errmsg), gettext("DUAProfile received from the server" " has bad format")); MKERROR(LOG_ERR, *errorp, NS_LDAP_CONFIG, strdup(errmsg), NULL); return (NULL); } do { __s_api_split_key_value(attr, &attrName, &attrVal); if (attrName == NULL || attrVal == NULL) { __s_api_destroy_config(configStruct); (void) snprintf(errmsg, sizeof (errmsg), gettext("Attribute %s is not valid"), attr); MKERROR(LOG_ERR, *errorp, NS_LDAP_CONFIG, strdup(errmsg), NULL); return (NULL); } /* Get the version of the profile. */ if (strcasecmp(attrName, "objectclass") == 0) { if (strcasecmp(attrVal, _PROFILE2_OBJECTCLASS) == 0) { if (__ns_ldap_setParamValue(configStruct, NS_LDAP_FILE_VERSION_P, NS_LDAP_VERSION_2, errorp) != NS_LDAP_SUCCESS) { __s_api_destroy_config(configStruct); return (NULL); } } else if (strcasecmp(attrVal, _PROFILE1_OBJECTCLASS) == 0) { if (__ns_ldap_setParamValue(configStruct, NS_LDAP_FILE_VERSION_P, NS_LDAP_VERSION_1, errorp) != NS_LDAP_SUCCESS) { __s_api_destroy_config(configStruct); return (NULL); } } continue; } if (set_attr(configStruct, attrName, attrVal, errorp) != NS_LDAP_SUCCESS) { __s_api_destroy_config(configStruct); return (NULL); } } while (attr = strtok_r(NULL, DOORLINESEP, &rest)); if (__s_api_crosscheck(configStruct, errmsg, B_FALSE) != NS_SUCCESS) { MKERROR(LOG_ERR, *errorp, NS_LDAP_CONFIG, strdup(errmsg), NULL); __s_api_destroy_config(configStruct); return (NULL); } return (configStruct); }
int __ns_ldap_getSearchDescriptors( const char *service, ns_ldap_search_desc_t ***desc, ns_ldap_error_t **errorp) { int rc; int slen; void **param = NULL; void **paramVal = NULL; char **sdl, *srv, **sdl_save; char errstr[2 * MAXERROR]; ns_ldap_search_desc_t **sdlist; int cnt, max; int vers; ns_config_t *cfg; ns_ldap_search_desc_t *ret; if ((desc == NULL) || (errorp == NULL)) return (NS_LDAP_INVALID_PARAM); *desc = NULL; *errorp = NULL; rc = __ns_ldap_getParam(NS_LDAP_SERVICE_SEARCH_DESC_P, (void ***)¶m, errorp); if (rc != NS_LDAP_SUCCESS) { return (rc); } sdl = (char **)param; cnt = 0; max = 0; sdlist = NULL; cfg = __s_api_get_default_config(); if (cfg == NULL) { (void) snprintf(errstr, sizeof (errstr), gettext("No configuration information available.")); MKERROR(LOG_ERR, *errorp, NS_CONFIG_NOTLOADED, strdup(errstr), NULL); return (NS_LDAP_CONFIG); } vers = cfg->version; __s_api_release_config(cfg); /* If using version1 or no sd's process SEARCH_DN if available */ if (vers == NS_LDAP_V1 && param == NULL) { rc = __s_api_get_search_DNs_v1(&sdl, service, errorp); if (rc != NS_LDAP_SUCCESS || sdl == NULL) { return (rc); } sdl_save = sdl; /* Convert a SEARCH_DN to a search descriptor */ for (; *sdl; sdl++) { ret = (ns_ldap_search_desc_t *) calloc(1, sizeof (ns_ldap_search_desc_t)); if (ret == NULL) { (void) __ns_ldap_freeSearchDescriptors(&sdlist); __s_api_free2dArray(sdl_save); return (NS_LDAP_MEMORY); } ret->basedn = strdup(*sdl); if (ret->basedn == NULL) { free(ret); (void) __ns_ldap_freeASearchDesc(ret); (void) __ns_ldap_freeSearchDescriptors(&sdlist); __s_api_free2dArray(sdl_save); return (NS_LDAP_MEMORY); } /* default scope */ if ((rc = __ns_ldap_getParam(NS_LDAP_SEARCH_SCOPE_P, ¶mVal, errorp)) != NS_LDAP_SUCCESS) { (void) __ns_ldap_freeASearchDesc(ret); (void) __ns_ldap_freeSearchDescriptors(&sdlist); __s_api_free2dArray(sdl_save); return (rc); } if (paramVal && *paramVal) ret->scope = * (ScopeType_t *)(*paramVal); else ret->scope = NS_LDAP_SCOPE_ONELEVEL; (void) __ns_ldap_freeParam(¶mVal); paramVal = NULL; rc = __ns_ldap_saveSearchDesc(&sdlist, &cnt, &max, ret); if (rc < 0) { (void) __ns_ldap_freeASearchDesc(ret); (void) __ns_ldap_freeSearchDescriptors(&sdlist); __s_api_free2dArray(sdl_save); return (NS_LDAP_MEMORY); } } __s_api_free2dArray(sdl_save); *desc = sdlist; return (NS_LDAP_SUCCESS); } if (sdl == NULL || service == NULL) { (void) __ns_ldap_freeParam(¶m); param = NULL; *desc = NULL; return (NS_LDAP_SUCCESS); } slen = strlen(service); /* Process the version2 sd's */ for (; *sdl; sdl++) { srv = *sdl; if (strncasecmp(service, srv, slen) != 0) continue; srv += slen; if (*srv != COLONTOK) continue; srv++; while (srv != NULL && *srv != NULL) { /* Process 1 */ rc = __s_api_parseASearchDesc(service, &srv, &ret); if (rc != NS_LDAP_SUCCESS) { (void) __ns_ldap_freeSearchDescriptors(&sdlist); (void) snprintf(errstr, (2 * MAXERROR), gettext( "Invalid serviceSearchDescriptor (%s). " "Illegal configuration"), *sdl); (void) __ns_ldap_freeParam(¶m); param = NULL; MKERROR(LOG_ERR, *errorp, NS_CONFIG_SYNTAX, strdup(errstr), NULL); return (rc); } if (ret != NULL) { rc = __ns_ldap_saveSearchDesc( &sdlist, &cnt, &max, ret); } if (rc < 0) { (void) __ns_ldap_freeSearchDescriptors(&sdlist); (void) __ns_ldap_freeParam(¶m); param = NULL; return (NS_LDAP_MEMORY); } } } (void) __ns_ldap_freeParam(¶m); param = NULL; *desc = sdlist; return (NS_LDAP_SUCCESS); }