LCOV - code coverage report
Current view: top level - source3/utils - net_rap.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 0 558 0.0 %
Date: 2024-02-28 12:06:22 Functions: 0 64 0.0 %

          Line data    Source code
       1             : /*
       2             :    Samba Unix/Linux SMB client library
       3             :    Distributed SMB/CIFS Server Management Utility
       4             :    Copyright (C) 2001 Steve French  (sfrench@us.ibm.com)
       5             :    Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com)
       6             :    Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
       7             :    Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
       8             : 
       9             :    Originally written by Steve and Jim. Largely rewritten by tridge in
      10             :    November 2001.
      11             : 
      12             :    This program is free software; you can redistribute it and/or modify
      13             :    it under the terms of the GNU General Public License as published by
      14             :    the Free Software Foundation; either version 3 of the License, or
      15             :    (at your option) any later version.
      16             : 
      17             :    This program is distributed in the hope that it will be useful,
      18             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      19             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20             :    GNU General Public License for more details.
      21             : 
      22             :    You should have received a copy of the GNU General Public License
      23             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      24             : 
      25             : #include "includes.h"
      26             : #include "../librpc/gen_ndr/rap.h"
      27             : #include "../librpc/gen_ndr/svcctl.h"
      28             : #include "utils/net.h"
      29             : #include "libsmb/libsmb.h"
      30             : #include "clirap2.h"
      31             : #include "../libcli/smb/smbXcli_base.h"
      32             : 
      33             : /* The following messages were for error checking that is not properly
      34             :    reported at the moment.  Which should be reinstated? */
      35             : #define ERRMSG_TARGET_WG_NOT_VALID      "\nTarget workgroup option not valid "\
      36             :                                         "except on net rap server command, ignored"
      37             : #define ERRMSG_INVALID_HELP_OPTION      "\nInvalid help option\n"
      38             : 
      39             : #define ERRMSG_BOTH_SERVER_IPADDRESS    "\nTarget server and IP address both "\
      40             :   "specified. Do not set both at the same time.  The target IP address was used\n"
      41             : 
      42           0 : static int errmsg_not_implemented(void)
      43             : {
      44           0 :         d_printf(_("\nNot implemented\n"));
      45           0 :         return 0;
      46             : }
      47             : 
      48           0 : int net_rap_file_usage(struct net_context *c, int argc, const char **argv)
      49             : {
      50           0 :         return net_file_usage(c, argc, argv);
      51             : }
      52             : 
      53             : /***************************************************************************
      54             :   list info on an open file
      55             : ***************************************************************************/
      56           0 : static void file_fn(const char * pPath, const char * pUser, uint16_t perms,
      57             :                     uint16_t locks, uint32_t id)
      58             : {
      59           0 :         d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
      60             :                  id, pUser, perms, locks, pPath);
      61           0 : }
      62             : 
      63           0 : static void one_file_fn(const char *pPath, const char *pUser, uint16_t perms,
      64             :                         uint16_t locks, uint32_t id)
      65             : {
      66           0 :         d_printf(_("File ID          %d\n"
      67             :                    "User name        %s\n"
      68             :                    "Locks            0x%-4.2x\n"
      69             :                    "Path             %s\n"
      70             :                    "Permissions      0x%x\n"),
      71             :                  id, pUser, locks, pPath, perms);
      72           0 : }
      73             : 
      74             : 
      75           0 : static int rap_file_close(struct net_context *c, int argc, const char **argv)
      76             : {
      77           0 :         struct cli_state *cli;
      78           0 :         int ret;
      79           0 :         if (argc == 0 || c->display_usage) {
      80           0 :                 return net_rap_file_usage(c, argc, argv);
      81             :         }
      82             : 
      83           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
      84           0 :                 return -1;
      85             : 
      86           0 :         ret = cli_NetFileClose(cli, atoi(argv[0]));
      87           0 :         cli_shutdown(cli);
      88           0 :         return ret;
      89             : }
      90             : 
      91           0 : static int rap_file_info(struct net_context *c, int argc, const char **argv)
      92             : {
      93           0 :         struct cli_state *cli;
      94           0 :         int ret;
      95           0 :         if (argc == 0 || c->display_usage)
      96           0 :                 return net_rap_file_usage(c, argc, argv);
      97             : 
      98           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
      99           0 :                 return -1;
     100             : 
     101           0 :         ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
     102           0 :         cli_shutdown(cli);
     103           0 :         return ret;
     104             : }
     105             : 
     106           0 : static int rap_file_user(struct net_context *c, int argc, const char **argv)
     107             : {
     108           0 :         struct cli_state *cli;
     109           0 :         int ret;
     110             : 
     111           0 :         if (argc == 0 || c->display_usage)
     112           0 :                 return net_rap_file_usage(c, argc, argv);
     113             : 
     114           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     115           0 :                 return -1;
     116             : 
     117             :         /* list open files */
     118             : 
     119           0 :         d_printf(_("\nEnumerating open files on remote server:\n\n"
     120             :                    "\nFileId  Opened by            Perms  Locks  Path \n"
     121             :                    "------  ---------            -----  -----  ---- \n"));
     122           0 :         ret = cli_NetFileEnum(cli, argv[0], NULL, file_fn);
     123             : 
     124           0 :         if (ret == -1)
     125           0 :                 d_printf(_("\nOperation not supported by server!\n\n"));
     126             : 
     127           0 :         cli_shutdown(cli);
     128           0 :         return ret;
     129             : }
     130             : 
     131           0 : int net_rap_file(struct net_context *c, int argc, const char **argv)
     132             : {
     133           0 :         struct functable func[] = {
     134             :                 {
     135             :                         "close",
     136             :                         rap_file_close,
     137             :                         NET_TRANSPORT_RAP,
     138             :                         N_("Close specified file on server"),
     139             :                         N_("net rap file close\n"
     140             :                            "    Close specified file on server")
     141             :                 },
     142             :                 {
     143             :                         "user",
     144             :                         rap_file_user,
     145             :                         NET_TRANSPORT_RAP,
     146             :                         N_("List all files opened by username"),
     147             :                         N_("net rap file user\n"
     148             :                            "    List all files opened by username")
     149             :                 },
     150             :                 {
     151             :                         "info",
     152             :                         rap_file_info,
     153             :                         NET_TRANSPORT_RAP,
     154             :                         N_("Display info about an opened file"),
     155             :                         N_("net rap file info\n"
     156             :                            "    Display info about an opened file")
     157             :                 },
     158             :                 {NULL, NULL, 0, NULL, NULL}
     159             :         };
     160             : 
     161           0 :         if (argc == 0) {
     162           0 :                 struct cli_state *cli;
     163           0 :                 int ret;
     164             : 
     165           0 :                 if (c->display_usage) {
     166           0 :                         d_printf(_("Usage:\n"));
     167           0 :                         d_printf(_("net rap file\n"
     168             :                                    "    List all open files on rempte "
     169             :                                    "server\n"));
     170           0 :                         net_display_usage_from_functable(func);
     171           0 :                         return 0;
     172             :                 }
     173             : 
     174           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     175           0 :                         return -1;
     176             : 
     177             :                 /* list open files */
     178             : 
     179           0 :                 d_printf(_("\nEnumerating open files on remote server:\n\n"
     180             :                            "\nFileId  Opened by            Perms  Locks  Path\n"
     181             :                            "------  ---------            -----  -----  ----\n"));
     182           0 :                 ret = cli_NetFileEnum(cli, NULL, NULL, file_fn);
     183             : 
     184           0 :                 if (ret == -1)
     185           0 :                         d_printf(_("\nOperation not supported by server!\n\n"));
     186             : 
     187           0 :                 cli_shutdown(cli);
     188           0 :                 return ret;
     189             :         }
     190             : 
     191           0 :         return net_run_function(c, argc, argv, "net rap file", func);
     192             : }
     193             : 
     194           0 : int net_rap_share_usage(struct net_context *c, int argc, const char **argv)
     195             : {
     196           0 :         return net_share_usage(c, argc, argv);
     197             : }
     198             : 
     199           0 : static void long_share_fn(const char *share_name, uint32_t type,
     200             :                           const char *comment, void *state)
     201             : {
     202           0 :         d_printf("%-12s %-8.8s %-50s\n",
     203             :                  share_name, net_share_type_str(type), comment);
     204           0 : }
     205             : 
     206           0 : static void share_fn(const char *share_name, uint32_t type,
     207             :                      const char *comment, void *state)
     208             : {
     209           0 :         d_printf("%s\n", share_name);
     210           0 : }
     211             : 
     212           0 : static int rap_share_delete(struct net_context *c, int argc, const char **argv)
     213             : {
     214           0 :         struct cli_state *cli;
     215           0 :         int ret;
     216             : 
     217           0 :         if (argc == 0 || c->display_usage) {
     218           0 :                 return net_rap_share_usage(c, argc, argv);
     219             :         }
     220             : 
     221           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     222           0 :                 return -1;
     223             : 
     224           0 :         ret = cli_NetShareDelete(cli, argv[0]);
     225           0 :         cli_shutdown(cli);
     226           0 :         return ret;
     227             : }
     228             : 
     229           0 : static int rap_share_add(struct net_context *c, int argc, const char **argv)
     230             : {
     231           0 :         struct cli_state *cli;
     232           0 :         int ret;
     233             : 
     234           0 :         struct rap_share_info_2 sinfo;
     235           0 :         char *p;
     236           0 :         char *sharename;
     237             : 
     238           0 :         if (argc == 0 || c->display_usage) {
     239           0 :                 return net_rap_share_usage(c, argc, argv);
     240             :         }
     241             : 
     242           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     243           0 :                 return -1;
     244             : 
     245           0 :         sharename = SMB_STRDUP(argv[0]);
     246           0 :         p = strchr(sharename, '=');
     247           0 :         if (p == NULL) {
     248           0 :                 d_printf(_("Server path not specified\n"));
     249           0 :                 SAFE_FREE(sharename);
     250           0 :                 return net_rap_share_usage(c, argc, argv);
     251             :         }
     252           0 :         *p = 0;
     253           0 :         strlcpy((char *)sinfo.share_name, sharename, sizeof(sinfo.share_name));
     254           0 :         sinfo.reserved1 = '\0';
     255           0 :         sinfo.share_type = 0;
     256           0 :         sinfo.comment = c->opt_comment ? smb_xstrdup(c->opt_comment) : "";
     257           0 :         sinfo.perms = 0;
     258           0 :         sinfo.maximum_users = c->opt_maxusers;
     259           0 :         sinfo.active_users = 0;
     260           0 :         sinfo.path = p+1;
     261           0 :         memset(sinfo.password, '\0', sizeof(sinfo.password));
     262           0 :         sinfo.reserved2 = '\0';
     263             : 
     264           0 :         ret = cli_NetShareAdd(cli, &sinfo);
     265           0 :         cli_shutdown(cli);
     266           0 :         SAFE_FREE(sharename);
     267           0 :         return ret;
     268             : }
     269             : 
     270             : 
     271           0 : int net_rap_share(struct net_context *c, int argc, const char **argv)
     272             : {
     273           0 :         struct functable func[] = {
     274             :                 {
     275             :                         "delete",
     276             :                         rap_share_delete,
     277             :                         NET_TRANSPORT_RAP,
     278             :                         N_("Delete a share from server"),
     279             :                         N_("net rap share delete\n"
     280             :                            "    Delete a share from server")
     281             :                 },
     282             :                 {
     283             :                         "close",
     284             :                         rap_share_delete,
     285             :                         NET_TRANSPORT_RAP,
     286             :                         N_("Delete a share from server"),
     287             :                         N_("net rap share close\n"
     288             :                            "    Delete a share from server\n"
     289             :                            "    Alias for net rap share delete")
     290             :                 },
     291             :                 {
     292             :                         "add",
     293             :                         rap_share_add,
     294             :                         NET_TRANSPORT_RAP,
     295             :                         N_("Add a share to server"),
     296             :                         N_("net rap share add\n"
     297             :                            "    Add a share to server")
     298             :                 },
     299             :                 {NULL, NULL, 0, NULL, NULL}
     300             :         };
     301             : 
     302           0 :         if (argc == 0) {
     303           0 :                 struct cli_state *cli;
     304           0 :                 int ret;
     305             : 
     306           0 :                 if (c->display_usage) {
     307           0 :                         d_printf(_("Usage:\n"));
     308           0 :                         d_printf(_("net rap share\n"
     309             :                                    "    List all shares on remote server\n"));
     310           0 :                         net_display_usage_from_functable(func);
     311           0 :                         return 0;
     312             :                 }
     313             : 
     314           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     315           0 :                         return -1;
     316             : 
     317           0 :                 if (c->opt_long_list_entries) {
     318           0 :                         d_printf(_(
     319             :         "\nEnumerating shared resources (exports) on remote server:\n\n"
     320             :         "\nShare name   Type     Description\n"
     321             :         "----------   ----     -----------\n"));
     322           0 :                         ret = cli_RNetShareEnum(cli, long_share_fn, NULL);
     323             :                 } else {
     324           0 :                         ret = cli_RNetShareEnum(cli, share_fn, NULL);
     325             :                 }
     326           0 :                 cli_shutdown(cli);
     327           0 :                 return ret;
     328             :         }
     329             : 
     330           0 :         return net_run_function(c, argc, argv, "net rap share", func);
     331             : }
     332             : 
     333           0 : int net_rap_session_usage(struct net_context *c, int argc, const char **argv)
     334             : {
     335           0 :         d_printf(_(
     336             :          "\nnet rap session [misc. options] [targets]"
     337             :          "\n\tenumerates all active SMB/CIFS sessions on target server\n"));
     338           0 :         d_printf(_(
     339             :          "\nnet rap session DELETE <client_name> [misc. options] [targets] \n"
     340             :          "\tor"
     341             :          "\nnet rap session CLOSE <client_name> [misc. options] [targets]"
     342             :          "\n\tDeletes (closes) a session from specified client to server\n"));
     343           0 :         d_printf(_(
     344             :         "\nnet rap session INFO <client_name>"
     345             :         "\n\tEnumerates all open files in specified session\n"));
     346             : 
     347           0 :         net_common_flags_usage(c, argc, argv);
     348           0 :         return -1;
     349             : }
     350             : 
     351           0 : static void list_sessions_func(char *wsname, char *username, uint16_t conns,
     352             :                         uint16_t opens, uint16_t users, uint32_t sess_time,
     353             :                         uint32_t idle_time, uint32_t user_flags, char *clitype)
     354             : {
     355           0 :         int hrs = idle_time / 3600;
     356           0 :         int min = (idle_time / 60) % 60;
     357           0 :         int sec = idle_time % 60;
     358             : 
     359           0 :         d_printf("\\\\%-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d\n",
     360             :                  wsname, username, clitype, opens, hrs, min, sec);
     361           0 : }
     362             : 
     363           0 : static void display_session_func(const char *wsname, const char *username,
     364             :                                  uint16_t conns, uint16_t opens, uint16_t users,
     365             :                                  uint32_t sess_time, uint32_t idle_time,
     366             :                                  uint32_t user_flags, const char *clitype)
     367             : {
     368           0 :         int ihrs = idle_time / 3600;
     369           0 :         int imin = (idle_time / 60) % 60;
     370           0 :         int isec = idle_time % 60;
     371           0 :         int shrs = sess_time / 3600;
     372           0 :         int smin = (sess_time / 60) % 60;
     373           0 :         int ssec = sess_time % 60;
     374           0 :         d_printf(_("User name       %-20.20s\n"
     375             :                    "Computer        %-20.20s\n"
     376             :                    "Guest logon     %-20.20s\n"
     377             :                    "Client Type     %-40.40s\n"
     378             :                    "Sess time       %2.2d:%2.2d:%2.2d\n"
     379             :                    "Idle time       %2.2d:%2.2d:%2.2d\n"),
     380             :                  username, wsname,
     381             :                  (user_flags&0x0)?_("yes"):_("no"), clitype,
     382             :                  shrs, smin, ssec, ihrs, imin, isec);
     383           0 : }
     384             : 
     385           0 : static void display_conns_func(uint16_t conn_id, uint16_t conn_type, uint16_t opens,
     386             :                                uint16_t users, uint32_t conn_time,
     387             :                                const char *username, const char *netname)
     388             : {
     389           0 :         d_printf("%-14.14s %-8.8s %5d\n",
     390             :                  netname, net_share_type_str(conn_type), opens);
     391           0 : }
     392             : 
     393           0 : static int rap_session_info(struct net_context *c, int argc, const char **argv)
     394             : {
     395           0 :         const char *sessname;
     396           0 :         struct cli_state *cli;
     397           0 :         int ret;
     398             : 
     399           0 :         if (argc == 0 || c->display_usage)
     400           0 :                 return net_rap_session_usage(c, argc, argv);
     401             : 
     402           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     403           0 :                 return -1;
     404             : 
     405           0 :         sessname = argv[0];
     406             : 
     407           0 :         ret = cli_NetSessionGetInfo(cli, sessname, display_session_func);
     408           0 :         if (ret < 0) {
     409           0 :                 cli_shutdown(cli);
     410           0 :                 return ret;
     411             :         }
     412             : 
     413           0 :         d_printf(_("Share name     Type     # Opens\n-------------------------"
     414             :                    "-----------------------------------------------------\n"));
     415           0 :         ret = cli_NetConnectionEnum(cli, sessname, display_conns_func);
     416           0 :         cli_shutdown(cli);
     417           0 :         return ret;
     418             : }
     419             : 
     420           0 : static int rap_session_delete(struct net_context *c, int argc, const char **argv)
     421             : {
     422           0 :         struct cli_state *cli;
     423           0 :         int ret;
     424             : 
     425           0 :         if (argc == 0 || c->display_usage)
     426           0 :                 return net_rap_session_usage(c, argc, argv);
     427             : 
     428           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     429           0 :                 return -1;
     430             : 
     431           0 :         ret = cli_NetSessionDel(cli, argv[0]);
     432           0 :         cli_shutdown(cli);
     433           0 :         return ret;
     434             : }
     435             : 
     436           0 : int net_rap_session(struct net_context *c, int argc, const char **argv)
     437             : {
     438           0 :         struct functable func[] = {
     439             :                 {
     440             :                         "info",
     441             :                         rap_session_info,
     442             :                         NET_TRANSPORT_RAP,
     443             :                         N_("Display information about session"),
     444             :                         N_("net rap session info\n"
     445             :                            "    Display information about session")
     446             :                 },
     447             :                 {
     448             :                         "delete",
     449             :                         rap_session_delete,
     450             :                         NET_TRANSPORT_RAP,
     451             :                         N_("Close specified session"),
     452             :                         N_("net rap session delete\n"
     453             :                            "    Close specified session\n"
     454             :                            "    Alias for net rap session close")
     455             :                 },
     456             :                 {
     457             :                         "close",
     458             :                         rap_session_delete,
     459             :                         NET_TRANSPORT_RAP,
     460             :                         N_("Close specified session"),
     461             :                         N_("net rap session close\n"
     462             :                            "    Close specified session")
     463             :                 },
     464             :                 {NULL, NULL, 0, NULL, NULL}
     465             :         };
     466             : 
     467           0 :         if (argc == 0) {
     468           0 :                 struct cli_state *cli;
     469           0 :                 int ret;
     470             : 
     471           0 :                 if (c->display_usage) {
     472           0 :                         d_printf(_("Usage:\n"));
     473           0 :                         d_printf(_("net rap session\n"
     474             :                                    "    List all open sessions on remote "
     475             :                                    "server\n"));
     476           0 :                         net_display_usage_from_functable(func);
     477           0 :                         return 0;
     478             :                 }
     479             : 
     480           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     481           0 :                         return -1;
     482             : 
     483           0 :                 d_printf(_("Computer             User name            "
     484             :                            "Client Type        Opens Idle time\n"
     485             :                            "------------------------------------------"
     486             :                            "------------------------------------\n"));
     487           0 :                 ret = cli_NetSessionEnum(cli, list_sessions_func);
     488             : 
     489           0 :                 cli_shutdown(cli);
     490           0 :                 return ret;
     491             :         }
     492             : 
     493           0 :         return net_run_function(c, argc, argv, "net rap session", func);
     494             : }
     495             : 
     496             : /****************************************************************************
     497             : list a server name
     498             : ****************************************************************************/
     499           0 : static void display_server_func(const char *name, uint32_t m,
     500             :                                 const char *comment, void * reserved)
     501             : {
     502           0 :         d_printf("\t%-16.16s     %s\n", name, comment);
     503           0 : }
     504             : 
     505           0 : static int net_rap_server_name(struct net_context *c, int argc, const char *argv[])
     506             : {
     507           0 :         struct cli_state *cli;
     508           0 :         char *name;
     509             : 
     510           0 :         if (c->display_usage) {
     511           0 :                 d_printf("%s\n%s",
     512             :                          _("Usage:"),
     513             :                          _("net rap server name\n"
     514             :                            "    Get the name of the server\n"));
     515           0 :                 return 0;
     516             :         }
     517             : 
     518           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     519           0 :                 return -1;
     520             : 
     521           0 :         if (!cli_get_server_name(NULL, cli, &name)) {
     522           0 :                 d_fprintf(stderr, _("cli_get_server_name failed\n"));
     523           0 :                 cli_shutdown(cli);
     524           0 :                 return -1;
     525             :         }
     526             : 
     527           0 :         d_printf(_("Server name = %s\n"), name);
     528             : 
     529           0 :         TALLOC_FREE(name);
     530           0 :         cli_shutdown(cli);
     531           0 :         return 0;
     532             : }
     533             : 
     534           0 : static int net_rap_server_domain(struct net_context *c, int argc,
     535             :                                  const char **argv)
     536             : {
     537           0 :         struct cli_state *cli;
     538           0 :         int ret;
     539             : 
     540           0 :         if (c->display_usage) {
     541           0 :                 d_printf("%s\n%s",
     542             :                          _("Usage:"),
     543             :                          _("net rap server domain\n"
     544             :                            "    Enumerate servers in this domain/workgroup\n"));
     545           0 :                 return 0;
     546             :         }
     547             : 
     548           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     549           0 :                 return -1;
     550             : 
     551           0 :         d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n"
     552             :                    "\tServer name          Server description\n"
     553             :                    "\t-------------        ----------------------------\n"));
     554             : 
     555           0 :         ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL,
     556             :                                 display_server_func,NULL);
     557           0 :         cli_shutdown(cli);
     558           0 :         return ret;
     559             : }
     560             : 
     561           0 : int net_rap_server(struct net_context *c, int argc, const char **argv)
     562             : {
     563           0 :         struct functable func[] = {
     564             :                 {
     565             :                         "name",
     566             :                         net_rap_server_name,
     567             :                         NET_TRANSPORT_RAP,
     568             :                         N_("Get the name of the server"),
     569             :                         N_("net rap server name\n"
     570             :                            "    Get the name of the server")
     571             :                 },
     572             :                 {
     573             :                         "domain",
     574             :                         net_rap_server_domain,
     575             :                         NET_TRANSPORT_RAP,
     576             :                         N_("Get the servers in this domain/workgroup"),
     577             :                         N_("net rap server domain\n"
     578             :                            "    Get the servers in this domain/workgroup")
     579             :                 },
     580             :                 {NULL, NULL, 0, NULL, NULL}
     581             :         };
     582             : 
     583             :         /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
     584             :         /* Fall through for 'domain', any other forms will cause to show usage message */
     585           0 :         return net_run_function(c, argc, argv, "net rap server", func);
     586             : 
     587             : }
     588             : 
     589           0 : int net_rap_domain_usage(struct net_context *c, int argc, const char **argv)
     590             : {
     591           0 :         d_printf(_("net rap domain [misc. options] [target]\n\tlists the"
     592             :                    " domains or workgroups visible on the current network\n"));
     593             : 
     594           0 :         net_common_flags_usage(c, argc, argv);
     595           0 :         return -1;
     596             : }
     597             : 
     598           0 : int net_rap_domain(struct net_context *c, int argc, const char **argv)
     599             : {
     600           0 :         struct cli_state *cli;
     601           0 :         int ret;
     602             : 
     603           0 :         if (c->display_usage)
     604           0 :                 return net_rap_domain_usage(c, argc, argv);
     605             : 
     606           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     607           0 :                 return -1;
     608             : 
     609           0 :         d_printf(_("\nEnumerating domains:\n\n"
     610             :                    "\tDomain name          Server name of Browse Master\n"
     611             :                    "\t-------------        ----------------------------\n"));
     612             : 
     613           0 :         ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
     614             :                                 display_server_func,NULL);
     615           0 :         cli_shutdown(cli);
     616           0 :         return ret;
     617             : }
     618             : 
     619           0 : int net_rap_printq_usage(struct net_context *c, int argc, const char **argv)
     620             : {
     621           0 :         d_printf(_(
     622             :          "net rap printq [misc. options] [targets]\n"
     623             :          "\tor\n"
     624             :          "net rap printq info [<queue_name>] [misc. options] [targets]\n"
     625             :          "\tlists the specified queue and jobs on the target server.\n"
     626             :          "\tIf the queue name is not specified, all queues are listed.\n\n"));
     627           0 :         d_printf(_(
     628             :          "net rap printq delete [<queue name>] [misc. options] [targets]\n"
     629             :          "\tdeletes the specified job number on the target server, or the\n"
     630             :          "\tprinter queue if no job number is specified\n"));
     631             : 
     632           0 :         net_common_flags_usage(c, argc, argv);
     633             : 
     634           0 :         return -1;
     635             : }
     636             : 
     637           0 : static void enum_queue(const char *queuename, uint16_t pri, uint16_t start,
     638             :                        uint16_t until, const char *sep, const char *pproc,
     639             :                        const char *dest, const char *qparms,
     640             :                        const char *qcomment, uint16_t status, uint16_t jobcount)
     641             : {
     642           0 :         d_printf(_("%-17.17s Queue %5d jobs                      "),
     643             :                  queuename, jobcount);
     644             : 
     645           0 :         switch (status) {
     646           0 :         case 0:
     647           0 :                 d_printf(_("*Printer Active*\n"));
     648           0 :                 break;
     649           0 :         case 1:
     650           0 :                 d_printf(_("*Printer Paused*\n"));
     651           0 :                 break;
     652           0 :         case 2:
     653           0 :                 d_printf(_("*Printer error*\n"));
     654           0 :                 break;
     655           0 :         case 3:
     656           0 :                 d_printf(_("*Delete Pending*\n"));
     657           0 :                 break;
     658           0 :         default:
     659           0 :                 d_printf(_("**UNKNOWN STATUS**\n"));
     660             :         }
     661           0 : }
     662             : 
     663           0 : static void enum_jobs(uint16_t jobid, const char *ownername,
     664             :                       const char *notifyname, const char *datatype,
     665             :                       const char *jparms, uint16_t pos, uint16_t status,
     666             :                       const char *jstatus, unsigned int submitted, unsigned int jobsize,
     667             :                       const char *comment)
     668             : {
     669           0 :         d_printf("     %-23.23s %5d %9d            ",
     670             :                  ownername, jobid, jobsize);
     671           0 :         switch (status) {
     672           0 :         case 0:
     673           0 :                 d_printf(_("Waiting\n"));
     674           0 :                 break;
     675           0 :         case 1:
     676           0 :                 d_printf(_("Held in queue\n"));
     677           0 :                 break;
     678           0 :         case 2:
     679           0 :                 d_printf(_("Spooling\n"));
     680           0 :                 break;
     681           0 :         case 3:
     682           0 :                 d_printf(_("Printing\n"));
     683           0 :                 break;
     684           0 :         default:
     685           0 :                 d_printf(_("**UNKNOWN STATUS**\n"));
     686             :         }
     687           0 : }
     688             : 
     689             : #define PRINTQ_ENUM_DISPLAY \
     690             :     _("Print queues at \\\\%s\n\n"\
     691             :       "Name                         Job #      Size            Status\n\n"\
     692             :       "------------------------------------------------------------------"\
     693             :       "-------------\n")
     694             : 
     695           0 : static int rap_printq_info(struct net_context *c, int argc, const char **argv)
     696             : {
     697           0 :         struct cli_state *cli;
     698           0 :         int ret;
     699             : 
     700           0 :         if (argc == 0 || c->display_usage)
     701           0 :                 return net_rap_printq_usage(c, argc, argv);
     702             : 
     703           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     704           0 :                 return -1;
     705             : 
     706           0 :         d_printf(PRINTQ_ENUM_DISPLAY, smbXcli_conn_remote_name(cli->conn)); /* list header */
     707           0 :         ret = cli_NetPrintQGetInfo(cli, argv[0], enum_queue, enum_jobs);
     708           0 :         cli_shutdown(cli);
     709           0 :         return ret;
     710             : }
     711             : 
     712           0 : static int rap_printq_delete(struct net_context *c, int argc, const char **argv)
     713             : {
     714           0 :         struct cli_state *cli;
     715           0 :         NTSTATUS status;
     716             : 
     717           0 :         if (argc == 0 || c->display_usage)
     718           0 :                 return net_rap_printq_usage(c, argc, argv);
     719             : 
     720           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     721           0 :                 return -1;
     722             : 
     723           0 :         status = cli_printjob_del(cli, atoi(argv[0]));
     724           0 :         cli_shutdown(cli);
     725           0 :         if (!NT_STATUS_IS_OK(status)) {
     726           0 :                 return -1;
     727             :         }
     728           0 :         return 0;
     729             : }
     730             : 
     731           0 : int net_rap_printq(struct net_context *c, int argc, const char **argv)
     732             : {
     733           0 :         struct cli_state *cli;
     734           0 :         int ret;
     735             : 
     736           0 :         struct functable func[] = {
     737             :                 {
     738             :                         "info",
     739             :                         rap_printq_info,
     740             :                         NET_TRANSPORT_RAP,
     741             :                         N_("Display info about print queues and jobs"),
     742             :                         N_("net rap printq info [queue]\n"
     743             :                            "    Display info about print jobs in queue.\n"
     744             :                            "    If queue is not specified, all queues are "
     745             :                            "listed")
     746             :                 },
     747             :                 {
     748             :                         "delete",
     749             :                         rap_printq_delete,
     750             :                         NET_TRANSPORT_RAP,
     751             :                         N_("Delete print job(s)"),
     752             :                         N_("net rap printq delete\n"
     753             :                            "    Delete print job(s)")
     754             :                 },
     755             :                 {NULL, NULL, 0, NULL, NULL}
     756             :         };
     757             : 
     758           0 :         if (argc == 0) {
     759           0 :                 if (c->display_usage) {
     760           0 :                         d_printf(_("Usage:\n"));
     761           0 :                         d_printf(_("net rap printq\n"
     762             :                                    "    List the print queue\n"));
     763           0 :                         net_display_usage_from_functable(func);
     764           0 :                         return 0;
     765             :                 }
     766             : 
     767           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     768           0 :                         return -1;
     769             : 
     770           0 :                 d_printf(PRINTQ_ENUM_DISPLAY, smbXcli_conn_remote_name(cli->conn)); /* list header */
     771           0 :                 ret = cli_NetPrintQEnum(cli, enum_queue, enum_jobs);
     772           0 :                 cli_shutdown(cli);
     773           0 :                 return ret;
     774             :         }
     775             : 
     776           0 :         return net_run_function(c, argc, argv, "net rap printq", func);
     777             : }
     778             : 
     779           0 : static int net_rap_user_usage(struct net_context *c, int argc, const char **argv)
     780             : {
     781           0 :         return net_user_usage(c, argc, argv);
     782             : }
     783             : 
     784           0 : static void user_fn(const char *user_name, void *state)
     785             : {
     786           0 :         d_printf("%-21.21s\n", user_name);
     787           0 : }
     788             : 
     789           0 : static void long_user_fn(const char *user_name, const char *comment,
     790             :                          const char * home_dir, const char * logon_script,
     791             :                          void *state)
     792             : {
     793           0 :         d_printf("%-21.21s %s\n",
     794             :                  user_name, comment);
     795           0 : }
     796             : 
     797           0 : static void group_member_fn(const char *user_name, void *state)
     798             : {
     799           0 :         d_printf("%-21.21s\n", user_name);
     800           0 : }
     801             : 
     802           0 : static int rap_user_delete(struct net_context *c, int argc, const char **argv)
     803             : {
     804           0 :         struct cli_state *cli;
     805           0 :         int ret;
     806             : 
     807           0 :         if (argc == 0 || c->display_usage) {
     808           0 :                 return net_rap_user_usage(c, argc, argv);
     809             :         }
     810             : 
     811           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     812           0 :                 return -1;
     813             : 
     814           0 :         ret = cli_NetUserDelete(cli, argv[0]);
     815           0 :         cli_shutdown(cli);
     816           0 :         return ret;
     817             : }
     818             : 
     819           0 : static int rap_user_add(struct net_context *c, int argc, const char **argv)
     820             : {
     821           0 :         struct cli_state *cli;
     822           0 :         int ret;
     823           0 :         struct rap_user_info_1 userinfo;
     824             : 
     825           0 :         if (argc == 0 || c->display_usage) {
     826           0 :                 return net_rap_user_usage(c, argc, argv);
     827             :         }
     828             : 
     829           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     830           0 :                 return -1;
     831             : 
     832           0 :         strlcpy((char *)userinfo.user_name, argv[0], sizeof(userinfo.user_name));
     833           0 :         if (c->opt_flags == 0)
     834           0 :                 c->opt_flags = 0x21;
     835             : 
     836           0 :         userinfo.userflags = c->opt_flags;
     837           0 :         userinfo.reserved1 = '\0';
     838           0 :         userinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
     839           0 :         userinfo.priv = 1;
     840           0 :         userinfo.home_dir = NULL;
     841           0 :         userinfo.logon_script = NULL;
     842           0 :         userinfo.passwrd[0] = '\0';
     843             : 
     844           0 :         ret = cli_NetUserAdd(cli, &userinfo);
     845             : 
     846           0 :         cli_shutdown(cli);
     847           0 :         return ret;
     848             : }
     849             : 
     850           0 : static int rap_user_info(struct net_context *c, int argc, const char **argv)
     851             : {
     852           0 :         struct cli_state *cli;
     853           0 :         int ret;
     854           0 :         if (argc == 0 || c->display_usage) {
     855           0 :                 return net_rap_user_usage(c, argc, argv);
     856             :         }
     857             : 
     858           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     859           0 :                 return -1;
     860             : 
     861           0 :         ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
     862           0 :         cli_shutdown(cli);
     863           0 :         return ret;
     864             : }
     865             : 
     866           0 : int net_rap_user(struct net_context *c, int argc, const char **argv)
     867             : {
     868           0 :         int ret = -1;
     869           0 :         struct functable func[] = {
     870             :                 {
     871             :                         "add",
     872             :                         rap_user_add,
     873             :                         NET_TRANSPORT_RAP,
     874             :                         N_("Add specified user"),
     875             :                         N_("net rap user add\n"
     876             :                            "    Add specified user")
     877             :                 },
     878             :                 {
     879             :                         "info",
     880             :                         rap_user_info,
     881             :                         NET_TRANSPORT_RAP,
     882             :                         N_("List domain groups of specified user"),
     883             :                         N_("net rap user info\n"
     884             :                            "    List domain groups of specified user")
     885             : 
     886             :                 },
     887             :                 {
     888             :                         "delete",
     889             :                         rap_user_delete,
     890             :                         NET_TRANSPORT_RAP,
     891             :                         N_("Remove specified user"),
     892             :                         N_("net rap user delete\n"
     893             :                            "    Remove specified user")
     894             :                 },
     895             :                 {NULL, NULL, 0, NULL, NULL}
     896             :         };
     897             : 
     898           0 :         if (argc == 0) {
     899           0 :                 struct cli_state *cli;
     900           0 :                 if (c->display_usage) {
     901           0 :                         d_printf(_("Usage:\n"));
     902           0 :                         d_printf(_("net rap user\n"
     903             :                                    "    List all users\n"));
     904           0 :                         net_display_usage_from_functable(func);
     905           0 :                         return 0;
     906             :                 }
     907             : 
     908           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     909           0 :                         goto done;
     910           0 :                 if (c->opt_long_list_entries) {
     911           0 :                         d_printf(_("\nUser name             Comment"
     912             :                                    "\n-----------------------------\n"));
     913           0 :                         ret = cli_RNetUserEnum(cli, long_user_fn, NULL);
     914           0 :                         cli_shutdown(cli);
     915           0 :                         goto done;
     916             :                 }
     917           0 :                 ret = cli_RNetUserEnum0(cli, user_fn, NULL);
     918           0 :                 cli_shutdown(cli);
     919           0 :                 goto done;
     920             :         }
     921             : 
     922           0 :         ret = net_run_function(c, argc, argv, "net rap user", func);
     923           0 :  done:
     924           0 :         if (ret != 0) {
     925           0 :                 DEBUG(1, (_("Net user returned: %d\n"), ret));
     926             :         }
     927           0 :         return ret;
     928             : }
     929             : 
     930             : 
     931           0 : int net_rap_group_usage(struct net_context *c, int argc, const char **argv)
     932             : {
     933           0 :         return net_group_usage(c, argc, argv);
     934             : }
     935             : 
     936           0 : static void long_group_fn(const char *group_name, const char *comment,
     937             :                           void *state)
     938             : {
     939           0 :         d_printf("%-21.21s %s\n", group_name, comment);
     940           0 : }
     941             : 
     942           0 : static void group_fn(const char *group_name, void *state)
     943             : {
     944           0 :         d_printf("%-21.21s\n", group_name);
     945           0 : }
     946             : 
     947           0 : static int rap_group_delete(struct net_context *c, int argc, const char **argv)
     948             : {
     949           0 :         struct cli_state *cli;
     950           0 :         int ret;
     951           0 :         if (argc == 0 || c->display_usage) {
     952           0 :                 return net_rap_group_usage(c, argc, argv);
     953             :         }
     954             : 
     955           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     956           0 :                 return -1;
     957             : 
     958           0 :         ret = cli_NetGroupDelete(cli, argv[0]);
     959           0 :         cli_shutdown(cli);
     960           0 :         return ret;
     961             : }
     962             : 
     963           0 : static int rap_group_add(struct net_context *c, int argc, const char **argv)
     964             : {
     965           0 :         struct cli_state *cli;
     966           0 :         int ret;
     967           0 :         struct rap_group_info_1 grinfo;
     968             : 
     969           0 :         if (argc == 0 || c->display_usage) {
     970           0 :                 return net_rap_group_usage(c, argc, argv);
     971             :         }
     972             : 
     973           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
     974           0 :                 return -1;
     975             : 
     976             :         /* BB check for length 21 or smaller explicitly ? BB */
     977           0 :         strlcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name));
     978           0 :         grinfo.reserved1 = '\0';
     979           0 :         grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
     980             : 
     981           0 :         ret = cli_NetGroupAdd(cli, &grinfo);
     982           0 :         cli_shutdown(cli);
     983           0 :         return ret;
     984             : }
     985             : 
     986           0 : int net_rap_group(struct net_context *c, int argc, const char **argv)
     987             : {
     988           0 :         struct functable func[] = {
     989             :                 {
     990             :                         "add",
     991             :                         rap_group_add,
     992             :                         NET_TRANSPORT_RAP,
     993             :                         N_("Add specified group"),
     994             :                         N_("net rap group add\n"
     995             :                            "    Add specified group")
     996             :                 },
     997             :                 {
     998             :                         "delete",
     999             :                         rap_group_delete,
    1000             :                         NET_TRANSPORT_RAP,
    1001             :                         N_("Delete specified group"),
    1002             :                         N_("net rap group delete\n"
    1003             :                            "    Delete specified group")
    1004             :                 },
    1005             :                 {NULL, NULL, 0, NULL, NULL}
    1006             :         };
    1007             : 
    1008           0 :         if (argc == 0) {
    1009           0 :                 struct cli_state *cli;
    1010           0 :                 int ret;
    1011           0 :                 if (c->display_usage) {
    1012           0 :                         d_printf(_("Usage:\n"));
    1013           0 :                         d_printf(_("net rap group\n"
    1014             :                                    "    List all groups\n"));
    1015           0 :                         net_display_usage_from_functable(func);
    1016           0 :                         return 0;
    1017             :                 }
    1018             : 
    1019           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
    1020           0 :                         return -1;
    1021           0 :                 if (c->opt_long_list_entries) {
    1022           0 :                         d_printf(_("Group name            Comment\n"
    1023             :                                    "-----------------------------\n"));
    1024           0 :                         ret = cli_RNetGroupEnum(cli, long_group_fn, NULL);
    1025           0 :                         cli_shutdown(cli);
    1026           0 :                         return ret;
    1027             :                 }
    1028           0 :                 ret = cli_RNetGroupEnum0(cli, group_fn, NULL);
    1029           0 :                 cli_shutdown(cli);
    1030           0 :                 return ret;
    1031             :         }
    1032             : 
    1033           0 :         return net_run_function(c, argc, argv, "net rap group", func);
    1034             : }
    1035             : 
    1036           0 : int net_rap_groupmember_usage(struct net_context *c, int argc, const char **argv)
    1037             : {
    1038           0 :         d_printf(_(
    1039             :          "net rap groupmember LIST <group> [misc. options] [targets]"
    1040             :          "\n\t Enumerate users in a group\n"
    1041             :          "\nnet rap groupmember DELETE <group> <user> [misc. options] "
    1042             :          "[targets]\n\t Delete specified user from specified group\n"
    1043             :          "\nnet rap groupmember ADD <group> <user> [misc. options] [targets]"
    1044             :          "\n\t Add specified user to specified group\n"));
    1045             : 
    1046           0 :         net_common_flags_usage(c, argc, argv);
    1047           0 :         return -1;
    1048             : }
    1049             : 
    1050             : 
    1051           0 : static int rap_groupmember_add(struct net_context *c, int argc, const char **argv)
    1052             : {
    1053           0 :         struct cli_state *cli;
    1054           0 :         int ret;
    1055           0 :         if (argc != 2 || c->display_usage) {
    1056           0 :                 return net_rap_groupmember_usage(c, argc, argv);
    1057             :         }
    1058             : 
    1059           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
    1060           0 :                 return -1;
    1061             : 
    1062           0 :         ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
    1063           0 :         cli_shutdown(cli);
    1064           0 :         return ret;
    1065             : }
    1066             : 
    1067           0 : static int rap_groupmember_delete(struct net_context *c, int argc, const char **argv)
    1068             : {
    1069           0 :         struct cli_state *cli;
    1070           0 :         int ret;
    1071           0 :         if (argc != 2 || c->display_usage) {
    1072           0 :                 return net_rap_groupmember_usage(c, argc, argv);
    1073             :         }
    1074             : 
    1075           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
    1076           0 :                 return -1;
    1077             : 
    1078           0 :         ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
    1079           0 :         cli_shutdown(cli);
    1080           0 :         return ret;
    1081             : }
    1082             : 
    1083           0 : static int rap_groupmember_list(struct net_context *c, int argc, const char **argv)
    1084             : {
    1085           0 :         struct cli_state *cli;
    1086           0 :         int ret;
    1087           0 :         if (argc == 0 || c->display_usage) {
    1088           0 :                 return net_rap_groupmember_usage(c, argc, argv);
    1089             :         }
    1090             : 
    1091           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
    1092           0 :                 return -1;
    1093             : 
    1094           0 :         ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
    1095           0 :         cli_shutdown(cli);
    1096           0 :         return ret;
    1097             : }
    1098             : 
    1099           0 : int net_rap_groupmember(struct net_context *c, int argc, const char **argv)
    1100             : {
    1101           0 :         struct functable func[] = {
    1102             :                 {
    1103             :                         "add",
    1104             :                         rap_groupmember_add,
    1105             :                         NET_TRANSPORT_RAP,
    1106             :                         N_("Add specified user to group"),
    1107             :                         N_("net rap groupmember add\n"
    1108             :                            "    Add specified user to group")
    1109             :                 },
    1110             :                 {
    1111             :                         "list",
    1112             :                         rap_groupmember_list,
    1113             :                         NET_TRANSPORT_RAP,
    1114             :                         N_("List users in group"),
    1115             :                         N_("net rap groupmember list\n"
    1116             :                            "    List users in group")
    1117             :                 },
    1118             :                 {
    1119             :                         "delete",
    1120             :                         rap_groupmember_delete,
    1121             :                         NET_TRANSPORT_RAP,
    1122             :                         N_("Remove user from group"),
    1123             :                         N_("net rap groupmember delete\n"
    1124             :                            "    Remove user from group")
    1125             :                 },
    1126             :                 {NULL, NULL, 0, NULL, NULL}
    1127             :         };
    1128             : 
    1129           0 :         return net_run_function(c, argc, argv, "net rap groupmember", func);
    1130             : }
    1131             : 
    1132           0 : int net_rap_validate_usage(struct net_context *c, int argc, const char **argv)
    1133             : {
    1134           0 :         d_printf(_("net rap validate <username> [password]\n"
    1135             :                    "\tValidate user and password to check whether they"
    1136             :                    " can access target server or domain\n"));
    1137             : 
    1138           0 :         net_common_flags_usage(c, argc, argv);
    1139           0 :         return -1;
    1140             : }
    1141             : 
    1142           0 : int net_rap_validate(struct net_context *c, int argc, const char **argv)
    1143             : {
    1144           0 :         return errmsg_not_implemented();
    1145             : }
    1146             : 
    1147           0 : int net_rap_service_usage(struct net_context *c, int argc, const char **argv)
    1148             : {
    1149           0 :         d_printf(_("net rap service [misc. options] [targets] \n"
    1150             :                  "\tlists all running service daemons on target server\n"));
    1151           0 :         d_printf(_("\nnet rap service START <name> [service startup arguments]"
    1152             :                  " [misc. options] [targets]"
    1153             :                  "\n\tStart named service on remote server\n"));
    1154           0 :         d_printf(_("\nnet rap service STOP <name> [misc. options] [targets]\n"
    1155             :                  "\n\tStop named service on remote server\n"));
    1156             : 
    1157           0 :         net_common_flags_usage(c, argc, argv);
    1158           0 :         return -1;
    1159             : }
    1160             : 
    1161           0 : static int rap_service_start(struct net_context *c, int argc, const char **argv)
    1162             : {
    1163           0 :         return errmsg_not_implemented();
    1164             : }
    1165             : 
    1166           0 : static int rap_service_stop(struct net_context *c, int argc, const char **argv)
    1167             : {
    1168           0 :         return errmsg_not_implemented();
    1169             : }
    1170             : 
    1171           0 : static void service_fn(const char *service_name, const char *dummy,
    1172             :                        void *state)
    1173             : {
    1174           0 :         d_printf("%-21.21s\n", service_name);
    1175           0 : }
    1176             : 
    1177           0 : int net_rap_service(struct net_context *c, int argc, const char **argv)
    1178             : {
    1179           0 :         struct functable func[] = {
    1180             :                 {
    1181             :                         "start",
    1182             :                         rap_service_start,
    1183             :                         NET_TRANSPORT_RAP,
    1184             :                         N_("Start service on remote server"),
    1185             :                         N_("net rap service start\n"
    1186             :                            "    Start service on remote server")
    1187             :                 },
    1188             :                 {
    1189             :                         "stop",
    1190             :                         rap_service_stop,
    1191             :                         NET_TRANSPORT_RAP,
    1192             :                         N_("Stop named serve on remote server"),
    1193             :                         N_("net rap service stop\n"
    1194             :                            "    Stop named serve on remote server")
    1195             :                 },
    1196             :                 {NULL, NULL, 0, NULL, NULL}
    1197             :         };
    1198             : 
    1199           0 :         if (argc == 0) {
    1200           0 :                 struct cli_state *cli;
    1201           0 :                 int ret;
    1202           0 :                 if (c->display_usage) {
    1203           0 :                         d_printf(_("Usage:\n"));
    1204           0 :                         d_printf(_("net rap service\n"
    1205             :                                    "    List services on remote server\n"));
    1206           0 :                         net_display_usage_from_functable(func);
    1207           0 :                         return 0;
    1208             :                 }
    1209             : 
    1210           0 :                 if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
    1211           0 :                         return -1;
    1212             : 
    1213           0 :                 if (c->opt_long_list_entries) {
    1214           0 :                         d_printf(_("Service name          Comment\n"
    1215             :                                    "-----------------------------\n"));
    1216           0 :                         ret = cli_RNetServiceEnum(cli, long_group_fn, NULL);
    1217           0 :                         if (ret) {
    1218           0 :                                 cli_shutdown(cli);
    1219           0 :                                 return ret;
    1220             :                         }
    1221             :                 }
    1222           0 :                 ret = cli_RNetServiceEnum(cli, service_fn, NULL);
    1223           0 :                 cli_shutdown(cli);
    1224           0 :                 return ret;
    1225             :         }
    1226             : 
    1227           0 :         return net_run_function(c, argc, argv, "net rap service", func);
    1228             : }
    1229             : 
    1230           0 : int net_rap_password_usage(struct net_context *c, int argc, const char **argv)
    1231             : {
    1232           0 :         d_printf(_(
    1233             :          "net rap password <user> <oldpwo> <newpw> [misc. options] [target]\n"
    1234             :          "\tchanges the password for the specified user at target\n"));
    1235             : 
    1236           0 :         return -1;
    1237             : }
    1238             : 
    1239             : 
    1240           0 : int net_rap_password(struct net_context *c, int argc, const char **argv)
    1241             : {
    1242           0 :         struct cli_state *cli;
    1243           0 :         int ret;
    1244             : 
    1245           0 :         if (argc < 3 || c->display_usage)
    1246           0 :                 return net_rap_password_usage(c, argc, argv);
    1247             : 
    1248           0 :         if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
    1249           0 :                 return -1;
    1250             : 
    1251             :         /* BB Add check for password lengths? */
    1252           0 :         ret = cli_oem_change_password(cli, argv[0], argv[2], argv[1]);
    1253           0 :         cli_shutdown(cli);
    1254           0 :         return ret;
    1255             : }
    1256             : 
    1257           0 : int net_rap_admin_usage(struct net_context *c, int argc, const char **argv)
    1258             : {
    1259           0 :         d_printf(_(
    1260             :    "net rap admin <remote command> [cmd args [env]] [misc. options] [targets]"
    1261             :    "\n\texecutes a remote command on an os/2 target server\n"));
    1262             : 
    1263           0 :         return -1;
    1264             : }
    1265             : 
    1266             : 
    1267           0 : int net_rap_admin(struct net_context *c, int argc, const char **argv)
    1268             : {
    1269           0 :         return errmsg_not_implemented();
    1270             : }
    1271             : 
    1272             : /* Entry-point for all the RAP functions. */
    1273             : 
    1274           0 : int net_rap(struct net_context *c, int argc, const char **argv)
    1275             : {
    1276           0 :         struct functable func[] = {
    1277             :                 {
    1278             :                         "file",
    1279             :                         net_rap_file,
    1280             :                         NET_TRANSPORT_RAP,
    1281             :                         N_("List open files"),
    1282             :                         N_("net rap file\n"
    1283             :                            "    List open files")
    1284             :                 },
    1285             :                 {
    1286             :                         "share",
    1287             :                         net_rap_share,
    1288             :                         NET_TRANSPORT_RAP,
    1289             :                         N_("List shares exported by server"),
    1290             :                         N_("net rap share\n"
    1291             :                            "    List shares exported by server")
    1292             :                 },
    1293             :                 {
    1294             :                         "session",
    1295             :                         net_rap_session,
    1296             :                         NET_TRANSPORT_RAP,
    1297             :                         N_("List open sessions"),
    1298             :                         N_("net rap session\n"
    1299             :                            "    List open sessions")
    1300             :                 },
    1301             :                 {
    1302             :                         "server",
    1303             :                         net_rap_server,
    1304             :                         NET_TRANSPORT_RAP,
    1305             :                         N_("List servers in workgroup"),
    1306             :                         N_("net rap server\n"
    1307             :                            "    List servers in domain/workgroup")
    1308             :                 },
    1309             :                 {
    1310             :                         "domain",
    1311             :                         net_rap_domain,
    1312             :                         NET_TRANSPORT_RAP,
    1313             :                         N_("List domains in network"),
    1314             :                         N_("net rap domain\n"
    1315             :                            "    List domains in network")
    1316             :                 },
    1317             :                 {
    1318             :                         "printq",
    1319             :                         net_rap_printq,
    1320             :                         NET_TRANSPORT_RAP,
    1321             :                         N_("List printer queues on server"),
    1322             :                         N_("net rap printq\n"
    1323             :                            "    List printer queues on server")
    1324             :                 },
    1325             :                 {
    1326             :                         "user",
    1327             :                         net_rap_user,
    1328             :                         NET_TRANSPORT_RAP,
    1329             :                         N_("List users"),
    1330             :                         N_("net rap user\n"
    1331             :                            "    List users")
    1332             :                 },
    1333             :                 {
    1334             :                         "group",
    1335             :                         net_rap_group,
    1336             :                         NET_TRANSPORT_RAP,
    1337             :                         N_("List user groups"),
    1338             :                         N_("net rap group\n"
    1339             :                            "    List user groups")
    1340             :                 },
    1341             :                 {
    1342             :                         "validate",
    1343             :                         net_rap_validate,
    1344             :                         NET_TRANSPORT_RAP,
    1345             :                         N_("Check username/password"),
    1346             :                         N_("net rap validate\n"
    1347             :                            "    Check username/password")
    1348             :                 },
    1349             :                 {
    1350             :                         "groupmember",
    1351             :                         net_rap_groupmember,
    1352             :                         NET_TRANSPORT_RAP,
    1353             :                         N_("List/modify group memberships"),
    1354             :                         N_("net rap groupmember\n"
    1355             :                            "    List/modify group memberships")
    1356             :                 },
    1357             :                 {
    1358             :                         "admin",
    1359             :                         net_rap_admin,
    1360             :                         NET_TRANSPORT_RAP,
    1361             :                         N_("Execute commands on remote OS/2"),
    1362             :                         N_("net rap admin\n"
    1363             :                            "    Execute commands on remote OS/2")
    1364             :                 },
    1365             :                 {
    1366             :                         "service",
    1367             :                         net_rap_service,
    1368             :                         NET_TRANSPORT_RAP,
    1369             :                         N_("Start/stop remote service"),
    1370             :                         N_("net rap service\n"
    1371             :                            "    Start/stop remote service")
    1372             :                 },
    1373             :                 {
    1374             :                         "password",
    1375             :                         net_rap_password,
    1376             :                         NET_TRANSPORT_RAP,
    1377             :                         N_("Change user password"),
    1378             :                         N_("net rap password\n"
    1379             :                            "    Change user password")
    1380             :                 },
    1381             :                 {NULL, NULL, 0, NULL, NULL}
    1382             :         };
    1383             : 
    1384           0 :         return net_run_function(c, argc, argv, "net rap", func);
    1385             : }
    1386             : 

Generated by: LCOV version 1.14