s3:pylibsmb: Add .unlink() API to SMB Py bindings
[samba.git] / source3 / utils / net.c
index e0776c8d82c6df16111989d431bfbb2a954ea9fa..8350e8c0967b81783b58630f5e9bcc5111589366 100644 (file)
@@ -50,6 +50,7 @@
 #include "messages.h"
 #include "cmdline_contexts.h"
 #include "lib/gencache.h"
+#include "auth/credentials/credentials.h"
 
 #ifdef WITH_FAKE_KASERVER
 #include "utils/net_afs.h"
@@ -358,7 +359,7 @@ static int net_getlocalsid(struct net_context *c, int argc, const char **argv)
 {
         struct dom_sid sid;
        const char *name;
-       fstring sid_str;
+       struct dom_sid_buf sid_str;
 
        if (argc >= 1) {
                name = argv[0];
@@ -389,8 +390,9 @@ static int net_getlocalsid(struct net_context *c, int argc, const char **argv)
                DEBUG(0, ("Can't fetch domain SID for name: %s\n", name));
                return 1;
        }
-       sid_to_fstring(sid_str, &sid);
-       d_printf(_("SID for domain %s is: %s\n"), name, sid_str);
+       d_printf(_("SID for domain %s is: %s\n"),
+                name,
+                dom_sid_str_buf(&sid, &sid_str));
        return 0;
 }
 
@@ -439,7 +441,7 @@ static int net_setdomainsid(struct net_context *c, int argc, const char **argv)
 static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
 {
        struct dom_sid domain_sid;
-       fstring sid_str;
+       struct dom_sid_buf sid_str;
 
        if (argc > 0) {
                d_printf(_("Usage:"));
@@ -470,17 +472,18 @@ static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
                        d_fprintf(stderr, _("Could not fetch local SID\n"));
                        return 1;
                }
-               sid_to_fstring(sid_str, &domain_sid);
                d_printf(_("SID for local machine %s is: %s\n"),
-                        lp_netbios_name(), sid_str);
+                        lp_netbios_name(),
+                        dom_sid_str_buf(&domain_sid, &sid_str));
        }
        if (!secrets_fetch_domain_sid(c->opt_workgroup, &domain_sid)) {
                d_fprintf(stderr, _("Could not fetch domain SID\n"));
                return 1;
        }
 
-       sid_to_fstring(sid_str, &domain_sid);
-       d_printf(_("SID for domain %s is: %s\n"), c->opt_workgroup, sid_str);
+       d_printf(_("SID for domain %s is: %s\n"),
+                c->opt_workgroup,
+                dom_sid_str_buf(&domain_sid, &sid_str));
 
        return 0;
 }
@@ -904,6 +907,26 @@ static struct functable net_func[] = {
 };
 
 
+static void get_credentials_file(struct net_context *c,
+                                const char *file)
+{
+       struct cli_credentials *cred = cli_credentials_init(c);
+
+       if (cred == NULL) {
+               d_printf("ERROR: Unable to allocate memory!\n");
+               exit(-1);
+       }
+
+       if (!cli_credentials_parse_file(cred, file, CRED_GUESS_FILE)) {
+               exit(-1);
+       }
+
+       c->opt_user_name = cli_credentials_get_username(cred);
+       c->opt_user_specified = (c->opt_user_name != NULL);
+       c->opt_password = cli_credentials_get_password(cred);
+       c->opt_target_workgroup = cli_credentials_get_domain(cred);
+}
+
 /****************************************************************************
   main program
 ****************************************************************************/
@@ -923,6 +946,7 @@ static struct functable net_func[] = {
                {"help",        'h', POPT_ARG_NONE,   0, 'h'},
                {"workgroup",   'w', POPT_ARG_STRING, &c->opt_target_workgroup},
                {"user",        'U', POPT_ARG_STRING, &c->opt_user_name, 'U'},
+               {"authentication-file", 'A', POPT_ARG_STRING, &c->opt_user_name, 'A', "Get the credentials from a file", "FILE"},
                {"ipaddress",   'I', POPT_ARG_STRING, 0,'I'},
                {"port",        'p', POPT_ARG_INT,    &c->opt_port},
                {"myname",      'n', POPT_ARG_STRING, &c->opt_requester_name},
@@ -1025,6 +1049,9 @@ static struct functable net_func[] = {
                                c->opt_password = p+1;
                        }
                        break;
+               case 'A':
+                       get_credentials_file(c, c->opt_user_name);
+                       break;
                default:
                        d_fprintf(stderr, _("\nInvalid option %s: %s\n"),
                                 poptBadOption(pc, 0), poptStrerror(opt));