MYLDAP_ENTRY *shadow_uid2entry(MYLDAP_SESSION *session, const char *username, int *rcp) { MYLDAP_SEARCH *search = NULL; MYLDAP_ENTRY *entry = NULL; const char *base; char filter[BUFLEN_FILTER]; int i; /* if it isn't a valid username, just bail out now */ if (!isvalidname(username)) { if (rcp != NULL) *rcp = LDAP_INVALID_SYNTAX; return NULL; } /* we have to look up the entry */ mkfilter_shadow_byname(username, filter, sizeof(filter)); for (i = 0; (i < NSS_LDAP_CONFIG_MAX_BASES) && ((base = shadow_bases[i]) != NULL); i++) { search = myldap_search(session, base, shadow_scope, filter, shadow_attrs, rcp); if (search == NULL) { if ((rcp != NULL) && (*rcp == LDAP_SUCCESS)) *rcp = LDAP_NO_SUCH_OBJECT; return NULL; } entry = myldap_get_entry(search, rcp); if (entry != NULL) return entry; } if ((rcp != NULL) && (*rcp == LDAP_SUCCESS)) *rcp = LDAP_NO_SUCH_OBJECT; return NULL; }
int IsVariableDefinition(const std::string &a_expression) { bool found = false; int index; for (int i = 0; i < a_expression.length(); i++) { if (a_expression[i] == ':') { if (!found) { found = true; index = i; } else throw ExpressionError("Invalid assignment", new Token); } } if (found) { // parse int name_end = index - 1; while (a_expression[name_end] == ' ' && name_end >= 0) name_end--; if (name_end < 0) throw ExpressionError("Invalid variable definition", new Token); last_variable_name = a_expression.substr(0, name_end + 1); if (!isvalidname(last_variable_name) || isallupper(last_variable_name, true)) return 0; int value_start = index + 1; while (a_expression[value_start] == ' ' && value_start < a_expression.length()) value_start++; if (value_start == a_expression.length()) { G::variables.Remove(HashFunc(last_variable_name)); return 2; } last_variable_value = a_expression.substr(value_start); return 1; } return 0; }
/* ensure that both userdn and username are filled in from the entry, returns an LDAP result code */ static MYLDAP_ENTRY *validate_user(MYLDAP_SESSION *session, char *username, int *rcp) { int rc; MYLDAP_ENTRY *entry = NULL; /* check username for validity */ if (!isvalidname(username)) { log_log(LOG_WARNING, "request denied by validnames option"); *rcp = LDAP_NO_SUCH_OBJECT; return NULL; } /* get the user entry based on the username */ entry = uid2entry(session, username, &rc); if (entry == NULL) { if (rc == LDAP_SUCCESS) rc = LDAP_NO_SUCH_OBJECT; log_log(LOG_DEBUG, "\"%s\": user not found: %s", username, ldap_err2string(rc)); *rcp = rc; return NULL; } return entry; }
int parsebootfile(const char *fname, char **devname, uint *unit, uint *partition, const char **file) { const char *col; *devname = default_devname; *unit = default_unit; *partition = default_partition; *file = default_filename; if (fname == NULL) return (0); if((col = strchr(fname, ':'))) { /* device given */ static char savedevname[MAXDEVNAME+1]; int devlen; unsigned int u = 0, p = 0; int i = 0; devlen = col - fname; if (devlen > MAXDEVNAME) return (EINVAL); #define isvalidname(c) ((c) >= 'a' && (c) <= 'z') if (!isvalidname(fname[i])) return (EINVAL); do { savedevname[i] = fname[i]; i++; } while (isvalidname(fname[i])); savedevname[i] = '\0'; #define isnum(c) ((c) >= '0' && (c) <= '9') if (i < devlen) { if (!isnum(fname[i])) return (EUNIT); do { u *= 10; u += fname[i++] - '0'; } while (isnum(fname[i])); } #define isvalidpart(c) ((c) >= 'a' && (c) <= 'p') if (i < devlen) { if (!isvalidpart(fname[i])) return (EPART); p = fname[i++] - 'a'; } if (i != devlen) return (ENXIO); *devname = savedevname; *unit = u; *partition = p; fname = col + 1; } if (*fname) *file = fname; return (0); }
void TokenListToRPN(TokenList &a_list, RPNStack &a_rpn) { // Shunting yard algorithm std::vector<Token*> opStack; Token *c_token = a_list.head; while (c_token) { switch (c_token->type) { case Token::Type::Name: if (isalllower(c_token->name, true) && isvalidname(c_token->name)) { if (G::functions.Exists(c_token->name)) { opStack.push_back(c_token); c_token->type = Token::Type::E_Function; } else if (G::variables.Exists(c_token->name)) { a_rpn.push_back({ ExprNode::Type::Number, G::variables.Get(c_token->name) }); } else throw ExpressionError("Undefined reference", c_token); } else if (isallupper(c_token->name, true) && isvalidname(c_token->name)) { if (G::constants.Exists(c_token->name)) a_rpn.push_back({ ExprNode::Type::Number, G::constants.Get(c_token->name) }); else throw ExpressionError("Undefined constant", c_token); } else throw ExpressionError("Invalid value name", c_token); break; case Token::Type::Number: a_rpn.push_back({ ExprNode::Type::Number, c_token->value }); break; case Token::Type::Operator: if (opStack.size() > 0) { if (c_token->optype == Token::OpType::RPar) { Token *tos = opStack.back(); if (opStack.size() == 0) throw ExpressionError("#1 Mismatched parenthesis", c_token); while (tos->optype != Token::OpType::LPar) { a_rpn.push_back({ ExprNode::Type::Operator, 0, tos->optype }); opStack.pop_back(); tos = opStack.back(); if (opStack.size() == 0) throw ExpressionError("#2 Mismatched parenthesis", c_token); } opStack.pop_back(); // pop opening parantheses if (opStack.size() > 0) { tos = opStack.back(); if (tos->type == Token::Type::E_Function) { a_rpn.push_back({ ExprNode::Type::Function, 0, Token::OpType::None, HashFunc(tos->name) }); opStack.pop_back(); } } } else if (c_token->optype == Token::OpType::Comma) { Token *tos = opStack.back(); if (opStack.size() == 0) throw ExpressionError("Invalid separator", c_token); while (tos->optype != Token::OpType::LPar) { a_rpn.push_back({ ExprNode::Type::Operator, 0, tos->optype }); opStack.pop_back(); tos = opStack.back(); if (opStack.size() == 0) throw ExpressionError("Invalid separator", c_token); } } else { if (c_token->optype != Token::OpType::LPar) { while (opStack.size() > 0 && opStack.back()->optype != Token::OpType::LPar) { Token *tos = opStack.back(); if ((is_la(c_token->optype) && precedence(c_token->optype) <= precedence(tos->optype)) || (is_ra(c_token->optype) && precedence(c_token->optype) < precedence(tos->optype))) { opStack.pop_back(); a_rpn.push_back({ ExprNode::Type::Operator, 0, tos->optype }); } else break; } } opStack.push_back(c_token); } } else if (c_token->optype != Token::OpType::RPar || c_token->optype != Token::OpType::Comma) opStack.push_back(c_token); break; case Token::Type::Special: a_rpn.push_back({ ExprNode::Type::Special, 0, ExprNode::OpType::None, 0, c_token->sptype }); break; } c_token = c_token->next; } for (unsigned i = opStack.size(); i-- > 0; ) { if (opStack[i]->optype == Token::OpType::LPar || opStack[i]->optype == Token::OpType::RPar) throw ExpressionError("#3 Mismatched parenthesis", opStack[i]); a_rpn.push_back({ ExprNode::Type::Operator, 0, opStack[i]->optype }); } }