root/source4/libnet/py_net.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. py_net_ctx
  2. py_net_join
  3. initnet

   1 /* 
   2    Unix SMB/CIFS implementation.
   3    Samba utility functions
   4    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
   5    
   6    This program is free software; you can redistribute it and/or modify
   7    it under the terms of the GNU General Public License as published by
   8    the Free Software Foundation; either version 3 of the License, or
   9    (at your option) any later version.
  10    
  11    This program is distributed in the hope that it will be useful,
  12    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14    GNU General Public License for more details.
  15    
  16    You should have received a copy of the GNU General Public License
  17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18 */
  19 
  20 #include "includes.h"
  21 #include <Python.h>
  22 #include "libnet.h"
  23 #include "libcli/security/security.h"
  24 #include "lib/events/events.h"
  25 #include "param/param.h"
  26 
  27 /* FIXME: This prototype should be in param/pyparam.h */
  28 struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx);
  29 
  30 static struct libnet_context *py_net_ctx(PyObject *obj, struct tevent_context *ev)
     /* [<][>][^][v][top][bottom][index][help] */
  31 {
  32         /* FIXME: Use obj */
  33         return libnet_context_init(ev, py_default_loadparm_context(NULL));
  34 }
  35 
  36 static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
     /* [<][>][^][v][top][bottom][index][help] */
  37 {
  38         struct libnet_Join r;
  39         NTSTATUS status;
  40         PyObject *result;
  41         TALLOC_CTX *mem_ctx;
  42         struct tevent_context *ev;
  43         struct libnet_context *libnet_ctx;
  44         const char *kwnames[] = { "domain_name", "netbios_name", "join_type", "level", NULL };
  45 
  46         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssii:Join", discard_const_p(char *, kwnames), 
  47                                          &r.in.domain_name, &r.in.netbios_name, 
  48                                          &r.in.join_type, &r.in.level))
  49                 return NULL;
  50 
  51         /* FIXME: we really need to get a context from the caller or we may end
  52          * up with 2 event contexts */
  53         ev = s4_event_context_init(NULL);
  54         mem_ctx = talloc_new(ev);
  55 
  56         libnet_ctx = py_net_ctx(cls, ev);
  57 
  58         status = libnet_Join(libnet_ctx, mem_ctx, &r);
  59         if (NT_STATUS_IS_ERR(status)) {
  60                 PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
  61                 talloc_free(mem_ctx);
  62                 return NULL;
  63         }
  64 
  65         result = Py_BuildValue("sss", r.out.join_password, 
  66                                dom_sid_string(mem_ctx, r.out.domain_sid),
  67                                r.out.domain_name);
  68 
  69         talloc_free(mem_ctx);
  70 
  71         if (result == NULL)
  72                 return NULL;
  73 
  74         return result;
  75 }
  76 
  77 static char py_net_join_doc[] = "join(domain_name, netbios_name, join_type, level) -> (join_password, domain_sid, domain_name)\n\n" \
  78 "Join the domain with the specified name.";
  79 
  80 static struct PyMethodDef net_methods[] = {
  81         {"Join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS, py_net_join_doc},
  82         {NULL }
  83 };
  84 
  85 void initnet(void)
     /* [<][>][^][v][top][bottom][index][help] */
  86 {
  87         Py_InitModule("net", net_methods);
  88 }

/* [<][>][^][v][top][bottom][index][help] */