Return to xauth_pam_plugin.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / plugins / xauth_pam |
1.1 misho 1: /* 2: * Copyright (C) 2012 Martin Willi 3: * Copyright (C) 2012 revosec AG 4: * 5: * This program is free software; you can redistribute it and/or modify it 6: * under the terms of the GNU General Public License as published by the 7: * Free Software Foundation; either version 2 of the License, or (at your 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 9: * 10: * This program is distributed in the hope that it will be useful, but 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13: * for more details. 14: */ 15: 16: #include "xauth_pam_plugin.h" 17: #include "xauth_pam.h" 18: #include "xauth_pam_listener.h" 19: 20: #include <daemon.h> 21: 22: #ifndef CAP_AUDIT_WRITE 23: #define CAP_AUDIT_WRITE 29 24: #endif 25: 26: typedef struct private_xauth_pam_plugin_t private_xauth_pam_plugin_t; 27: 28: /** 29: * private data of xauth_pam plugin 30: */ 31: struct private_xauth_pam_plugin_t { 32: 33: /** 34: * implements plugin interface 35: */ 36: xauth_pam_plugin_t public; 37: 38: /** 39: * Listener 40: */ 41: xauth_pam_listener_t *listener; 42: 43: /** 44: * Do PAM session management? 45: */ 46: bool session; 47: }; 48: 49: /** 50: * Register XAuth method and listener 51: */ 52: static bool register_listener(private_xauth_pam_plugin_t *this, 53: plugin_feature_t *feature, bool reg, void *data) 54: { 55: if (reg) 56: { 57: charon->bus->add_listener(charon->bus, &this->listener->listener); 58: } 59: else 60: { 61: charon->bus->remove_listener(charon->bus, &this->listener->listener); 62: } 63: return TRUE; 64: } 65: 66: METHOD(plugin_t, get_name, char*, 67: private_xauth_pam_plugin_t *this) 68: { 69: return "xauth-pam"; 70: } 71: 72: METHOD(plugin_t, get_features, int, 73: private_xauth_pam_plugin_t *this, plugin_feature_t *features[]) 74: { 75: static plugin_feature_t f[] = { 76: PLUGIN_CALLBACK(xauth_method_register, xauth_pam_create_server), 77: PLUGIN_PROVIDE(XAUTH_SERVER, "pam"), 78: PLUGIN_CALLBACK((plugin_feature_callback_t)register_listener, NULL), 79: PLUGIN_PROVIDE(CUSTOM, "pam-session"), 80: }; 81: *features = f; 82: if (!this->session) 83: { 84: return 2; 85: } 86: return countof(f); 87: } 88: 89: METHOD(plugin_t, destroy, void, 90: private_xauth_pam_plugin_t *this) 91: { 92: this->listener->destroy(this->listener); 93: free(this); 94: } 95: 96: /* 97: * see header file 98: */ 99: plugin_t *xauth_pam_plugin_create() 100: { 101: private_xauth_pam_plugin_t *this; 102: 103: /* required for PAM authentication */ 104: if (!lib->caps->keep(lib->caps, CAP_AUDIT_WRITE)) 105: { 106: DBG1(DBG_DMN, "xauth-pam plugin requires CAP_AUDIT_WRITE capability"); 107: return NULL; 108: } 109: 110: INIT(this, 111: .public = { 112: .plugin = { 113: .get_name = _get_name, 114: .get_features = _get_features, 115: .destroy = _destroy, 116: }, 117: }, 118: .session = lib->settings->get_str(lib->settings, 119: "%s.plugins.xauth-pam.session", FALSE, lib->ns), 120: .listener = xauth_pam_listener_create(), 121: ); 122: 123: return &this->public.plugin; 124: }