]> andersk Git - moira.git/blob - lib/mr_access.c
Avoid buffer overruns and check return value of malloc()
[moira.git] / lib / mr_access.c
1 /* $Id$
2  *
3  * Check access to a Moira query
4  *
5  * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include "mr_private.h"
13
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 RCSID("$Header$");
19
20 int mr_access_internal(int argc, char **argv);
21
22 /*
23  * Check access to a named query.
24  */
25 int mr_access(char *name, int argc, char **argv)
26 {
27   char **nargv = malloc(sizeof(char *) * (argc + 1));
28   int status = 0;
29
30   if (!nargv)
31     return ENOMEM;
32   nargv[0] = name;
33   memcpy(nargv + 1, argv, sizeof(char *) * argc);
34   status = mr_access_internal(argc + 1, nargv);
35   free(nargv);
36   return status;
37 }
38
39 /*
40  * Check access to a named query, where the query name is argv[0]
41  * and the arguments are the rest of argv[].
42  */
43 int mr_access_internal(int argc, char **argv)
44 {
45   int status;
46   mr_params params_st;
47   mr_params *params = NULL;
48   mr_params *reply = NULL;
49
50   CHECK_CONNECTED;
51
52   params = &params_st;
53   params->mr_version_no = sending_version_no;
54   params->mr_procno = MR_ACCESS;
55   params->mr_argc = argc;
56   params->mr_argl = NULL;
57   params->mr_argv = argv;
58
59   if ((status = mr_do_call(params, &reply)) == 0)
60     status = reply->mr_status;
61
62   mr_destroy_reply(reply);
63
64   return status;
65 }
This page took 0.040135 seconds and 5 git commands to generate.