#include "mbconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "ac/getopt.h"
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <netdb.h>
#include <string.h>
#include <signal.h>
#include "sock.h"
Go to the source code of this file.
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 95 of file sockdrive.c.
References buf, getopt(), host, mbdyn_make_inet_socket(), mbdyn_make_named_socket(), optarg, optind, path, PORT, port, SERVERHOST, and usage().
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 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]
static void usage |
( |
void |
| ) |
|
|
static |
Definition at line 66 of file sockdrive.c.
Referenced by main().
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");
const unsigned short int PORT = 5555 |
const char* SERVERHOST = "localhost" |
const char* SERVERPATH = "/var/mbdyn/mbdyn.sock" |