コード例 #1
0
ファイル: auxprop.c プロジェクト: 1ack/Impala
/* 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]");
}
コード例 #2
0
ファイル: auxprop.c プロジェクト: 1ack/Impala
/* 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;
}
コード例 #3
0
ファイル: auxprop.c プロジェクト: cyrusimap/cyrus-sasl
/* 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;
}