35 #include "ac/getopt.h" 
   41 #include <sys/types.h> 
   42 #include <sys/socket.h> 
   43 #include <netinet/in.h> 
   51 #if defined(HAVE_SASL_SASL_H) 
   52 #include <sasl/sasl.h> 
   53 #elif defined (HAVE_SASL_H) 
   61 const unsigned short int PORT = 5555;
 
   69                 "\n\tusage: sockdrive [h:p:D:w:Wi:I:] <label> [<value>]\n\n" 
   70                 "\t\t-D <user>\tuser name\n" 
   71                 "\t\t-h <host>\thost name\n" 
   72                 "\t\t-i {yes|no}\tincremental (i.e. value[<label>] += <value>)\n" 
   73                 "\t\t-I {yes|no}\timpulsive (reset after one step)\n" 
   74                 "\t\t-m <mech>\tSASL mechanism (needs -S)\n" 
   75                 "\t\t-p <port>\tport number\n" 
   76                 "\t\t-P <path>\tpath of named pipe\n" 
   77                 "\t\t-S\t\tenable SASL auth" 
   82                 "\t\t-w <cred>\tuser credentials\n" 
   83                 "\t\t-W\t\tprompt for user credentials\n" 
   84                 "\t\t<label>:\tfile drive (base 1) index to modify\n" 
   86                 "\t\t<value>:\tnew value (or increment if -i)\n\n");
 
   91 static struct mbdyn_sasl_t mbdyn_sasl = MBDYN_SASL_INIT;
 
   95 main(
int argc, 
char *argv[])
 
  118                 opt = 
getopt (argc, argv, 
"D:h:i:I:m:p:P:S:w:W");
 
  134                         if (strcasecmp(
optarg, 
"yes") == 0) {
 
  136                         } 
else if (strcasecmp(
optarg, 
"no") == 0) {
 
  142                         if (strcasecmp(
optarg, 
"yes") == 0) {
 
  144                         } 
else if (strcasecmp(
optarg, 
"no") == 0) {
 
  152                         fprintf(stderr, 
"SASL not supported\n");
 
  167                         fprintf(stderr, 
"SASL not supported\n");
 
  184                                 snprintf(buf, 
sizeof(buf), 
"Password for user \"%s\": ", user);
 
  188                                 cred = getpass(
"Password: ");
 
  198         if ((argc - 
optind) < 1) {
 
  204         if ((argc - 
optind) > 1) {
 
  214                 fprintf(stderr, 
"socket initialization error\n");
 
  220                 printf(
"initializing SASL data...\n");
 
  222                 mbdyn_sasl.use_sasl = MBDYN_SASL_CLIENT;
 
  223                 mbdyn_sasl.sasl_flags = MBDYN_SASL_FLAG_CRITICAL | MBDYN_SASL_FLAG_USERAUTHZ;
 
  224                 mbdyn_sasl.sasl_mech = mech;
 
  225                 mbdyn_sasl.sasl_user = user;
 
  226                 mbdyn_sasl.sasl_cred = cred;
 
  227                 mbdyn_sasl.sasl_hostname = 
host;
 
  229                 if (mbdyn_sasl_client_init(&mbdyn_sasl) != SASL_OK) {
 
  230                         fprintf(stderr, 
"SASL init failed\n");
 
  234                 if (mbdyn_sasl_client_auth(sock, NULL, &mbdyn_sasl) != SASL_OK) {
 
  235                         fprintf(stderr, 
"SASL auth failed\n");
 
  241         fd = fdopen(sock, 
"w");
 
  245                         fprintf(fd, 
"user: %s\n", user);
 
  247                                 fprintf(fd, 
"password: %s\n", cred);
 
  248                                 memset(cred, 
'\0', strlen(cred));
 
  253         fprintf(fd, 
"label: %s\n", label);
 
  256                 fprintf(fd, 
"inc: yes\n");
 
  257         } 
else if (inc == -1) {
 
  258                 fprintf(fd, 
"inc: no\n");
 
  262                 fprintf(fd, 
"imp: yes\n");
 
  263         } 
else if (imp == -1) {
 
  264                 fprintf(fd, 
"imp: no\n");
 
  268                 fprintf(fd, 
"value: %s\n", value);
 
int main(int argc, char *argv[])
int mbdyn_make_inet_socket(struct sockaddr_in *name, const char *hostname, unsigned short int port, int dobind, int *perror)
const unsigned short int PORT
int mbdyn_make_named_socket(struct sockaddr_un *name, const char *path, int dobind, int *perror)
int getopt(int argc, char *const argv[], const char *opts)
static doublereal buf[BUFSIZE]