Exemplo n.º 1
0
/* Do the callbacks for auxprop stores */
int sasl_auxprop_store(sasl_conn_t *conn,
		       struct propctx *ctx, const char *user)
{
    sasl_getopt_t *getopt;
    int ret, found = 0;
    void *context;
    const char *plist = NULL;
    auxprop_plug_list_t *ptr;
    sasl_server_params_t *sparams = NULL;
    unsigned userlen = 0;

    if (ctx) {
	if (!conn || !user)
	    return SASL_BADPARAM;

	sparams = ((sasl_server_conn_t *) conn)->sparams;
	userlen = (unsigned) strlen(user);
    }
    
    /* Pickup getopt callback from the connection, if conn is not NULL */
    if(_sasl_getcallback(conn, SASL_CB_GETOPT, &getopt, &context) == SASL_OK) {
	ret = getopt(context, NULL, "auxprop_plugin", &plist, NULL);
	if(ret != SASL_OK) plist = NULL;
    }

    ret = SASL_OK;
    if(!plist) {
	/* Do store in all plugins */
	for(ptr = auxprop_head; ptr && ret == SASL_OK; ptr = ptr->next) {
	    found=1;
	    if (ptr->plug->auxprop_store)
		ret = ptr->plug->auxprop_store(ptr->plug->glob_context,
					       sparams, ctx, user, userlen);
	}
    } else {
	char *pluginlist = NULL, *freeptr = NULL, *thisplugin = NULL;

	if(_sasl_strdup(plist, &pluginlist, NULL) != SASL_OK) return SASL_FAIL;
	thisplugin = freeptr = pluginlist;
	
	/* Do store in all *specified* plugins, in order */
	while(*thisplugin) {
	    char *p;
	    int last=0;
	    
	    while(*thisplugin && isspace((int)*thisplugin)) thisplugin++;
	    if(!(*thisplugin)) break;
	    
	    for(p = thisplugin;*p != '\0' && !isspace((int)*p); p++);
	    if(*p == '\0') last = 1;
	    else *p='\0';
	    
	    for(ptr = auxprop_head; ptr && ret == SASL_OK; ptr = ptr->next) {
		/* Skip non-matching plugins */
		if((!ptr->plug->name
		    || strcasecmp(ptr->plug->name, thisplugin)))
		    continue;

		found=1;
		if (ptr->plug->auxprop_store)
		    ret = ptr->plug->auxprop_store(ptr->plug->glob_context,
						   sparams, ctx, user, userlen);
	    }

	    if(last) break;

	    thisplugin = p+1;
	}

	sasl_FREE(freeptr);
    }

    if(!found) {
	_sasl_log(NULL, SASL_LOG_ERR,
		  "could not find auxprop plugin, was searching for %s",
		  plist ? plist : "[all]");
	return SASL_FAIL;
    }

    return ret;
}
Exemplo n.º 2
0
/* Do the callbacks for auxprop lookups */
int _sasl_auxprop_lookup(sasl_server_params_t *sparams,
			  unsigned flags,
			  const char *user, unsigned ulen) 
{
    sasl_getopt_t *getopt;
    int ret, found = 0;
    void *context;
    const char *plist = NULL;
    auxprop_plug_list_t *ptr;
    int result = SASL_NOMECH;

    if(_sasl_getcallback(sparams->utils->conn,
			 SASL_CB_GETOPT,
			 (sasl_callback_ft *)&getopt,
			 &context) == SASL_OK) {
	ret = getopt(context, NULL, "auxprop_plugin", &plist, NULL);
	if(ret != SASL_OK) plist = NULL;
    }

    if(!plist) {
	/* Do lookup in all plugins */

	/* TODO: Ideally, each auxprop plugin should be marked if its failure
	   should be ignored or treated as a fatal error of the whole lookup. */
	for(ptr = auxprop_head; ptr; ptr = ptr->next) {
	    found=1;
	    ret = ptr->plug->auxprop_lookup(ptr->plug->glob_context,
				      sparams, flags, user, ulen);
	    result = _sasl_account_status (result, ret);
	}
    } else {
	char *pluginlist = NULL, *freeptr = NULL, *thisplugin = NULL;

	if(_sasl_strdup(plist, &pluginlist, NULL) != SASL_OK) return SASL_NOMEM;
	thisplugin = freeptr = pluginlist;
	
	/* Do lookup in all *specified* plugins, in order */
	while(*thisplugin) {
	    char *p;
	    int last=0;
	    
	    while(*thisplugin && isspace((int)*thisplugin)) thisplugin++;
	    if(!(*thisplugin)) break;
	    
	    for(p = thisplugin;*p != '\0' && !isspace((int)*p); p++);
	    if(*p == '\0') last = 1;
	    else *p='\0';
	    
	    for(ptr = auxprop_head; ptr; ptr = ptr->next) {
		/* Skip non-matching plugins */
		if(!ptr->plug->name
		   || strcasecmp(ptr->plug->name, thisplugin))
		    continue;
	    
		found=1;
		ret = ptr->plug->auxprop_lookup(ptr->plug->glob_context,
					  sparams, flags, user, ulen);
		result = _sasl_account_status (result, ret);
	    }

	    if(last) break;

	    thisplugin = p+1;
	}

	sasl_FREE(freeptr);
    }

    if(!found) {
	_sasl_log(sparams->utils->conn, SASL_LOG_DEBUG,
		  "could not find auxprop plugin, was searching for '%s'",
		  plist ? plist : "[all]");
    }

    return result;
}
Exemplo n.º 3
0
/* Do the callbacks for auxprop lookups */
void _sasl_auxprop_lookup(sasl_server_params_t *sparams,
			  unsigned flags,
			  const char *user, unsigned ulen) 
{
    sasl_getopt_t *getopt;
    int ret, found = 0;
    void *context;
    const char *plist = NULL;
    auxprop_plug_list_t *ptr;

    if(_sasl_getcallback(sparams->utils->conn,
			 SASL_CB_GETOPT, &getopt, &context) == SASL_OK) {
	ret = getopt(context, NULL, "auxprop_plugin", &plist, NULL);
	if(ret != SASL_OK) plist = NULL;
    }

    if(!plist) {
	/* Do lookup in all plugins */
	for(ptr = auxprop_head; ptr; ptr = ptr->next) {
	    found=1;
	    ptr->plug->auxprop_lookup(ptr->plug->glob_context,
				      sparams, flags, user, ulen);
	}
    } else {
	char *pluginlist = NULL, *freeptr = NULL, *thisplugin = NULL;

	if(_sasl_strdup(plist, &pluginlist, NULL) != SASL_OK) return;
	thisplugin = freeptr = pluginlist;
	
	/* Do lookup in all *specified* plugins, in order */
	while(*thisplugin) {
	    char *p;
	    int last=0;
	    
	    while(*thisplugin && isspace((int)*thisplugin)) thisplugin++;
	    if(!(*thisplugin)) break;
	    
	    for(p = thisplugin;*p != '\0' && !isspace((int)*p); p++);
	    if(*p == '\0') last = 1;
	    else *p='\0';
	    
	    for(ptr = auxprop_head; ptr; ptr = ptr->next) {
		/* Skip non-matching plugins */
		if(!ptr->plug->name
		   || strcasecmp(ptr->plug->name, thisplugin))
		    continue;
	    
		found=1;
		ptr->plug->auxprop_lookup(ptr->plug->glob_context,
					  sparams, flags, user, ulen);
	    }

	    if(last) break;

	    thisplugin = p+1;
	}

	sasl_FREE(freeptr);
    }

    if(!found)
	_sasl_log(sparams->utils->conn, SASL_LOG_DEBUG,
		  "could not find auxprop plugin, was searching for '%s'",
		  plist ? plist : "[all]");
}
Exemplo n.º 4
0
int sasl_config_init(const char *filename)
{
    FILE *infile;
    int lineno = 0;
    int alloced = 0;
    char buf[4096];
    char *p, *key;
    int result;

    nconfiglist=0;

    infile = fopen(filename, "r");
    if (!infile) {
      return SASL_CONTINUE;
    }
    
    while (fgets(buf, sizeof(buf), infile)) {
	lineno++;

	if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
	for (p = buf; *p && isspace((int) *p); p++);
	if (!*p || *p == '#') continue;

	key = p;
	while (*p && (isalnum((int) *p) || *p == '-' || *p == '_')) {
	    if (isupper((int) *p)) *p = tolower(*p);
	    p++;
	}
	if (*p != ':') {
	  return SASL_FAIL;
	}
	*p++ = '\0';

	while (*p && isspace((int) *p)) p++;
	
	if (!*p) {
	  return SASL_FAIL;
	}

	if (nconfiglist == alloced) {
	    alloced += CONFIGLISTGROWSIZE;
	    configlist=sasl_REALLOC((char *)configlist, 
				    alloced * sizeof(struct configlist));
	    if (configlist==NULL) return SASL_NOMEM;
	}



	result = _sasl_strdup(key,
			      &(configlist[nconfiglist].key),
			      NULL);
	if (result!=SASL_OK) return result;
	result = _sasl_strdup(p,
			      &(configlist[nconfiglist].value),
			      NULL);
	if (result!=SASL_OK) return result;

	nconfiglist++;
    }
    fclose(infile);

    return SASL_OK;
}