[Asterisk-Dev] [patch] Function to check passcode against vm
passcode
Gil Kloepfer
astr-dev at kloepfer.org
Tue Jan 17 15:39:22 MST 2006
Folks-
I'm trying to get feedback and someone to do some additional testing of
the following patch that adds a function that allows testing an
entered set of digits against the password entered in the voicemail.conf
file for a specific mailbox.
The rationale behind this is that there are occasions where I have
already read a "password" (I'm calling it a passcode since it is really
just digits) and want to just test it against a particular user's
voicemail mailbox password. This differs from VMAuthenticate which
requires the password to be entered at the same time the test is done.
The new function syntax is:
VMPASSCHECK(mailbox[@context]|passcode)
It returns 1 if the passcode matches the passcode in voicemail.conf
for mailbox (and optionally @context). If the mailbox doesn't exist
or the passcode doesn't match, or the passcode is blank, it returns 0.
If I get good feedback or the lack of negative feedback, I will
submit the patch to Mantis. (yes, I have a disclaimer on file)
The patch is against SVN-1.2 ver 8153 (17-Jan-2006). It is based on
code in app_hasnewvoicemail.c and app_voicemail.c.
Thanks!
---
Gil Kloepfer
astr-dev at kloepfer.org
-- Cut Here -- -- Cut Here -- -- Cut Here -- -- Cut Here -- -- Cut Here --
--- asterisk/apps/app_voicemail.c.ORIG 2006-01-17 16:04:49.000000000 -0600
+++ asterisk/apps/app_voicemail.c 2006-01-17 16:31:32.000000000 -0600
@@ -5025,6 +5025,69 @@
return 0;
}
+static char *func_vmpasscheck_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ struct localuser *u;
+ char *args, *mailbox, *context, *passcode, *vmpass;
+ struct ast_vm_user vmus, *vmu = NULL;
+
+ LOCAL_USER_ACF_ADD(u);
+
+ ast_copy_string(buf, "0", len);
+
+ if (ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "VMPASSCHECK function was called with no arguments\n");
+ goto done;
+ }
+
+ args = ast_strdupa(data);
+ if (!args) {
+ ast_log(LOG_ERROR, "Out of memory");
+ goto done;
+ }
+
+ passcode = strchr(args, '|');
+ if (passcode)
+ *passcode++ = '\0';
+ else {
+ ast_log(LOG_WARNING, "Passcode not provided to VMPASSCHECK function\n");
+ goto done;
+ }
+ mailbox = args;
+ context = strchr(args, '@');
+ if (context)
+ *context++ = '\0';
+ else
+ context = "default";
+
+ vmu = find_user(&vmus, context, mailbox);
+ if (vmu) {
+ vmpass = vmu->password;
+ if (*vmpass == '-')
+ vmpass++;
+
+ if (*vmpass != '\0' && strcmp(passcode, vmpass) == 0)
+ ast_copy_string(buf, "1", len);
+ }
+
+done:
+ LOCAL_USER_REMOVE(u);
+ return buf;
+}
+
+struct ast_custom_function vmpasscheck_function = {
+ .name "VMPASSCHECK",
+ .synopsis = "Check entered passcode against a mailbox's passcode",
+ .syntax = "VMPASSCHECK(mailbox[@context]|passcode)",
+ .desc =
+ "This function tests whether the specified passcode matches the\n"
+ "passcode for mailbox at context (if not given, context defaults\n"
+ "to \"default\"). Returns 0 if the passcode doesn't match or\n"
+ "the specified mailbox does not exist. If the password matches\n"
+ "1 is returned.\n",
+ .read = func_vmpasscheck_read,
+};
+
static int vm_execmain(struct ast_channel *chan, void *data)
{
/* XXX This is, admittedly, some pretty horrendus code. For some
@@ -6263,6 +6326,7 @@
res |= ast_unregister_application(app4);
res |= ast_cli_unregister(&show_voicemail_users_cli);
res |= ast_cli_unregister(&show_voicemail_zones_cli);
+ res |= ast_custom_function_unregister(&vmpasscheck_function);
ast_uninstall_vm_functions();
STANDARD_HANGUP_LOCALUSERS;
@@ -6277,6 +6341,7 @@
res |= ast_register_application(app2, vm_execmain, synopsis_vmain, descrip_vmain);
res |= ast_register_application(app3, vm_box_exists, synopsis_vm_box_exists, descrip_vm_box_exists);
res |= ast_register_application(app4, vmauthenticate, synopsis_vmauthenticate, descrip_vmauthenticate);
+ res |= ast_custom_function_register(&vmpasscheck_function);
if (res)
return(res);
-- Cut Here -- -- Cut Here -- -- Cut Here -- -- Cut Here -- -- Cut Here --
More information about the asterisk-dev
mailing list