Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 2000 **/
  4. /**********************************************************************/
  5. /*
  6. makeconn.c
  7. Simple command-line tool to make a deviceless connection given a
  8. text file containing a username and password
  9. FILE HISTORY:
  10. jschwart 24-Apr-2000 Created
  11. */
  12. #define STRICT
  13. #include <windows.h>
  14. #include <winnetwk.h>
  15. #include <stdio.h>
  16. #define MAX_BUFFER 256
  17. int __cdecl
  18. main(
  19. int argc,
  20. char *argv[]
  21. )
  22. {
  23. FILE *fp;
  24. DWORD dwErr;
  25. int nLen;
  26. char szUsername[MAX_BUFFER];
  27. char szPassword[MAX_BUFFER];
  28. NETRESOURCE nr;
  29. //
  30. // Check for the filename and remote name
  31. //
  32. if (argc != 3)
  33. {
  34. printf("Usage: %s <network share> <filename>\n", argv[0]);
  35. return 1;
  36. }
  37. fp = fopen(argv[2], "r");
  38. if (fp == NULL)
  39. {
  40. printf("Unable to open file %s\n", argv[2]);
  41. return 1;
  42. }
  43. //
  44. // Username is the first line in the file
  45. //
  46. fgets(szUsername, MAX_BUFFER, fp);
  47. //
  48. // Password is the second
  49. //
  50. fgets(szPassword, MAX_BUFFER, fp);
  51. fclose(fp);
  52. //
  53. // Trim off the trailing newlines that fgets inserts
  54. //
  55. szUsername[strlen(szUsername) - 1] = '\0';
  56. nLen = strlen(szPassword) - 1;
  57. if (szPassword[nLen] == '\n')
  58. {
  59. szPassword[nLen] = '\0';
  60. }
  61. ZeroMemory(&nr, sizeof(nr));
  62. nr.dwType = RESOURCETYPE_DISK;
  63. nr.lpRemoteName = argv[1];
  64. printf("Path %s\n", argv[1]);
  65. dwErr = WNetAddConnection2(&nr,
  66. szPassword,
  67. szUsername,
  68. 0);
  69. if (dwErr != NO_ERROR)
  70. {
  71. printf("Unable to make a connection to %s -- error %d\n", argv[1], dwErr);
  72. return 1;
  73. }
  74. else
  75. {
  76. printf("Connection to %s succeeded\n", argv[1]);
  77. }
  78. return 0;
  79. }