client.c PATCH: script-parsable output (merge into HEAD)
Derrell.Lipman at UnwiredUniverse.com
Derrell.Lipman at UnwiredUniverse.com
Tue May 7 17:18:20 GMT 2002
I've merged the changes I had made to SAMBA_2_2's client.c into HEAD. This
patch adds a -x option which provides the same data as -L, but in a format
that is easily parsed by scripts.
Index: client.c
===================================================================
RCS file: /cvsroot/samba/source/client/client.c,v
retrieving revision 1.209
diff -r1.209 client.c
55a56,94
> /*
> * Line Field Output allows for easily-parsable output when generating a list
> * of shares available on a host.
> *
> * Output is tab-separated fields, with all fields pertaining to one record on
> * a single line. Field 1 will be one of the following, with the indicated
> * additional fields:
> *
> * #D = Share type is "Disk"
> * Field 2 = Share name / Field 3 = Comment
> * #P = Share type is "Printer"
> * Field 2 = Share name / Field 3 = Comment
> * #C = Share type is "deviCe"
> * Field 2 = Share name / Field 3 = Comment
> * #I = Share type is "Ipc"
> * Field 2 = Share name / Field 3 = Comment
> *
> * #E = Error
> * Field 2 = Full error message
> *
> * #M = Master browser
> * Field 2 = Server name / Field 3 = Comment
> *
> * #W = Workgroup
> * Field 2 = Workgroup name / Field 3 = Master
> *
> * #N = domaiN
> * Field 2 = Domain name
> *
> * #O = Operating system
> * Field 2 = OS name
> *
> * #V = Version
> * Field 2 = Version string
> *
> * Selecting this option implies -L as well.
> */
> static BOOL line_field_output = False;
>
1883a1923
> char line_id_char;
1890c1930
< fstrcpy(typestr,"Disk"); break;
---
> fstrcpy(typestr,"Disk"); line_id_char = 'D'; break;
1892c1932
< fstrcpy(typestr,"Printer"); break;
---
> fstrcpy(typestr,"Printer"); line_id_char = 'P'; break;
1894c1934
< fstrcpy(typestr,"Device"); break;
---
> fstrcpy(typestr,"Device"); line_id_char = 'C'; break;
1896c1936,1950
< fstrcpy(typestr,"IPC"); break;
---
> fstrcpy(typestr,"IPC"); line_id_char = 'I'; break;
> }
>
> if (line_field_output)
> {
> printf("#%c\t%s\t%s\n",
> line_id_char, name, comment);
> }
> else
> {
> /* FIXME: If the remote machine returns non-ascii characters
> in any of these fields, they can corrupt the output. We
> should remove them. */
> d_printf("\t%-15.15s%-10.10s%s\n",
> name,typestr,comment);
1898,1902d1951
< /* FIXME: If the remote machine returns non-ascii characters
< in any of these fields, they can corrupt the output. We
< should remove them. */
< d_printf("\t%-15.15s%-10.10s%s\n",
< name,typestr,comment);
1913,1914c1962,1966
< d_printf("\n\tSharename Type Comment\n");
< d_printf("\t--------- ---- -------\n");
---
> if (! line_field_output)
> {
> d_printf("\n\tSharename Type Comment\n");
> d_printf("\t--------- ---- -------\n");
> }
1916a1969,1970
> if (line_field_output)
> d_printf("#E\t");
1928c1982,1997
< d_printf("\t%-16.16s %s\n", name, comment);
---
> if (line_field_output)
> d_printf("#M\t%s\t%s\n", name, comment);
> else
> d_printf("\t%-16.16s %s\n", name, comment);
> }
>
> /****************************************************************************
> list a workgroup name
> ****************************************************************************/
> static void workgroup_fn(const char *name, uint32 m,
> const char *comment, void *state)
> {
> if (line_field_output)
> d_printf("#W\t%s\t%s\n", name, comment);
> else
> d_printf("\t%-16.16s %s\n", name, comment);
1938,1939c2007,2011
< d_printf("\n\tServer Comment\n");
< d_printf("\t--------- -------\n");
---
> if (! line_field_output)
> {
> d_printf("\n\tServer Comment\n");
> d_printf("\t--------- -------\n");
> }
1943,1944c2015,2019
< d_printf("\n\tWorkgroup Master\n");
< d_printf("\t--------- -------\n");
---
> if (! line_field_output)
> {
> d_printf("\n\tWorkgroup Master\n");
> d_printf("\t--------- -------\n");
> }
1946c2021
< cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, server_fn, NULL);
---
> cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, workgroup_fn, NULL);
2320,2321c2395,2400
< DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
< c->server_domain,c->server_os,c->server_type));
---
> if (line_field_output)
> printf("#N\t%s\n#O\t%s\n#V\t%s\n",
> c->server_domain,c->server_os,c->server_type);
> else
> DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
> c->server_domain,c->server_os,c->server_type));
2323,2324c2402,2407
< DEBUG(1,("OS=[%s] Server=[%s]\n",
< c->server_os,c->server_type));
---
> if (line_field_output)
> printf("#O\t%s\n#V\t%s\n",
> c->server_os,c->server_type);
> else
> DEBUG(1,("OS=[%s] Server=[%s]\n",
> c->server_os,c->server_type));
2390d2472
< d_printf("\t-L host get a list of shares available on a host\n");
2398a2481,2513
> d_printf("\t-L host get a list of shares available on a host\n");
> d_printf("\t-x host get a list of shares available on a host but\n");
> d_printf("\t print with the following parsable format:\n");
> d_printf("\t Output is tab-separated fields, with all fields\n");
> d_printf("\t pertaining to one record on a single line.\n");
> d_printf("\t Field 1 will be one of the following, with the\n");
> d_printf("\t indicated additional fields:\n");
> d_printf("\t #D = Share type is Disk\n");
> d_printf("\t Field 2 = Share name\n");
> d_printf("\t Field 3 = Comment\n");
> d_printf("\t #P = Share type is Printer\n");
> d_printf("\t Field 2 = Share name\n");
> d_printf("\t Field 3 = Comment\n");
> d_printf("\t #C = Share type is deviCe\n");
> d_printf("\t Field 2 = Share name\n");
> d_printf("\t Field 3 = Comment\n");
> d_printf("\t #I = Share type is Ipc\n");
> d_printf("\t Field 2 = Share name\n");
> d_printf("\t Field 3 = Comment\n");
> d_printf("\t #E = Error\n");
> d_printf("\t Field 2 = Full error message\n");
> d_printf("\t #M = Master browser\n");
> d_printf("\t Field 2 = Master browser name\n");
> d_printf("\t Field 3 = Comment\n");
> d_printf("\t #W = Workgroup\n");
> d_printf("\t Field 2 = Workgroup name\n");
> d_printf("\t Field 3 = Master\n");
> d_printf("\t #N = domaiN\n");
> d_printf("\t Field 2 = Domain name\n");
> d_printf("\t #O = Operating system\n");
> d_printf("\t Field 2 = OS name\n");
> d_printf("\t #V = Version\n");
> d_printf("\t Field 2 = Version string\n");
2706c2821
< getopt(argc, argv,"s:O:R:M:i:Nn:d:Pp:l:hI:EU:L:t:m:W:T:D:c:b:A:k")) != EOF) {
---
> getopt(argc, argv,"s:O:R:M:i:Nn:d:Pp:l:hI:EU:L:x:t:m:W:T:D:c:b:A:k")) != EOF) {
2835a2951,2953
> case 'x':
> line_field_output = True;
> /* fall through */
More information about the samba-technical
mailing list