-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rearranged the init system, this is not well tested yet.
- Loading branch information
Caleb James DeLisle
committed
Mar 27, 2012
1 parent
a7732c9
commit 321e2a9
Showing
15 changed files
with
683 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,96 @@ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
|
|||
#include "admin/AuthorizedPasswords.h" | |||
#include "memory/BufferAllocator.h" | |||
|
|||
struct Context | |||
{ | |||
struct Admin* admin; | |||
struct CryptoAuth* ca; | |||
struct Allocator* allocator; | |||
}; | |||
|
|||
struct User | |||
{ | |||
uint64_t trust; | |||
}; | |||
|
|||
static void sendResponse(String* msg, struct Admin* admin, String* txid) | |||
{ | |||
#define BUFFERSZ 1024 | |||
uint8_t buffer[BUFFERSZ]; | |||
struct Allocator* alloc = BufferAllocator_new(buffer, BUFFERSZ); | |||
Dict* output = Dict_new(alloc); | |||
Dict_putString(output, String_CONST("error"), msg, alloc); | |||
Admin_sendMessage(output, txid, admin); | |||
} | |||
|
|||
static void add(Dict* ap, void* vcontext, String* txid) | |||
{ | |||
struct Context* context = (struct Context*) vcontext; | |||
|
|||
String* passwd = Dict_getString(ap, String_CONST("password")); | |||
int64_t* authType = Dict_getInt(ap, String_CONST("authType")); | |||
|
|||
String* msg = NULL; | |||
if (!(passwd && authType)) { | |||
msg = String_CONST("Must specify authType, and password."); | |||
} else if (*authType < 1 || *authType > 255) { | |||
msg = String_CONST("Auth must be between 1 and 255 inclusive."); | |||
} else { | |||
struct User* u = context->allocator->malloc(sizeof(struct User), context->allocator); | |||
// At some point this will be implemented... | |||
u->trust = 0; | |||
int32_t ret = CryptoAuth_addUser(passwd, *authType, u, context->ca); | |||
|
|||
switch (ret) { | |||
case 0: | |||
msg = String_CONST("none"); | |||
break; | |||
case CryptoAuth_addUser_INVALID_AUTHTYPE: | |||
msg = String_CONST("Specified auth type is not supported."); | |||
break; | |||
case CryptoAuth_addUser_OUT_OF_SPACE: | |||
msg = String_CONST("Out of memory to store password."); | |||
break; | |||
case CryptoAuth_addUser_DUPLICATE: | |||
msg = String_CONST("Password already added."); | |||
break; | |||
default: | |||
msg = String_CONST("Unknown error."); | |||
}; | |||
} | |||
|
|||
sendResponse(msg, context->admin, txid); | |||
} | |||
|
|||
static void flush(Dict* ap, void* vcontext, String* txid) | |||
{ | |||
struct Context* context = (struct Context*) vcontext; | |||
CryptoAuth_flushUsers(context->ca); | |||
sendResponse(String_CONST("none"), context->admin, txid); | |||
} | |||
|
|||
void AuthorizedPasswords_init(struct Admin* admin, | |||
struct CryptoAuth* ca, | |||
struct Allocator* allocator) | |||
{ | |||
struct Context* context = allocator->malloc(sizeof(struct Context), allocator); | |||
context->admin = admin; | |||
context->allocator = allocator; | |||
context->ca = ca; | |||
Admin_registerFunction("AuthorizedPasswords_add", add, context, true, admin); | |||
Admin_registerFunction("AuthorizedPasswords_flush", flush, context, true, admin); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
/* | |||
* You may redistribute this program and/or modify it under the terms of | |||
* the GNU General Public License as published by the Free Software Foundation, | |||
* either version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef AuthorizedPasswords_H | |||
#define AuthorizedPasswords_H | |||
|
|||
#include "admin/Admin.h" | |||
#include "crypto/CryptoAuth.h" | |||
#include "memory/Allocator.h" | |||
|
|||
/** | |||
* Init the AuthorizedPasswords admin function. | |||
* This function exports the following calls, | |||
* AuthorizedPasswords_add() --- Add an authorized password routers to connect. | |||
* - requires a password. | |||
* - inputs | |||
* password: (String, mandatory) | |||
* The password to authorize. | |||
* authType: (Integer, mandatory) | |||
* The way in which nodes will be allowed to authenticate with | |||
* the password. | |||
* | |||
* - outputs | |||
* error: (String) | |||
* A message explaining what went wrong, if everything went ok, | |||
* the error will be "none". | |||
* | |||
* AuthorizedPasswords_flush() --- Remove all authorized passwords. | |||
* - requires a password | |||
* - inputs (none) | |||
* - outputs | |||
* error: (String) | |||
* always "none". | |||
* | |||
* @param admin the admin object. | |||
* @param ca the cryptoauth to add users to. | |||
* @param allocator a persistent memory allocator. | |||
*/ | |||
void AuthorizedPasswords_init(struct Admin* admin, | |||
struct CryptoAuth* ca, | |||
struct Allocator* allocator); | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.