root/source3/lib/netapi/examples/common.c

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

DEFINITIONS

This source file includes following definitions.
  1. popt_common_callback

   1 #include <stdlib.h>
   2 #include <string.h>
   3 #include <sys/types.h>
   4 #include <inttypes.h>
   5 
   6 #include <popt.h>
   7 #include <netapi.h>
   8 
   9 void popt_common_callback(poptContext con,
     /* [<][>][^][v][top][bottom][index][help] */
  10                          enum poptCallbackReason reason,
  11                          const struct poptOption *opt,
  12                          const char *arg, const void *data)
  13 {
  14         struct libnetapi_ctx *ctx = NULL;
  15 
  16         libnetapi_getctx(&ctx);
  17 
  18         if (reason == POPT_CALLBACK_REASON_PRE) {
  19         }
  20 
  21         if (reason == POPT_CALLBACK_REASON_POST) {
  22         }
  23 
  24         if (!opt) {
  25                 return;
  26         }
  27         switch (opt->val) {
  28                 case 'U': {
  29                         char *puser = strdup(arg);
  30                         char *p = NULL;
  31 
  32                         if ((p = strchr(puser,'%'))) {
  33                                 size_t len;
  34                                 *p = 0;
  35                                 libnetapi_set_username(ctx, puser);
  36                                 libnetapi_set_password(ctx, p+1);
  37                                 len = strlen(p+1);
  38                                 memset(strchr(arg,'%')+1,'X',len);
  39                         } else {
  40                                 libnetapi_set_username(ctx, puser);
  41                         }
  42                         free(puser);
  43                         break;
  44                 }
  45                 case 'd':
  46                         libnetapi_set_debuglevel(ctx, arg);
  47                         break;
  48                 case 'p':
  49                         libnetapi_set_password(ctx, arg);
  50                         break;
  51                 case 'k':
  52                         libnetapi_set_use_kerberos(ctx);
  53                         break;
  54         }
  55 }
  56 
  57 struct poptOption popt_common_netapi_examples[] = {
  58         { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback },
  59         { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" },
  60         { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" },
  61         { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" },
  62         { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL },
  63         POPT_TABLEEND
  64 };
  65 

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