⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clirap2.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
        fn(username, comment, homedir, logonscript, cli);      }    } else {      DEBUG(4,("NetUserEnum res=%d\n", res));    }  } else {    DEBUG(4,("NetUserEnum no data returned\n"));  }      SAFE_FREE(rparam);  SAFE_FREE(rdata);  return res;}int cli_RNetUserEnum0(struct cli_state *cli,		      void (*fn)(const char *, void *),		      void *state){  char param[WORDSIZE                 /* api number    */	    +sizeof(RAP_NetUserEnum_REQ) /* parm string   */	    +sizeof(RAP_USER_INFO_L0)    /* return string */	    +WORDSIZE                 /* info level    */	    +WORDSIZE];               /* buffer size   */  char *p;  char *rparam = NULL;  char *rdata = NULL;   unsigned int rprcnt, rdrcnt;  int res = -1;    memset(param, '\0', sizeof(param));  p = make_header(param, RAP_WUserEnum,		  RAP_NetUserEnum_REQ, RAP_USER_INFO_L0);  PUTWORD(p,0); /* Info level 1 */  PUTWORD(p,0xFF00); /* Return buffer size *//* BB Fix handling of large numbers of users to be returned */  if (cli_api(cli,	      param, PTR_DIFF(p,param),8,	      NULL, 0, CLI_BUFFER_SIZE,	      &rparam, &rprcnt,	      &rdata, &rdrcnt)) {    res = GETRES(rparam);    cli->rap_error = res;    if (cli->rap_error != 0) {      DEBUG(1,("NetUserEnum gave error %d\n", cli->rap_error));    }  }  if (rdata) {    if (res == 0 || res == ERRmoredata) {      int i, count;      char username[RAP_USERNAME_LEN];      p = rparam + WORDSIZE + WORDSIZE; /* skip result and converter */      GETWORD(p, count);      for (i=0,p=rdata;i<count;i++) {        GETSTRINGF(p, username, RAP_USERNAME_LEN);        fn(username, cli);      }    } else {      DEBUG(4,("NetUserEnum res=%d\n", res));    }  } else {    DEBUG(4,("NetUserEnum no data returned\n"));  }      SAFE_FREE(rparam);  SAFE_FREE(rdata);  return res;}/**************************************************************************** call a NetFileClose2 - close open file on another session to server****************************************************************************/int cli_NetFileClose(struct cli_state *cli, uint32 file_id ){  char *rparam = NULL;  char *rdata = NULL;  char *p;  unsigned int rdrcnt,rprcnt;  char param[WORDSIZE                    /* api number    */	    +sizeof(RAP_WFileClose2_REQ) /* req string    */	    +1                           /* no ret string */	    +DWORDSIZE];                 /* file ID          */  int res = -1;  /* now send a SMBtrans command with api RNetShareEnum */  p = make_header(param, RAP_WFileClose2, RAP_WFileClose2_REQ, NULL);  PUTDWORD(p, file_id);          	   if (cli_api(cli, 	      param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */	      NULL, 0, 200,       /* data, length, maxlen */	      &rparam, &rprcnt,   /* return params, length */	      &rdata, &rdrcnt))   /* return data, length */    {      res = GETRES(rparam);            if (res == 0) {	/* nothing to do */		      } else if (res == 2314){         DEBUG(1, ("NetFileClose2 - attempt to close non-existant file open instance\n"));      } else {	DEBUG(4,("NetFileClose2 res=%d\n", res));      }          } else {      res = -1;      DEBUG(4,("NetFileClose2 failed\n"));    }    SAFE_FREE(rparam);  SAFE_FREE(rdata);    return res;}/****************************************************************************call a NetFileGetInfo - get information about server file opened from other     workstation****************************************************************************/int cli_NetFileGetInfo(struct cli_state *cli, uint32 file_id, void (*fn)(const char *, const char *, uint16, uint16, uint32)){  char *rparam = NULL;  char *rdata = NULL;  char *p;  unsigned int rdrcnt,rprcnt;  int res;  char param[WORDSIZE                      /* api number      */	    +sizeof(RAP_WFileGetInfo2_REQ) /* req string      */	    +sizeof(RAP_FILE_INFO_L3)      /* return string   */	    +DWORDSIZE                     /* file ID          */	    +WORDSIZE                      /* info level      */	    +WORDSIZE];                    /* buffer size     */  /* now send a SMBtrans command with api RNetShareEnum */  p = make_header(param, RAP_WFileGetInfo2,		  RAP_WFileGetInfo2_REQ, RAP_FILE_INFO_L3);   PUTDWORD(p, file_id);  PUTWORD(p, 3);  /* info level */  PUTWORD(p, 0x1000);   /* buffer size */   if (cli_api(cli, 	      param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */	      NULL, 0, 0x1000,  /* data, length, maxlen */	      &rparam, &rprcnt,               /* return params, length */	      &rdata, &rdrcnt))               /* return data, length */    {      res = GETRES(rparam);      if (res == 0 || res == ERRmoredata) {	int converter,id, perms, locks;	pstring fpath, fuser;	  	p = rparam + WORDSIZE; /* skip result */	GETWORD(p, converter);	p = rdata;	GETDWORD(p, id);	GETWORD(p, perms);	GETWORD(p, locks);	GETSTRINGP(p, fpath, rdata, converter);	GETSTRINGP(p, fuser, rdata, converter);		fn(fpath, fuser, perms, locks, id);      } else {	DEBUG(4,("NetFileGetInfo2 res=%d\n", res));      }          } else {      res = -1;      DEBUG(4,("NetFileGetInfo2 failed\n"));    }    SAFE_FREE(rparam);  SAFE_FREE(rdata);    return res;}/***************************************************************************** Call a NetFileEnum2 - list open files on an SMB server* * PURPOSE:  Remotes a NetFileEnum API call to the current server or target *           server listing the files open via the network (and their*           corresponding open instance ids)*          * Dependencies: none** Parameters: *             cli    - pointer to cli_state structure*             user   - if present, return only files opened by this remote user*             base_path - if present, return only files opened below this *                         base path*             fn     - display function to invoke for each entry in the result*                        ** Returns:*             True      - success*             False     - failure*****************************************************************************/int cli_NetFileEnum(struct cli_state *cli, char * user, char * base_path, void (*fn)(const char *, const char *, uint16, uint16, uint32)){  char *rparam = NULL;  char *rdata = NULL;  char *p;  unsigned int rdrcnt,rprcnt;  char param[WORDSIZE                   /* api number      */	    +sizeof(RAP_WFileEnum2_REQ) /* req string      */	    +sizeof(RAP_FILE_INFO_L3)   /* return string   */	    +256                        /* base path (opt) */	    +RAP_USERNAME_LEN           /* user name (opt) */	    +WORDSIZE                   /* info level      */	    +WORDSIZE                   /* buffer size     */	    +DWORDSIZE                  /* resume key ?    */	    +DWORDSIZE];                /* resume key ?    */  int count = -1;  /* now send a SMBtrans command with api RNetShareEnum */  p = make_header(param, RAP_WFileEnum2,		  RAP_WFileEnum2_REQ, RAP_FILE_INFO_L3);   PUTSTRING(p, base_path, 256);  PUTSTRING(p, user, RAP_USERNAME_LEN);  PUTWORD(p, 3); /* info level */  PUTWORD(p, 0xFF00);  /* buffer size */   PUTDWORD(p, 0);  /* zero out the resume key */  PUTDWORD(p, 0);  /* or is this one the resume key? */        	   if (cli_api(cli, 	      param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */	      NULL, 0, 0xFF00,  /* data, length, maxlen */	      &rparam, &rprcnt,               /* return params, length */	      &rdata, &rdrcnt))               /* return data, length */    {      int res = GETRES(rparam);            if (res == 0 || res == ERRmoredata) {	int converter, i;	p = rparam + WORDSIZE; /* skip result */	GETWORD(p, converter);	GETWORD(p, count);		p = rdata;	for (i=0; i<count; i++) {	  int id, perms, locks;	  pstring fpath, fuser;	  	  GETDWORD(p, id);	  GETWORD(p, perms);	  GETWORD(p, locks);	  GETSTRINGP(p, fpath, rdata, converter);	  GETSTRINGP(p, fuser, rdata, converter);	  fn(fpath, fuser, perms, locks, id);	}  /* BB fix ERRmoredata case to send resume request */      } else {	DEBUG(4,("NetFileEnum2 res=%d\n", res));      }          } else {      DEBUG(4,("NetFileEnum2 failed\n"));    }    SAFE_FREE(rparam);  SAFE_FREE(rdata);    return count;}/**************************************************************************** call a NetShareAdd - share/export directory on remote server****************************************************************************/int cli_NetShareAdd(struct cli_state *cli, RAP_SHARE_INFO_2 * sinfo ){  char *rparam = NULL;  char *rdata = NULL;  char *p;  unsigned int rdrcnt,rprcnt;  int res;  char param[WORDSIZE                  /* api number    */	    +sizeof(RAP_WShareAdd_REQ) /* req string    */	    +sizeof(RAP_SHARE_INFO_L2) /* return string */	    +WORDSIZE                  /* info level    */	    +WORDSIZE];                /* reserved word */  char data[1024];  /* offset to free format string section following fixed length data.  */  /* will be updated by PUTSTRINGP macro and will end up with total len */  int soffset = RAP_SHARENAME_LEN + 1 /* share name + pad   */    + WORDSIZE                        /* share type    */    + DWORDSIZE                       /* comment pointer */    + WORDSIZE                        /* permissions */    + WORDSIZE                        /* max users */    + WORDSIZE                        /* active users */    + DWORDSIZE                       /* share path */    + RAP_SPASSWD_LEN + 1;            /* share password + pad */  memset(param,'\0',sizeof(param));  /* now send a SMBtrans command with api RNetShareAdd */  p = make_header(param, RAP_WshareAdd,		  RAP_WShareAdd_REQ, RAP_SHARE_INFO_L2);   PUTWORD(p, 2); /* info level */  PUTWORD(p, 0); /* reserved word 0 */  p = data;  PUTSTRINGF(p, sinfo->share_name, RAP_SHARENAME_LEN);  PUTBYTE(p, 0); /* pad byte 0 */  PUTWORD(p, sinfo->share_type);  PUTSTRINGP(p, sinfo->comment, data, soffset);  PUTWORD(p, sinfo->perms);  PUTWORD(p, sinfo->maximum_users);  PUTWORD(p, sinfo->active_users);  PUTSTRINGP(p, sinfo->path, data, soffset);  PUTSTRINGF(p, sinfo->password, RAP_SPASSWD_LEN);  SCVAL(p,-1,0x0A); /* required 0x0A at end of password */    if (cli_api(cli, 	      param, sizeof(param), 1024, /* Param, length, maxlen */	      data, soffset, sizeof(data), /* data, length, maxlen */	      &rparam, &rprcnt,   /* return params, length */	      &rdata, &rdrcnt))   /* return data, length */    {      res = rparam? SVAL(rparam,0) : -1;			      if (res == 0) {	/* nothing to do */		      }      else {	DEBUG(4,("NetShareAdd res=%d\n", res));      }          } else {      res = -1;      DEBUG(4,("NetShareAdd failed\n"));    }    SAFE_FREE(rparam);  SAFE_FREE(rdata);    return res;}/**************************************************************************** call a NetShareDelete - unshare exported directory on remote server****************************************************************************/int cli_NetShareDelete(struct cli_state *cli, const char * share_name ){  char *rparam = NULL;  char *rdata = NULL;  char *p;  unsigned int rdrcnt,rprcnt;  int res;  char param[WORDSIZE                  /* api number    */	    +sizeof(RAP_WShareDel_REQ) /* req string    */	    +1                         /* no ret string */	    +RAP_SHARENAME_LEN         /* share to del  */	    +WORDSIZE];                /* reserved word */	      /* now send a SMBtrans command with api RNetShareDelete */  p = make_header(param, RAP_WshareDel, RAP_WShareDel_REQ, NULL);  PUTSTRING(p,share_name,RAP_SHARENAME_LEN);  PUTWORD(p,0);  /* reserved word MBZ on input */        	   if (cli_api(cli, 	      param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */	      NULL, 0, 200,       /* data, length, maxlen */	      &rparam, &rprcnt,   /* return params, length */	      &rdata, &rdrcnt))   /* return data, length */    {      res = GETRES(rparam);			      if (res == 0) {	/* nothing to do */		      }      else {	DEBUG(4,("NetShareDelete res=%d\n", res));      }          } else {      res = -1;      DEBUG(4,("NetShareDelete failed\n"));    }    SAFE_FREE(rparam);  SAFE_FREE(rdata);	  return res;}/*************************************************************************** Function Name:  cli_get_pdc_name** PURPOSE:  Remotes a NetServerEnum API call to the current server*           requesting the name of a server matching the server*           type of SV_TYPE_DOMAIN_CTRL (PDC).** Dependencies: none** Parameters: *             cli       - pointer to cli_state structure*             workgroup - pointer to string containing name of domain*             pdc_name  - pointer to string that will contain PDC name*                         on successful return** Returns:*             True      - success

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -